Class CPEAnalyzer
- All Implemented Interfaces:
Analyzer
- Direct Known Subclasses:
NpmCPEAnalyzer
- Author:
- Jeremy Long
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidanalyzeDependency(Dependency dependency, Engine engine) Analyzes a dependency and attempts to determine if there are any CPE identifiers for this dependency.protected StringbuildSearch(Map<String, org.apache.commons.lang3.mutable.MutableInt> vendor, Map<String, org.apache.commons.lang3.mutable.MutableInt> product, Set<String> vendorWeighting, Set<String> productWeightings) Builds a Lucene search string by properly escaping data and constructing a valid search query.voidCloses the data sources.protected voidcollectTerms(Map<String, org.apache.commons.lang3.mutable.MutableInt> terms, Iterable<Evidence> evidence) Returns the text created by concatenating the text and the values from the EvidenceCollection (filtered for a specific confidence).protected voiddetermineCPE(Dependency dependency) Searches the data store of CPE entries, trying to identify the CPE for the given dependency based on the evidence contained within.protected booleandetermineIdentifiers(Dependency dependency, String vendor, String product, Confidence currentConfidence) Retrieves a list of CPE values from the CveDB based on the vendor and product passed in.Returns the analysis phase that this analyzer should run in.protected StringReturns the setting key to determine if the analyzer is enabled.protected CveDBgetCveDB()returns a reference to the CveDB.protected MemoryIndexReturns the memory index.getName()Returns the name of this analyzer.static voidCommand line tool for querying the Lucene CPE Index.voidOpens the data source.voidprepareAnalyzer(Engine engine) Creates the CPE Lucene Index.protected List<IndexEntry> searchCPE(Map<String, org.apache.commons.lang3.mutable.MutableInt> vendor, Map<String, org.apache.commons.lang3.mutable.MutableInt> product, Set<String> vendorWeightings, Set<String> productWeightings, String ecosystem) Searches the Lucene CPE index to identify possible CPE entries associated with the supplied vendor, product, and version.protected voidsetCpeSuppressionAnalyzer(CpeSuppressionAnalyzer suppression) Sets the CPE Suppression Analyzer.protected voidSets the reference to the CveDB.protected voidSets the MemoryIndex.Methods inherited from class AbstractAnalyzer
analyze, close, getSettings, initialize, isEnabled, prepare, setEnabled, supportsParallelProcessing
-
Constructor Details
-
CPEAnalyzer
public CPEAnalyzer()
-
-
Method Details
-
getName
-
getAnalysisPhase
Returns the analysis phase that this analyzer should run in.- Returns:
- the analysis phase that this analyzer should run in.
-
prepareAnalyzer
Creates the CPE Lucene Index.- Overrides:
prepareAnalyzerin classAbstractAnalyzer- Parameters:
engine- a reference to the dependency-check engine- Throws:
InitializationException- is thrown if there is an issue opening the index.
-
open
Opens the data source.- Parameters:
cve- a reference to the NVD CVE database- Throws:
IOException- when the Lucene directory to be queried does not exist or is corrupt.DatabaseException- when the database throws an exception. This usually occurs when the database is in use by another process.
-
closeAnalyzer
public void closeAnalyzer()Closes the data sources.- Overrides:
closeAnalyzerin classAbstractAnalyzer
-
determineCPE
protected void determineCPE(Dependency dependency) throws org.apache.lucene.index.CorruptIndexException, IOException, org.apache.lucene.queryparser.classic.ParseException, AnalysisException Searches the data store of CPE entries, trying to identify the CPE for the given dependency based on the evidence contained within. The dependency passed in is updated with any identified CPE values.- Parameters:
dependency- the dependency to search for CPE entries on- Throws:
org.apache.lucene.index.CorruptIndexException- is thrown when the Lucene index is corruptIOException- is thrown when an IOException occursorg.apache.lucene.queryparser.classic.ParseException- is thrown when the Lucene query cannot be parsedAnalysisException- thrown if the suppression rules failed
-
collectTerms
protected void collectTerms(Map<String, org.apache.commons.lang3.mutable.MutableInt> terms, Iterable<Evidence> evidence) Returns the text created by concatenating the text and the values from the EvidenceCollection (filtered for a specific confidence). This attempts to prevent duplicate terms from being added.
Note, if the evidence is longer then 1000 characters it will be truncated.
- Parameters:
terms- the collection of termsevidence- an iterable set of evidence to concatenate
-
searchCPE
protected List<IndexEntry> searchCPE(Map<String, org.apache.commons.lang3.mutable.MutableInt> vendor, Map<String, org.apache.commons.lang3.mutable.MutableInt> product, Set<String> vendorWeightings, Set<String> productWeightings, String ecosystem) Searches the Lucene CPE index to identify possible CPE entries associated with the supplied vendor, product, and version.
If either the vendorWeightings or productWeightings lists have been populated this data is used to add weighting factors to the search.
- Parameters:
vendor- the text used to search the vendor fieldproduct- the text used to search the product fieldvendorWeightings- a list of strings to use to add weighting factors to the vendor fieldproductWeightings- Adds a list of strings that will be used to add weighting factors to the product searchecosystem- the dependency's ecosystem- Returns:
- a list of possible CPE values
-
buildSearch
protected String buildSearch(Map<String, org.apache.commons.lang3.mutable.MutableInt> vendor, Map<String, org.apache.commons.lang3.mutable.MutableInt> product, Set<String> vendorWeighting, Set<String> productWeightings) Builds a Lucene search string by properly escaping data and constructing a valid search query.
If either the possibleVendor or possibleProducts lists have been populated this data is used to add weighting factors to the search string generated.
- Parameters:
vendor- text to search the vendor fieldproduct- text to search the product fieldvendorWeighting- a list of strings to apply to the vendor to boost the terms weightproductWeightings- a list of strings to apply to the product to boost the terms weight- Returns:
- the Lucene query
-
analyzeDependency
Analyzes a dependency and attempts to determine if there are any CPE identifiers for this dependency.- Specified by:
analyzeDependencyin classAbstractAnalyzer- Parameters:
dependency- The Dependency to analyze.engine- The analysis engine- Throws:
AnalysisException- is thrown if there is an issue analyzing the dependency.
-
determineIdentifiers
protected boolean determineIdentifiers(Dependency dependency, String vendor, String product, Confidence currentConfidence) throws AnalysisException Retrieves a list of CPE values from the CveDB based on the vendor and product passed in. The list is then validated to find only CPEs that are valid for the given dependency. It is possible that the CPE identified is a best effort "guess" based on the vendor, product, and version information.- Parameters:
dependency- the Dependency being analyzedvendor- the vendor for the CPE being analyzedproduct- the product for the CPE being analyzedcurrentConfidence- the current confidence being used during analysis- Returns:
trueif an identifier was added to the dependency; otherwisefalse- Throws:
AnalysisException- thrown if the suppression rules failed
-
getAnalyzerEnabledSettingKey
Returns the setting key to determine if the analyzer is enabled.
- Specified by:
getAnalyzerEnabledSettingKeyin classAbstractAnalyzer- Returns:
- the key for the analyzer's enabled property
-
main
Command line tool for querying the Lucene CPE Index.- Parameters:
args- not used
-
setCveDB
-
getCveDB
-
setMemoryIndex
Sets the MemoryIndex.- Parameters:
idx- the memory index
-
getMemoryIndex
-
setCpeSuppressionAnalyzer
Sets the CPE Suppression Analyzer.- Parameters:
suppression- the CPE Suppression Analyzer
-