summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDhairya Nagodra <dnagodra@cisco.com>2023-12-11 02:04:59 -0800
committerSteve Sakoman <steve@sakoman.com>2024-01-09 05:50:24 -1000
commit4f7e40652cdf647c28f7dc6052bfa5db6bc9d8fb (patch)
tree4f79980c7e81dbd679ebedf8dac4eb05f6e182b9
parent036969937e7c84cc068efe0355dd26281cf89f03 (diff)
downloadopenembedded-core-contrib-4f7e40652cdf647c28f7dc6052bfa5db6bc9d8fb.tar.gz
cve-update-nvd2-native: faster requests with API keys
As per NVD, the public rate limit is 5 requests in 30s (6s delay). Using an API key increases the limit to 50 requests in 30s (0.6s delay). However, NVD still recommends sleeping for several seconds so that the other legitimate requests are serviced without denial or interruption. Keeping the default sleep at 6 seconds and 2 seconds with an API key. For failures, the wait time is unchanged (6 seconds). Reference: https://nvd.nist.gov/developers/start-here#RateLimits Signed-off-by: Dhairya Nagodra <dnagodra@cisco.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> (cherry picked from commit 5c32e2941d1dc3d04a799a1b7cbd275c1ccc9e79) Signed-off-by: Steve Sakoman <steve@sakoman.com>
-rw-r--r--meta/recipes-core/meta/cve-update-nvd2-native.bb7
1 files changed, 6 insertions, 1 deletions
diff --git a/meta/recipes-core/meta/cve-update-nvd2-native.bb b/meta/recipes-core/meta/cve-update-nvd2-native.bb
index dab0b69edc..0a8b6a8a0a 100644
--- a/meta/recipes-core/meta/cve-update-nvd2-native.bb
+++ b/meta/recipes-core/meta/cve-update-nvd2-native.bb
@@ -188,6 +188,11 @@ def update_db_file(db_tmp_file, d, database_time):
api_key = d.getVar("NVDCVE_API_KEY") or None
attempts = int(d.getVar("CVE_DB_UPDATE_ATTEMPTS"))
+ # Recommended by NVD
+ wait_time = 6
+ if api_key:
+ wait_time = 2
+
while True:
req_args['startIndex'] = index
raw_data = nvd_request_next(url, attempts, api_key, req_args)
@@ -210,7 +215,7 @@ def update_db_file(db_tmp_file, d, database_time):
break
# Recommended by NVD
- time.sleep(6)
+ time.sleep(wait_time)
# Update success, set the date to cve_check file.
cve_f.write('CVE database update : %s\n\n' % datetime.date.today())