aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre Le Magourou <pierre.lemagourou@softbankrobotics.com>2019-06-26 14:25:58 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2019-06-27 12:20:24 +0100
commit09be21f4d1793b1e26e78391f51bfc0a27b76deb (patch)
treec42e4a66c0681efc1697d4ed89524ade58dc7524
parent3a035bd0a06a6ded4d0ce7e35a3bce42245727d2 (diff)
downloadopenembedded-core-contrib-09be21f4d1793b1e26e78391f51bfc0a27b76deb.tar.gz
openembedded-core-contrib-09be21f4d1793b1e26e78391f51bfc0a27b76deb.tar.bz2
openembedded-core-contrib-09be21f4d1793b1e26e78391f51bfc0a27b76deb.zip
cve-update-db: Manage proxy if needed.
If https_proxy environment variable is defined, manage proxy to be able to download meta and json data feeds from https://nvd.nist.gov Signed-off-by: Pierre Le Magourou <pierre.lemagourou@softbankrobotics.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/recipes-core/meta/cve-update-db.bb11
1 files changed, 9 insertions, 2 deletions
diff --git a/meta/recipes-core/meta/cve-update-db.bb b/meta/recipes-core/meta/cve-update-db.bb
index 1f48820cc6..4c896dc880 100644
--- a/meta/recipes-core/meta/cve-update-db.bb
+++ b/meta/recipes-core/meta/cve-update-db.bb
@@ -25,6 +25,7 @@ python do_populate_cve_db() {
BASE_URL = "https://nvd.nist.gov/feeds/json/cve/1.0/nvdcve-1.0-"
YEAR_START = 2002
JSON_TMPFILE = d.getVar("CVE_CHECK_DB_DIR") + '/nvd.json.gz'
+ proxy = d.getVar("https_proxy")
# Connect to database
db_file = d.getVar("CVE_CHECK_DB_FILE")
@@ -39,7 +40,10 @@ python do_populate_cve_db() {
json_url = year_url + ".json.gz"
# Retrieve meta last modified date
- with urllib.request.urlopen(meta_url) as r:
+ req = urllib.request.Request(meta_url)
+ if proxy:
+ req.set_proxy(proxy, 'https')
+ with urllib.request.urlopen(req) as r:
date_line = str(r.read().splitlines()[0])
last_modified = re.search('lastModifiedDate:(.*)', date_line).group(1)
@@ -48,7 +52,10 @@ python do_populate_cve_db() {
meta = c.fetchone()
if not meta or meta[0] != last_modified:
# Update db with current year json file
- with urllib.request.urlopen(json_url) as r, open(JSON_TMPFILE, 'wb') as tmpfile:
+ req = urllib.request.Request(json_url)
+ if proxy:
+ req.set_proxy(proxy, 'https')
+ with urllib.request.urlopen(req) as r, open(JSON_TMPFILE, 'wb') as tmpfile:
shutil.copyfileobj(r, tmpfile)
with gzip.open(JSON_TMPFILE, 'rt') as jsonfile:
update_db(c, jsonfile)