Class CPEAnalyzer
- java.lang.Object
- 
- org.owasp.dependencycheck.analyzer.AbstractAnalyzer
- 
- org.owasp.dependencycheck.analyzer.CPEAnalyzer
 
 
- 
- All Implemented Interfaces:
- Analyzer
 - Direct Known Subclasses:
- NpmCPEAnalyzer
 
 @ThreadSafe public class CPEAnalyzer extends AbstractAnalyzer CPEAnalyzer is a utility class that takes a project dependency and attempts to discern if there is an associated CPE. It uses the evidence contained within the dependency to search the Lucene index.- Author:
- Jeremy Long
 
- 
- 
Constructor SummaryConstructors Constructor Description CPEAnalyzer()
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidanalyzeDependency(Dependency dependency, Engine engine)Analyzes a dependency and attempts to determine if there are any CPE identifiers for this dependency.protected java.lang.StringbuildSearch(java.util.Map<java.lang.String,org.apache.commons.lang3.mutable.MutableInt> vendor, java.util.Map<java.lang.String,org.apache.commons.lang3.mutable.MutableInt> product, java.util.Set<java.lang.String> vendorWeighting, java.util.Set<java.lang.String> productWeightings)Builds a Lucene search string by properly escaping data and constructing a valid search query.voidcloseAnalyzer()Closes the data sources.protected voidcollectTerms(java.util.Map<java.lang.String,org.apache.commons.lang3.mutable.MutableInt> terms, java.lang.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, java.lang.String vendor, java.lang.String product, Confidence currentConfidence)Retrieves a list of CPE values from the CveDB based on the vendor and product passed in.AnalysisPhasegetAnalysisPhase()Returns the analysis phase that this analyzer should run in.protected java.lang.StringgetAnalyzerEnabledSettingKey()Returns the setting key to determine if the analyzer is enabled.protected CveDBgetCveDB()returns a reference to the CveDB.protected MemoryIndexgetMemoryIndex()Returns the memory index.java.lang.StringgetName()Returns the name of this analyzer.static voidmain(java.lang.String[] args)Command line tool for querying the Lucene CPE Index.voidopen(CveDB cve)Opens the data source.voidprepareAnalyzer(Engine engine)Creates the CPE Lucene Index.protected java.util.List<IndexEntry>searchCPE(java.util.Map<java.lang.String,org.apache.commons.lang3.mutable.MutableInt> vendor, java.util.Map<java.lang.String,org.apache.commons.lang3.mutable.MutableInt> product, java.util.Set<java.lang.String> vendorWeightings, java.util.Set<java.lang.String> productWeightings, java.lang.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 voidsetCveDB(CveDB cveDb)Sets the reference to the CveDB.protected voidsetMemoryIndex(MemoryIndex idx)Sets the MemoryIndex.- 
Methods inherited from class org.owasp.dependencycheck.analyzer.AbstractAnalyzeranalyze, close, getSettings, initialize, isEnabled, prepare, setEnabled, supportsParallelProcessing
 
- 
 
- 
- 
- 
Method Detail- 
getNamepublic java.lang.String getName() Returns the name of this analyzer.- Returns:
- the name of this analyzer.
 
 - 
getAnalysisPhasepublic AnalysisPhase getAnalysisPhase() Returns the analysis phase that this analyzer should run in.- Returns:
- the analysis phase that this analyzer should run in.
 
 - 
prepareAnalyzerpublic void prepareAnalyzer(Engine engine) throws InitializationException Creates the CPE Lucene Index.- Overrides:
- prepareAnalyzerin class- AbstractAnalyzer
- Parameters:
- engine- a reference to the dependency-check engine
- Throws:
- InitializationException- is thrown if there is an issue opening the index.
 
 - 
openpublic void open(CveDB cve) throws java.io.IOException, DatabaseException Opens the data source.- Parameters:
- cve- a reference to the NVD CVE database
- Throws:
- java.io.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.
 
 - 
closeAnalyzerpublic void closeAnalyzer() Closes the data sources.- Overrides:
- closeAnalyzerin class- AbstractAnalyzer
 
 - 
determineCPEprotected void determineCPE(Dependency dependency) throws org.apache.lucene.index.CorruptIndexException, java.io.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 corrupt
- java.io.IOException- is thrown when an IOException occurs
- org.apache.lucene.queryparser.classic.ParseException- is thrown when the Lucene query cannot be parsed
- AnalysisException- thrown if the suppression rules failed
 
 - 
collectTermsprotected void collectTerms(java.util.Map<java.lang.String,org.apache.commons.lang3.mutable.MutableInt> terms, java.lang.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 terms
- evidence- an iterable set of evidence to concatenate
 
 - 
searchCPEprotected java.util.List<IndexEntry> searchCPE(java.util.Map<java.lang.String,org.apache.commons.lang3.mutable.MutableInt> vendor, java.util.Map<java.lang.String,org.apache.commons.lang3.mutable.MutableInt> product, java.util.Set<java.lang.String> vendorWeightings, java.util.Set<java.lang.String> productWeightings, java.lang.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 field
- product- the text used to search the product field
- vendorWeightings- a list of strings to use to add weighting factors to the vendor field
- productWeightings- Adds a list of strings that will be used to add weighting factors to the product search
- ecosystem- the dependency's ecosystem
- Returns:
- a list of possible CPE values
 
 - 
buildSearchprotected java.lang.String buildSearch(java.util.Map<java.lang.String,org.apache.commons.lang3.mutable.MutableInt> vendor, java.util.Map<java.lang.String,org.apache.commons.lang3.mutable.MutableInt> product, java.util.Set<java.lang.String> vendorWeighting, java.util.Set<java.lang.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 field
- product- text to search the product field
- vendorWeighting- a list of strings to apply to the vendor to boost the terms weight
- productWeightings- a list of strings to apply to the product to boost the terms weight
- Returns:
- the Lucene query
 
 - 
analyzeDependencyprotected void analyzeDependency(Dependency dependency, Engine engine) throws AnalysisException Analyzes a dependency and attempts to determine if there are any CPE identifiers for this dependency.- Specified by:
- analyzeDependencyin class- AbstractAnalyzer
- Parameters:
- dependency- The Dependency to analyze.
- engine- The analysis engine
- Throws:
- AnalysisException- is thrown if there is an issue analyzing the dependency.
 
 - 
determineIdentifiersprotected boolean determineIdentifiers(Dependency dependency, java.lang.String vendor, java.lang.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 analyzed
- vendor- the vendor for the CPE being analyzed
- product- the product for the CPE being analyzed
- currentConfidence- the current confidence being used during analysis
- Returns:
- trueif an identifier was added to the dependency; otherwise- false
- Throws:
- AnalysisException- thrown if the suppression rules failed
 
 - 
getAnalyzerEnabledSettingKeyprotected java.lang.String getAnalyzerEnabledSettingKey() Returns the setting key to determine if the analyzer is enabled. - Specified by:
- getAnalyzerEnabledSettingKeyin class- AbstractAnalyzer
- Returns:
- the key for the analyzer's enabled property
 
 - 
mainpublic static void main(java.lang.String[] args) Command line tool for querying the Lucene CPE Index.- Parameters:
- args- not used
 
 - 
setCveDBprotected void setCveDB(CveDB cveDb) Sets the reference to the CveDB.- Parameters:
- cveDb- the CveDB
 
 - 
getCveDBprotected CveDB getCveDB() returns a reference to the CveDB.- Returns:
- a reference to the CveDB
 
 - 
setMemoryIndexprotected void setMemoryIndex(MemoryIndex idx) Sets the MemoryIndex.- Parameters:
- idx- the memory index
 
 - 
getMemoryIndexprotected MemoryIndex getMemoryIndex() Returns the memory index.- Returns:
- the memory index
 
 - 
setCpeSuppressionAnalyzerprotected void setCpeSuppressionAnalyzer(CpeSuppressionAnalyzer suppression) Sets the CPE Suppression Analyzer.- Parameters:
- suppression- the CPE Suppression Analyzer
 
 
- 
 
-