Skip to content

Commit c656c23

Browse files
fix: Use of NVD api 2.0 (fixes #3541) (#3544)
1 parent f2df248 commit c656c23

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

cve_bin_tool/cli.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,9 @@ def main(argv=None):
550550
args["nvd_api_key"] = os.getenv("NVD_API_KEY")
551551

552552
if args["nvd_api_key"]:
553-
nvd_type = "api"
553+
if nvd_type != "api2":
554+
LOGGER.debug(f"{nvd_type} - changing to api. API Key {args['nvd_api_key']}")
555+
nvd_type = "api"
554556

555557
# If you're not using an NVD key, let you know how to get one
556558
if nvd_type == "json-nvd" and not args["nvd_api_key"] and not args["offline"]:

cve_bin_tool/nvd_api.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,14 @@ async def get_nvd_params(
168168
await self.validate_nvd_api()
169169

170170
if self.invalid_api:
171-
self.logger.warning(
172-
f'Unable to access NVD using provided API key: {self.params["apiKey"]}'
173-
)
171+
if self.api_version == "1.0":
172+
self.logger.warning(
173+
f'Unable to access NVD using provided API key: {self.params["apiKey"]}'
174+
)
175+
else:
176+
self.logger.warning(
177+
f'Unable to access NVD using provided API key: {self.header["apiKey"]}'
178+
)
174179
else:
175180
if time_of_last_update:
176181
# Fetch all the updated CVE entries from the modified date. Subtracting 2-minute offset for updating cve entries
@@ -228,7 +233,11 @@ async def validate_nvd_api(self):
228233
data = await response.json()
229234
if data.get("error", False):
230235
self.logger.error(f"NVD API error: {data['error']}")
231-
raise NVDKeyError(self.params["apiKey"])
236+
if self.api_version == "1.0":
237+
raise NVDKeyError(self.params["apiKey"])
238+
else:
239+
raise NVDKeyError(self.header["apiKey"])
240+
232241
except aiohttp.ClientResponseError as client_err:
233242
self.logger.debug(f"Response {client_err}")
234243
self.invalid_api = True
@@ -240,6 +249,9 @@ async def validate_nvd_api(self):
240249
if self.api_version == "1.0":
241250
del self.params["apiKey"]
242251
self.api_key = ""
252+
else:
253+
del self.header["apiKey"]
254+
self.api_key = ""
243255

244256
async def load_nvd_request(self, start_index):
245257
"""Get single NVD request and update year_wise_data list which contains list of all CVEs"""

0 commit comments

Comments
 (0)