Class CveDB
java.lang.Object
org.owasp.dependencycheck.data.nvdcve.CveDB
- All Implemented Interfaces:
AutoCloseable
The 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 Summary
FieldsModifier and TypeFieldDescriptionstatic final StringResource location for SQL file containing updates to the ecosystem cache. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidThis method is only referenced in unused code and will likely break on MySQL if ever used due to the MERGE statement.voidIt is possible that orphaned rows may be generated during database updates.voidclose()Closes the database connection.booleanChecks 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.voidThis method is only referenced in unused code.protected voidfinalize()Cleans up the object and ensures that "close" has been called.Searches the CPE entries in the database and retrieves all entries for a given vendor and product combination.Get the value of databaseProperties.Returns a map of known exploited vulnerabilities.Returns a set of properties.Returns the entire list of vendor/product combinations.Returns the entire list of vendor/product combinations filtered for just Node JS related products.getVulnerabilities(us.springett.parsers.cpe.Cpe cpe) Retrieves the vulnerabilities associated with the specified CPE.getVulnerability(String cve) Gets a vulnerability for the provided CVE.getVulnerability(String cve, 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.voidPersist the EcosystemCache into the database.voidsaveProperty(String key, String value) Saves a property to the database.intUpdates the EcoSystem Cache.voidupdateKnownExploitedVulnerabilities(List<Vulnerability> vulnerabilities) Merges the list of known exploited vulnerabilities into the database.voidupdateVulnerability(io.github.jeremylong.openvulnerability.client.nvd.DefCveItem cve, String baseEcosystem) Updates the vulnerability within the database.
-
Field Details
-
DB_ECOSYSTEM_CACHE
Resource location for SQL file containing updates to the ecosystem cache.- See Also:
-
-
Constructor Details
-
CveDB
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 Details
-
updateEcosystemCache
public int updateEcosystemCache()Updates the EcoSystem Cache.- Returns:
- The number of records updated by the DB_ECOSYSTEM_CACHE update script.
-
open
public void open()Opens the database connection pool. -
close
public void close()Closes the database connection. Close should be called on this object when it is done being used.- Specified by:
closein interfaceAutoCloseable
-
isOpen
public boolean isOpen()Returns whether the database connection is open or closed.- Returns:
- whether the database connection is open or closed
-
finalize
-
getDatabaseProperties
Get the value of databaseProperties.- Returns:
- the value of databaseProperties
-
getCPEs
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 analyzedproduct- the identified name of the product of the dependency being analyzed- Returns:
- a set of vulnerable software
-
getVendorProductList
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
-
getVendorProductListForNode
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
-
getProperties
Returns a set of properties.- Returns:
- the properties from the database
-
saveProperty
-
getVulnerabilities
public 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
-
getVulnerability
Gets a vulnerability for the provided CVE.- Parameters:
cve- the CVE to lookup- Returns:
- a vulnerability object
- Throws:
DatabaseException- if an exception occurs
-
getVulnerability
Gets a vulnerability for the provided CVE.- Parameters:
cve- the CVE to lookupconn- already active database connection- Returns:
- a vulnerability object
- Throws:
DatabaseException- if an exception occurs
-
updateVulnerability
public void updateVulnerability(io.github.jeremylong.openvulnerability.client.nvd.DefCveItem cve, 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 databasebaseEcosystem- the ecosystem the CVE belongs to; this is based off of things like the CVE description- Throws:
DatabaseException- is thrown if the database
-
updateKnownExploitedVulnerabilities
public void updateKnownExploitedVulnerabilities(List<Vulnerability> vulnerabilities) throws DatabaseException, 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..SQLException- thrown if there is an exception... duh..
-
dataExists
public boolean dataExists()Checks to see if data exists so that analysis can be performed.- Returns:
trueif data exists; otherwisefalse
-
cleanupDatabase
public 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. -
persistEcosystemCache
public void persistEcosystemCache()Persist the EcosystemCache into the database. -
defrag
public void defrag()If the database is using an H2 file based database callingdefrag()will de-fragment the database. -
deleteUnusedCpe
public void deleteUnusedCpe()This method is only referenced in unused code.Deletes unused dictionary entries from the database.
-
addCpe
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 identifiervendor- the CPE vendorproduct- the CPE product
-
getknownExploitedVulnerabilities
Returns a map of known exploited vulnerabilities.- Returns:
- a map of known exploited vulnerabilities
-