Class CveDB
- java.lang.Object
- 
- org.owasp.dependencycheck.data.nvdcve.CveDB
 
- 
- All Implemented Interfaces:
- java.lang.AutoCloseable
 
 @ThreadSafe public final class CveDB extends java.lang.Object implements java.lang.AutoCloseableThe database holding information about the NVD CVE data. This class is safe to be accessed from multiple threads in parallel, however internally only one connection will be used.- Author:
- Jeremy Long
 
- 
- 
Field SummaryFields Modifier and Type Field Description static java.lang.StringDB_ECOSYSTEM_CACHEResource location for SQL file containing updates to the ecosystem cache.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddCpe(java.lang.String cpe, java.lang.String vendor, java.lang.String product)This method is only referenced in unused code and will likely break on MySQL if ever used due to the MERGE statement.voidcleanupDatabase()It is possible that orphaned rows may be generated during database updates.voidclose()Closes the database connection.booleandataExists()Checks to see if data exists so that analysis can be performed.voiddefrag()If the database is using an H2 file based database callingdefrag()will de-fragment the database.voiddeleteUnusedCpe()This method is only referenced in unused code.protected voidfinalize()Cleans up the object and ensures that "close" has been called.java.util.Set<CpePlus>getCPEs(java.lang.String vendor, java.lang.String product)Searches the CPE entries in the database and retrieves all entries for a given vendor and product combination.DatabasePropertiesgetDatabaseProperties()Get the value of databaseProperties.java.util.Map<java.lang.String,Vulnerability>getknownExploitedVulnerabilities()Returns a map of known exploited vulnerabilities.java.util.PropertiesgetProperties()Returns a set of properties.java.util.Set<Pair<java.lang.String,java.lang.String>>getVendorProductList()Returns the entire list of vendor/product combinations.java.util.Set<Pair<java.lang.String,java.lang.String>>getVendorProductListForNode()Returns the entire list of vendor/product combinations filtered for just Node JS related products.java.util.List<Vulnerability>getVulnerabilities(us.springett.parsers.cpe.Cpe cpe)Retrieves the vulnerabilities associated with the specified CPE.VulnerabilitygetVulnerability(java.lang.String cve)Gets a vulnerability for the provided CVE.VulnerabilitygetVulnerability(java.lang.String cve, java.sql.Connection conn)Gets a vulnerability for the provided CVE.booleanisOpen()Returns whether the database connection is open or closed.voidopen()Opens the database connection pool.voidpersistEcosystemCache()Persist the EcosystemCache into the database.voidsaveProperty(java.lang.String key, java.lang.String value)Saves a property to the database.intupdateEcosystemCache()Updates the EcoSystem Cache.voidupdateKnownExploitedVulnerabilities(java.util.List<Vulnerability> vulnerabilities)Merges the list of known exploited vulnerabilities into the database.voidupdateVulnerability(io.github.jeremylong.openvulnerability.client.nvd.DefCveItem cve, java.lang.String baseEcosystem)Updates the vulnerability within the database.
 
- 
- 
- 
Field Detail- 
DB_ECOSYSTEM_CACHEpublic static final java.lang.String DB_ECOSYSTEM_CACHE Resource location for SQL file containing updates to the ecosystem cache.- See Also:
- Constant Field Values
 
 
- 
 - 
Constructor Detail- 
CveDBpublic CveDB(Settings settings) throws DatabaseException Creates a new CveDB object and opens the database connection. Note, the connection must be closed by the caller by calling the close method.- Parameters:
- settings- the configured settings
- Throws:
- DatabaseException- thrown if there is an exception opening the database.
 
 
- 
 - 
Method Detail- 
updateEcosystemCachepublic int updateEcosystemCache() Updates the EcoSystem Cache.- Returns:
- The number of records updated by the DB_ECOSYSTEM_CACHE update script.
 
 - 
openpublic void open() Opens the database connection pool.
 - 
closepublic void close() Closes the database connection. Close should be called on this object when it is done being used.- Specified by:
- closein interface- java.lang.AutoCloseable
 
 - 
isOpenpublic boolean isOpen() Returns whether the database connection is open or closed.- Returns:
- whether the database connection is open or closed
 
 - 
finalizeprotected void finalize() throws java.lang.ThrowableCleans up the object and ensures that "close" has been called.- Overrides:
- finalizein class- java.lang.Object
- Throws:
- java.lang.Throwable- thrown if there is a problem
 
 - 
getDatabasePropertiespublic DatabaseProperties getDatabaseProperties() Get the value of databaseProperties.- Returns:
- the value of databaseProperties
 
 - 
