Class NvdCveClientBuilder

java.lang.Object
io.github.jeremylong.openvulnerability.client.nvd.NvdCveClientBuilder
All Implemented Interfaces:
Cloneable

public final class NvdCveClientBuilder extends Object implements Cloneable
Used to build an NVD CVE API client. As the NvdCveClient client is autocloseable the builder should be used in a try with resources:
 try (NvdCveClient api = NvdCveClientBuilder.aNvdCveApi().build()) {
     while (api.hasNext()) {
         Collection<DefCveItem> items = api.next();
     }
 }
 
  • Field Details

    • LOG

      private static final org.slf4j.Logger LOG
      Reference to the logger.
    • filters

      private final List<org.apache.hc.core5.http.NameValuePair> filters
      A list of filters to apply to the request.
    • apiKey

      private String apiKey
      The NVD CVE API key.
    • endpoint

      private String endpoint
      The endpoint for the NVD CVE API.
    • resultsPerPage

      private int resultsPerPage
      The number of results per page.
    • delay

      private long delay
      The minimum delay between API calls in milliseconds.
    • maxRetryCount

      private int maxRetryCount
      The maximum number of retries for 503 and 429 responses from the NVD.
    • requestsPerThirtySeconds

      private int requestsPerThirtySeconds
      The number of requests to make per a rolling 30-seconds.
    • maxPageCount

      private int maxPageCount
      The maximum number of pages to retrieve from the NVD API.
    • cacheDirectory

      private Path cacheDirectory
      The directory to cache the NVD CVE API responses.
    • httpClientSupplier

      private HttpAsyncClientSupplier httpClientSupplier
    • userAgent

      private String userAgent
      The user agent to append to the default open-vulnerability-client's user-agent string
  • Constructor Details

    • NvdCveClientBuilder

      private NvdCveClientBuilder()
      Private constructor for a builder.
  • Method Details

    • aNvdCveApi

      public static NvdCveClientBuilder aNvdCveApi()
      Begin building the NVD CVE API Object.
      Returns:
      the builder
    • withApiKey

      public NvdCveClientBuilder withApiKey(String apiKey)
      Use an NVD CVE API key.
      Parameters:
      apiKey - the NVD CVE API key.
      Returns:
      the builder
      See Also:
    • withEndpoint

      public NvdCveClientBuilder withEndpoint(String endpoint)
      Use an alternative endpoint for the NVD CVE API.
      Parameters:
      endpoint - the endpoint for the NVD CVE API
      Returns:
      the builder
    • withCacheDirectory

      public NvdCveClientBuilder withCacheDirectory(Path cacheDirectory)
      Sets the directory to cache the NVD CVE API responses. This should only be used if downloading the entire set of CVE data from the NVD API. If the cache directory is used and there is an interruption in the download - under rare cases if the NVD updated the CVE data - the cache directory will not be updated and as such, the mirror may be out of sync. If using the cache directory and an interruption occurs, it is recommended to try again within 20 hours and if succesful, perform another update to retrieve the entries modified within the last 20 hours.
      Parameters:
      cacheDirectory - the directory to cache the NVD CVE API responses
      Returns:
      the builder
    • withDelay

      public NvdCveClientBuilder withDelay(long milliseconds)
      Use a minimum delay in milliseconds between API calls; useful if you run into issues with rate limiting.
      Parameters:
      milliseconds - the minimum number of milliseconds between API calls to the NVD CVE API
      Returns:
      the builder
    • withMaxRetryCount

      public NvdCveClientBuilder withMaxRetryCount(int maxRetryCount)
      Set the maximum number of retries for 503 and 429 responses from the NVD; default is 10.
      Parameters:
      maxRetryCount - the maximum number of retries for 503 and 429 responses from the NVD.
      Returns:
      the builder
    • withrequestsPerThirtySeconds

      @Deprecated public NvdCveClientBuilder withrequestsPerThirtySeconds(int requestsPerThirtySeconds)
      Deprecated.
      Set the number of requests to make in a rolling 30-seconds.
      Parameters:
      requestsPerThirtySeconds - the number of requests to make in a rolling 30-seconds.
      Returns:
      the builder
    • withRequestsPerThirtySeconds

      public NvdCveClientBuilder withRequestsPerThirtySeconds(int requestsPerThirtySeconds)
      Set the number of requests to make in a rolling 30-seconds.
      Parameters:
      requestsPerThirtySeconds - the number of requests to make in a rolling 30-seconds.
      Returns:
      the builder
    • withMaxPageCount

      public NvdCveClientBuilder withMaxPageCount(int count)
      Set the maximum number of pages to retrieve from the NVD API.
      Parameters:
      count - the maximum number of pages to retrieve from the NVD API
      Returns:
      the builder
    • withResultsPerPage

      public NvdCveClientBuilder withResultsPerPage(int resultsPerPage)
      Use a specific number of results per page. Value must be between 1 and 2000. The default value is 2000.
      Parameters:
      resultsPerPage - the number of results per page
      Returns:
      the builder
    • withFilter

      public NvdCveClientBuilder withFilter(String filter, String value)
      Add a querystring parameter to filter the call to the NVD CVE API.
      Parameters:
      filter - the querystring parameter
      value - the querystring parameter value
      Returns:
      the builder
    • withFilter

      public NvdCveClientBuilder withFilter(NvdCveClientBuilder.Filter filter, String value)
      Add a querystring parameter to filter the call to the NVD CVE API.
      Parameters:
      filter - the querystring parameter
      value - the querystring parameter value
      Returns:
      the builder
    • withFilter

      Add a querystring parameter to filter the call to the NVD CVE API.
      Parameters:
      filter - the querystring parameter
      Returns:
      the builder
    • withLastModifiedFilter

      public NvdCveClientBuilder withLastModifiedFilter(ZonedDateTime utcStartDate, ZonedDateTime utcEndDate)
      Use a range of no more than 120 days on the last modified dates to filter the results. The ZonedDateTime objects must be set to UTC.
      Parameters:
      utcStartDate - the UTC date time for the range start
      utcEndDate - the UTC date time for the range end
      Returns:
      the builder
    • withAdditionalUserAgent

      public NvdCveClientBuilder withAdditionalUserAgent(String userAgent)
      Use an additional identifier as part of the User-Agent when making requests.
      Parameters:
      userAgent - the user agent string to append
      Returns:
      the builder
    • withPublishedDateFilter

      public NvdCveClientBuilder withPublishedDateFilter(ZonedDateTime utcStartDate, ZonedDateTime utcEndDate)
      Filter the results with a range of published date times. The ZonedDateTime objects must be set to UTC.
      Parameters:
      utcStartDate - the UTC date time for the range start
      utcEndDate - the UTC date time for the range end
      Returns:
      the builder
    • withCvssV2SeverityFilter

      public NvdCveClientBuilder withCvssV2SeverityFilter(NvdCveClientBuilder.CvssV2Severity severity)
      Filter the results for a specific CVSS V2 Severity.
      Parameters:
      severity - the severity
      Returns:
      the builder
    • withCvssV3SeverityFilter

      public NvdCveClientBuilder withCvssV3SeverityFilter(NvdCveClientBuilder.CvssV3Severity severity)
      Filter the results for a specific CVSS V3 Severity.
      Parameters:
      severity - the severity
      Returns:
      the builder
    • withVirtualMatchString

      public NvdCveClientBuilder withVirtualMatchString(String virtualMatchString)
      This parameter filters CVE more broadly than cpeName. The exact value of {cpe match string} is compared against the CPE Match Criteria present on CVE applicability statements.
      Parameters:
      virtualMatchString - virtual matching CPE
      Returns:
      the builder
      See Also:
    • withVersionStart

      public NvdCveClientBuilder withVersionStart(String versionStart)
      The virtualMatchString parameter may be combined with versionStart and versionStartType to return only the CVEs associated with CPEs in specific version ranges.
      Parameters:
      versionStart - the version start
      Returns:
      the builder
      See Also:
    • withVersionStart

      public NvdCveClientBuilder withVersionStart(String versionStart, NvdCveClientBuilder.VersionType startType)
      The virtualMatchString parameter may be combined with versionStart and versionStartType to return only the CVEs associated with CPEs in specific version ranges.
      Parameters:
      versionStart - the version start
      startType - including or excluding
      Returns:
      the builder
      See Also:
    • withVersionEnd

      public NvdCveClientBuilder withVersionEnd(String versionEnd)
      The virtualMatchString parameter may be combined with versionEnd and versionEndType to return only the CVEs associated with CPEs in specific version ranges.
      Parameters:
      versionEnd - the version end
      Returns:
      the builder
      See Also:
    • withVersionEnd

      public NvdCveClientBuilder withVersionEnd(String versionEnd, NvdCveClientBuilder.VersionType endType)
      The virtualMatchString parameter may be combined with versionEnd and versionEndType to return only the CVEs associated with CPEs in specific version ranges.
      Parameters:
      versionEnd - the version end
      endType - including or excluding
      Returns:
      the builder
      See Also:
    • withHttpClientSupplier

      public NvdCveClientBuilder withHttpClientSupplier(HttpAsyncClientSupplier httpClientSupplier)
      Provide a supplier for custom HTTP clients.

      Note that withDelay(long) and withMaxRetryCount(int) have no effect when a custom HttpAsyncClientSupplier is provided. Instead, clients created by the supplier should be configured to use NvdApiRetryStrategy with the desired delay and retry count values.

      Parameters:
      httpClientSupplier - supplier for custom HTTP clients; if null a default client will be used
      Returns:
      the builder
    • build

      public NvdCveClient build()
      Build the NVD CVE API client.
      Returns:
      the NVD CVE API client
    • clone

      public NvdCveClientBuilder clone()
      Clone the builder.
      Overrides:
      clone in class Object
      Returns:
      the clone