summaryrefslogtreecommitdiffstats
path: root/meta
diff options
context:
space:
mode:
authorYoann Congal <yoann.congal@smile.fr>2024-03-17 16:21:48 -1000
committerSteve Sakoman <steve@sakoman.com>2024-03-25 04:02:32 -1000
commit53afd9dc5b41d48af62ee5c1e3790bf8ed8061f9 (patch)
tree9391364f423e459d8ee78afa9535b025bbb5936f /meta
parent17634daabd9daa162a68ff57e814f099829c34e2 (diff)
downloadpoky-53afd9dc5b41d48af62ee5c1e3790bf8ed8061f9.tar.gz
cve-update-nvd2-native: Add an age threshold for incremental update
Add a new variable "CVE_DB_INCR_UPDATE_AGE_THRES", which can be used to specify the maximum age of the database for doing an incremental update For older databases, a full re-download is done. With a value of "0", this forces a full-redownload. (From OE-Core rev: c9a3e5a4ca297249f8fd7380a824dce0c407280b) Signed-off-by: Yoann Congal <yoann.congal@smile.fr> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org> (cherry picked from commit 74c1765111b6610348eae4b7e41d7045ce58ef86) Signed-off-by: Steve Sakoman <steve@sakoman.com>
Diffstat (limited to 'meta')
-rw-r--r--meta/recipes-core/meta/cve-update-nvd2-native.bb20
1 files changed, 16 insertions, 4 deletions
diff --git a/meta/recipes-core/meta/cve-update-nvd2-native.bb b/meta/recipes-core/meta/cve-update-nvd2-native.bb
index 9b6e746add..af21989d58 100644
--- a/meta/recipes-core/meta/cve-update-nvd2-native.bb
+++ b/meta/recipes-core/meta/cve-update-nvd2-native.bb
@@ -26,6 +26,12 @@ NVDCVE_API_KEY ?= ""
26# Use a negative value to skip the update 26# Use a negative value to skip the update
27CVE_DB_UPDATE_INTERVAL ?= "86400" 27CVE_DB_UPDATE_INTERVAL ?= "86400"
28 28
29# CVE database incremental update age threshold, in seconds. If the database is
30# older than this threshold, do a full re-download, else, do an incremental
31# update. By default: the maximum allowed value from NVD: 120 days (120*24*60*60)
32# Use 0 to force a full download.
33CVE_DB_INCR_UPDATE_AGE_THRES ?= "10368000"
34
29# Number of attempts for each http query to nvd server before giving up 35# Number of attempts for each http query to nvd server before giving up
30CVE_DB_UPDATE_ATTEMPTS ?= "5" 36CVE_DB_UPDATE_ATTEMPTS ?= "5"
31 37
@@ -172,18 +178,24 @@ def update_db_file(db_tmp_file, d, database_time):
172 178
173 req_args = {'startIndex' : 0} 179 req_args = {'startIndex' : 0}
174 180
175 # The maximum range for time is 120 days 181 incr_update_threshold = int(d.getVar("CVE_DB_INCR_UPDATE_AGE_THRES"))
176 # Force a complete update if our range is longer 182 if database_time != 0:
177 if (database_time != 0):
178 database_date = datetime.datetime.fromtimestamp(database_time, tz=datetime.timezone.utc) 183 database_date = datetime.datetime.fromtimestamp(database_time, tz=datetime.timezone.utc)
179 today_date = datetime.datetime.now(tz=datetime.timezone.utc) 184 today_date = datetime.datetime.now(tz=datetime.timezone.utc)
180 delta = today_date - database_date 185 delta = today_date - database_date
181 if delta.days < 120: 186 if incr_update_threshold == 0:
187 bb.note("CVE database: forced full update")
188 elif delta < datetime.timedelta(seconds=incr_update_threshold):
182 bb.note("CVE database: performing partial update") 189 bb.note("CVE database: performing partial update")
190 # The maximum range for time is 120 days
191 if delta > datetime.timedelta(days=120):
192 bb.error("CVE database: Trying to do an incremental update on a larger than supported range")
183 req_args['lastModStartDate'] = database_date.isoformat() 193 req_args['lastModStartDate'] = database_date.isoformat()
184 req_args['lastModEndDate'] = today_date.isoformat() 194 req_args['lastModEndDate'] = today_date.isoformat()
185 else: 195 else:
186 bb.note("CVE database: file too old, forcing a full update") 196 bb.note("CVE database: file too old, forcing a full update")
197 else:
198 bb.note("CVE database: no preexisting database, do a full download")
187 199
188 with bb.progress.ProgressHandler(d) as ph, open(os.path.join(d.getVar("TMPDIR"), 'cve_check'), 'a') as cve_f: 200 with bb.progress.ProgressHandler(d) as ph, open(os.path.join(d.getVar("TMPDIR"), 'cve_check'), 'a') as cve_f:
189 201