Skip to content

Commit

Permalink
feat: NVD API data feed
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremylong committed Oct 8, 2023
1 parent 9976450 commit 9681868
Show file tree
Hide file tree
Showing 17 changed files with 975 additions and 872 deletions.
6 changes: 5 additions & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Copyright (c) 2012 Jeremy Long. All Rights Reserved.
<artifactId>jsonschema2pojo-maven-plugin</artifactId>

<executions>
<!-- <execution>
<!-- <execution>
<id>generate-nvd</id>
<phase>generate-sources</phase>
<goals>
Expand Down Expand Up @@ -289,6 +289,10 @@ Copyright (c) 2012 Jeremy Long. All Rights Reserved.
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-afterburner</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
*
* @author Jeremy Long
*/
@Deprecated
public class MetaProperties {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.util.TreeMap;
import javax.annotation.concurrent.ThreadSafe;

import org.owasp.dependencycheck.data.update.nvd.NvdCveInfo;
import org.owasp.dependencycheck.data.update.exception.UpdateException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -50,30 +49,18 @@ public class DatabaseProperties {
* The last modified request data for the NVD API.
*/
public static final String NVD_API_LAST_MODIFIED = "nvd.api.last.modified";
/**
* The properties file key for the last checked field - used to store the
* last check time.
*/
public static final String NVD_LAST_CHECKED = "nvd.api.last.checked";

public static final String NVD_CACHE_LAST_MODIFIED_BASE = "nvd.cache.last.modified";
public static final String NVD_CACHE_LAST_CHECKED = "nvd.cache.last.checked";

public static final String NVD_CACHE_LAST_MODIFIED = "nvd.cache.last.modified";

// TODO DELETE START--------------------------------------------------------
/**
* Modified key word, used as a key to store information about the modified
* file (i.e. the containing the last 8 days of updates)..
*/
public static final String MODIFIED = "Modified";
/**
* The properties file key for the last checked field - used to store the
* last check time of the Modified NVD CVE xml file.
*/
public static final String LAST_CHECKED = "NVD CVE Checked";
/**
* The properties file key for the last updated field - used to store the
* last updated time of the Modified NVD CVE xml file.
*/
public static final String LAST_UPDATED = "NVD CVE Modified";

/**
* Stores the last updated time for each of the NVD CVE files. These
* timestamps should be updated if we process the modified file within 7
Expand Down Expand Up @@ -128,19 +115,6 @@ public synchronized boolean isEmpty() {
return properties == null || properties.isEmpty();
}

/**
* Saves the last updated information to the properties file.
*
* @param updatedValue the updated NVD CVE entry
* @throws UpdateException is thrown if there is an update exception
*/
public synchronized void save(NvdCveInfo updatedValue) throws UpdateException {
if (updatedValue == null) {
return;
}
save(LAST_UPDATED_BASE + updatedValue.getId(), String.valueOf(updatedValue.getTimestamp()));
}

/**
* Saves the key value pair to the properties store.
*
Expand Down Expand Up @@ -214,20 +188,15 @@ public synchronized Map<String, String> getMetaData() {
}
return map;
}

/**
* Retrieves a zoned date time.
*
* @param key the property key
* @return the zoned date time
*/
public ZonedDateTime getTimestamp(String key) {
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("uuuu-MM-dd'T'HH:mm:ssX");
if (properties.contains(key)) {
String value = properties.getProperty(key);
return ZonedDateTime.parse(value, dtf);
}
return null;
return DatabaseProperties.getTimestamp(properties,key);
}

/**
Expand All @@ -240,4 +209,22 @@ public void save(String key, ZonedDateTime timestamp) throws UpdateException {
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("uuuu-MM-dd'T'HH:mm:ssX");
save(key, dtf.format(timestamp));
}


/**
* Retrieves a zoned date time.
*
* @param properties the properties file containing the date time
* @param key the property key
* @return the zoned date time
*/
public static ZonedDateTime getTimestamp(Properties properties, String key) {
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("uuuu-MM-dd'T'HH:mm:ssX");
if (properties.contains(key)) {
String value = properties.getProperty(key);
return ZonedDateTime.parse(value, dtf);
}
return null;
}

}
Loading

0 comments on commit 9681868

Please sign in to comment.