Skip to content

fix: plumb --use-mirror to work with new style #5178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 15 additions & 19 deletions cve_bin_tool/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
ErrorMode,
InsufficientArgs,
InvalidExtensionError,
MirrorError,
PDFOutputUnavailable,
VEXError,
excepthook,
Expand Down Expand Up @@ -814,12 +813,21 @@ def main(argv=None):
enabled_sources.append(source_epss)

if "NVD" not in disabled_sources:
source_nvd = nvd_source.NVD_Source(
nvd_type=nvd_type,
incremental_update=incremental_db_update,
nvd_api_key=args["nvd_api_key"],
error_mode=error_mode,
)
if args["use_mirror"]:
source_nvd = nvd_source.NVD_Source(
nvd_type=nvd_type,
incremental_update=incremental_db_update,
nvd_api_key=args["nvd_api_key"],
error_mode=error_mode,
feed=args["use_mirror"],
)
else:
source_nvd = nvd_source.NVD_Source(
nvd_type=nvd_type,
incremental_update=incremental_db_update,
nvd_api_key=args["nvd_api_key"],
error_mode=error_mode,
)
enabled_sources = [source_nvd] + enabled_sources

# Database update related settings
Expand All @@ -844,18 +852,6 @@ def main(argv=None):
)
return ERROR_CODES[CVEDBNotExist]

if args["use_mirror"] and not args["offline"]:
if (
cvedb_orig.fetch_from_mirror(
mirror=args["use_mirror"],
pubkey=args["verify"],
ignore_signature=args["ignore_sig"],
log_signature_error=args["log_signature_error"],
)
== -1
):
return ERROR_CODES[MirrorError]

# import database from JSON chopped by years
if args["import_json"] and cvedb_orig.check_db_exists():
return_code = cvedb_orig.json_to_db_wrapper(
Expand Down
28 changes: 0 additions & 28 deletions cve_bin_tool/cvedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import sqlite3
import tempfile
from datetime import date
from os import utime
from pathlib import Path
from typing import Any

Expand All @@ -38,7 +37,6 @@
OLD_CACHE_DIR,
)
from cve_bin_tool.error_handler import ERROR_CODES, CVEDBError, ErrorMode, SigningError
from cve_bin_tool.fetch_json_db import Fetch_JSON_DB
from cve_bin_tool.log import LOGGER
from cve_bin_tool.util import make_http_requests
from cve_bin_tool.version import check_latest_version
Expand Down Expand Up @@ -1156,32 +1154,6 @@ def json_to_db_wrapper(self, path, pubkey, ignore_signature, log_signature_error
)
return -1

def fetch_from_mirror(self, mirror, pubkey, ignore_signature, log_signature_error):
"""Get JSON information from download mirror."""
if not self.cachedir.exists():
self.cachedir.mkdir()
json_db = Fetch_JSON_DB(
mirror=mirror,
pubkey=pubkey,
ignore_signature=ignore_signature,
cache_dir=self.cachedir,
log_signature_error=log_signature_error,
error_mode=self.error_mode,
)
run_coroutine(json_db.handle_download())
json_data_path = self.cachedir / "json_data"
if (json_data_path / "metadata.json").exists() and self.json_to_db_wrapper(
path=json_data_path,
pubkey=pubkey,
ignore_signature=ignore_signature,
log_signature_error=log_signature_error,
) != -1:
self.time_of_last_update = json_db.metadata["timestamp"]
utime(self.dbpath, (self.time_of_last_update, self.time_of_last_update))
else:
self.clear_cached_data()
return -1

@contextlib.contextmanager
def with_cursor(self):
"""Context manager for database cursor."""
Expand Down
3 changes: 1 addition & 2 deletions cve_bin_tool/data_sources/nvd_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ class NVD_Source(Data_Source):
LOGGER = LOGGER.getChild("CVEDB")
NVDCVE_FILENAME_TEMPLATE = NVD_FILENAME_TEMPLATE
META_LINK_NVD = "https://nvd.nist.gov"
META_LINK_MIRROR = "https://v4.mirror.cveb.in/nvd/json/cve/1.1"
META_REGEX_NVD = re.compile(r"feeds\/json\/.*-[0-9]*\.[0-9]*-[0-9]*\.meta")
META_REGEX_MIRROR = re.compile(r"nvdcve-[0-9]*\.[0-9]*-[0-9]*\.meta")
RANGE_UNSET = ""
Expand Down Expand Up @@ -522,7 +521,7 @@ async def nist_scrape(self, session: RateLimiter):
meta_host = self.META_LINK_NVD
else:
json_meta_links = self.META_REGEX_MIRROR.findall(page)
meta_host = self.META_LINK_MIRROR
meta_host = self.feed
return dict(
await asyncio.gather(
*(
Expand Down
226 changes: 0 additions & 226 deletions cve_bin_tool/fetch_json_db.py

This file was deleted.

Loading