getCPEspublic java.util.Set<CpePlus> getCPEs(java.lang.String vendor, java.lang.String product) Searches the CPE entries in the database and retrieves all entries for a given vendor and product combination. The returned list will include all versions of the product that are registered in the NVD CVE data.- Parameters:
- vendor- the identified vendor name of the dependency being analyzed
- product- the identified name of the product of the dependency being analyzed
- Returns:
- a set of vulnerable software
 
 - 
getVendorProductListpublic java.util.Set<Pair<java.lang.String,java.lang.String>> getVendorProductList() throws DatabaseException Returns the entire list of vendor/product combinations.- Returns:
- the entire list of vendor/product combinations
- Throws:
- DatabaseException- thrown when there is an error retrieving the data from the DB
 
 - 
getVendorProductListForNodepublic java.util.Set<Pair<java.lang.String,java.lang.String>> getVendorProductListForNode() throws DatabaseException Returns the entire list of vendor/product combinations filtered for just Node JS related products.- Returns:
- the list of vendor/product combinations that are known to be related to Node JS
- Throws:
- DatabaseException- thrown when there is an error retrieving the data from the DB
 
 - 
getPropertiespublic java.util.Properties getProperties() Returns a set of properties.- Returns:
- the properties from the database
 
 - 
savePropertypublic void saveProperty(java.lang.String key, java.lang.String value)Saves a property to the database.- Parameters:
- key- the property key
- value- the property value
 
 - 
getVulnerabilitiespublic java.util.List<Vulnerability> getVulnerabilities(us.springett.parsers.cpe.Cpe cpe) throws DatabaseException Retrieves the vulnerabilities associated with the specified CPE.- Parameters:
- cpe- the CPE to retrieve vulnerabilities for
- Returns:
- a list of Vulnerabilities
- Throws:
- DatabaseException- thrown if there is an exception retrieving data
 
 - 
getVulnerabilitypublic Vulnerability getVulnerability(java.lang.String cve) throws DatabaseException Gets a vulnerability for the provided CVE.- Parameters:
- cve- the CVE to lookup
- Returns:
- a vulnerability object
- Throws:
- DatabaseException- if an exception occurs
 
 - 
getVulnerabilitypublic Vulnerability getVulnerability(java.lang.String cve, java.sql.Connection conn) throws DatabaseException Gets a vulnerability for the provided CVE.- Parameters:
- cve- the CVE to lookup
- conn- already active database connection
- Returns:
- a vulnerability object
- Throws:
- DatabaseException- if an exception occurs
 
 - 
updateVulnerabilitypublic void updateVulnerability(io.github.jeremylong.openvulnerability.client.nvd.DefCveItem cve, java.lang.String baseEcosystem)Updates the vulnerability within the database. If the vulnerability does not exist it will be added.- Parameters:
- cve- the vulnerability from the NVD CVE Data Feed to add to the database
- baseEcosystem- the ecosystem the CVE belongs to; this is based off of things like the CVE description
- Throws:
- DatabaseException- is thrown if the database
 
 - 
updateKnownExploitedVulnerabilitiespublic void updateKnownExploitedVulnerabilities(java.util.List<Vulnerability> vulnerabilities) throws DatabaseException, java.sql.SQLException Merges the list of known exploited vulnerabilities into the database.- Parameters:
- vulnerabilities- the list of known exploited vulnerabilities
- Throws:
- DatabaseException- thrown if there is an exception... duh..
- java.sql.SQLException- thrown if there is an exception... duh..
 
 - 
dataExistspublic boolean dataExists() Checks to see if data exists so that analysis can be performed.- Returns:
- trueif data exists; otherwise- false
 
 - 
cleanupDatabasepublic void cleanupDatabase() It is possible that orphaned rows may be generated during database updates. This should be called after all updates have been completed to ensure orphan entries are removed.
 - 
persistEcosystemCachepublic void persistEcosystemCache() Persist the EcosystemCache into the database.
 - 
defragpublic void defrag() If the database is using an H2 file based database callingdefrag()will de-fragment the database.
 - 
deleteUnusedCpepublic void deleteUnusedCpe() This method is only referenced in unused code.Deletes unused dictionary entries from the database. 
 - 
addCpepublic void addCpe(java.lang.String cpe, java.lang.String vendor, java.lang.String product)This method is only referenced in unused code and will likely break on MySQL if ever used due to the MERGE statement.Merges CPE entries into the database. - Parameters:
- cpe- the CPE identifier
- vendor- the CPE vendor
- product- the CPE product
 
 - 
getknownExploitedVulnerabilitiespublic java.util.Map<java.lang.String,Vulnerability> getknownExploitedVulnerabilities() Returns a map of known exploited vulnerabilities.- Returns:
- a map of known exploited vulnerabilities
 
 
- 
 
-