Skip to content

feat: Add options to import and export database (fixes #1655) #1656

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

Merged
merged 53 commits into from
Jun 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
771960a
Merge pull request #1 from intel/master
anthonyharrison May 27, 2020
20d6262
Merge remote-tracking branch 'upstream/master'
anthonyharrison Jun 1, 2020
5ab2c87
Merge remote-tracking branch 'upstream/master'
anthonyharrison Jul 18, 2020
ea57d05
Merge remote-tracking branch 'upstream/master'
anthonyharrison Aug 20, 2020
c2a8d1c
Merge remote-tracking branch 'upstream/master'
anthonyharrison Sep 1, 2020
7035ae9
Merge remote-tracking branch 'upstream/master'
anthonyharrison Sep 2, 2020
aaba9eb
Merge remote-tracking branch 'upstream/master'
anthonyharrison Sep 18, 2020
3b91b0e
Merge remote-tracking branch 'upstream/master'
anthonyharrison Oct 18, 2020
13fa1a8
Merge remote-tracking branch 'upstream/master'
anthonyharrison Nov 8, 2020
5db21eb
Merge remote-tracking branch 'upstream/master'
anthonyharrison Mar 14, 2021
9418560
Merge branch 'main'
anthonyharrison Mar 14, 2021
0f3f754
Merge branch 'main'
anthonyharrison Mar 24, 2021
9e04dab
Merge remote-tracking branch 'refs/remotes/upstream/main'
anthonyharrison May 30, 2021
da7e34a
Merge branch 'intel:main' into master
anthonyharrison Jun 20, 2021
8c9ea48
Merge branch 'intel:main' into master
anthonyharrison Jun 27, 2021
9581317
Merge branch 'intel:main' into master
anthonyharrison Jul 12, 2021
c59de25
Merge branch 'intel:main' into master
anthonyharrison Jul 25, 2021
bf5908a
Merge branch 'intel:main' into master
anthonyharrison Sep 3, 2021
2505e10
Merge branch 'intel:main' into master
anthonyharrison Sep 23, 2021
589b93d
Merge branch 'intel:main' into master
anthonyharrison Oct 13, 2021
42757cb
Merge branch 'intel:main' into master
anthonyharrison Oct 27, 2021
0f519a3
Merge branch 'intel:main' into master
anthonyharrison Nov 3, 2021
4e9f0e7
chore: update pre-commit config
web-flow Dec 1, 2021
4016283
Merge remote-tracking branch 'upstream/main'
anthonyharrison Dec 5, 2021
cd7b07a
Merge remote-tracking branch 'upstream/main'
anthonyharrison Dec 9, 2021
4197fde
Merge branch 'intel:main' into master
anthonyharrison Dec 12, 2021
6a9494b
Merge branch 'intel:main' into master
anthonyharrison Dec 20, 2021
187f669
Merge branch 'intel:main' into master
anthonyharrison Dec 23, 2021
03d40b2
Merge pull request #3 from anthonyharrison/chore-precommit-config
anthonyharrison Dec 28, 2021
5a9fc91
Merge remote-tracking branch 'upstream/main'
anthonyharrison Dec 28, 2021
38598df
Merge branch 'master' of https://github.com/anthonyharrison/cve-bin-t…
anthonyharrison Dec 28, 2021
53be88a
Merge remote-tracking branch 'upstream/main'
anthonyharrison Jan 12, 2022
076e16f
bug: set default version for xml2 checker to UNKNOWN (fixes #1517)
anthonyharrison Jan 12, 2022
6830930
Merge branch 'intel:main' into master
anthonyharrison Jan 18, 2022
047eecf
Merge branch 'intel:main' into master
anthonyharrison Jan 26, 2022
d78d40e
feat: Add XML schema validation (Fixes #1507)
anthonyharrison Jan 26, 2022
d61a04d
Revert "feat: Add XML schema validation (Fixes #1507)"
anthonyharrison Jan 26, 2022
fcfc11f
Merge branch 'intel:main' into master
anthonyharrison Feb 7, 2022
f6b21c0
Merge branch 'master' of git+ssh://github.com/anthonyharrison/cve-bin…
anthonyharrison Feb 7, 2022
c7c61a9
Merge branch 'intel:main' into master
anthonyharrison Feb 9, 2022
d08ef8a
Merge remote-tracking branch 'upstream/main'
anthonyharrison Feb 9, 2022
b9c7f22
Merge branch 'intel:main' into master
anthonyharrison Mar 20, 2022
c4ca795
Merge remote-tracking branch 'origin/master'
anthonyharrison Mar 20, 2022
70c6ebd
Merge remote-tracking branch 'upstream/main'
anthonyharrison Apr 15, 2022
4e91a0b
Merge remote-tracking branch 'upstream/main'
anthonyharrison Apr 15, 2022
e00b5a8
Merge remote-tracking branch 'upstream/main'
anthonyharrison May 2, 2022
b6cd33b
feat: Add command line options to import and export database (fixes #…
anthonyharrison May 2, 2022
547b442
Revert "feat: Add options to import and export database (fixes #1655)"
anthonyharrison May 2, 2022
05b5f38
feat: Add options to import and export database (fixes #1655)
anthonyharrison May 2, 2022
6da46e4
feat: Add command line options to import and export database (fixes #…
anthonyharrison May 2, 2022
05f56b2
Merge branch 'main' into pr-1655
terriko May 24, 2022
599b002
Merge branch 'main' into pr-1655
terriko May 26, 2022
6c66a53
feat: Add options to import and export database (fixes #1655)
anthonyharrison Jun 13, 2022
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ Usage:
comma-separated list of checkers to disable
-r RUNS, --runs RUNS comma-separated list of checkers to enable

Database Management:
--export EXPORT export database filename
--import IMPORT import database filename

Deprecated:
-x, --extract autoextract compressed files
CVE Binary Tool autoextracts all compressed files by default now
Expand Down
26 changes: 26 additions & 0 deletions cve_bin_tool/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,20 @@ def main(argv=None):
default="",
)

database_group = parser.add_argument_group("Database Management")
database_group.add_argument(
"--export",
action="store",
help="export database filename",
default="",
)
database_group.add_argument(
"--import",
action="store",
help="import database filename",
default="",
)

exploit_checker_group = parser.add_argument_group("Exploits")
exploit_checker_group.add_argument(
"--exploits",
Expand Down Expand Up @@ -473,6 +487,18 @@ def main(argv=None):
)
return -1

# Import database if file exists
if args["import"] and os.path.exists(args["import"]):
LOGGER.info(f'Import database from {args["import"]}')
cvedb_orig.copy_db(filename=args["import"], export=False)

# Export database if database exists
if args["export"] and cvedb_orig.check_db_exists():
LOGGER.info(f'Export database to {args["export"]}')
cvedb_orig.copy_db(filename=args["export"], export=True)
# And terminate operation
return 0

# Clear data if -u now is set
if db_update == "now":
cvedb_orig.clear_cached_data()
Expand Down
7 changes: 7 additions & 0 deletions cve_bin_tool/cvedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,13 @@ def init_database(self) -> None:
self.clear_cached_data()
self.connection.commit()

def copy_db(self, filename, export=True):
self.db_close()
if export:
shutil.copy(self.dbpath, filename)
else:
shutil.copy(filename, self.dbpath)

def populate_db(self) -> None:
"""Function that populates the database from the JSON.

Expand Down
17 changes: 17 additions & 0 deletions doc/MANUAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
- [-t TAG, --tag TAG](#-t-tag---tag-tag)
- [-m INTERMEDIATE_REPORTS, --merge INTERMEDIATE_REPORTS](#-m-intermediate_reports---merge-intermediate_reports)
- [-F TAGS, --filter TAGS](#-f-tags---filter-tags)
- [Database Management](#database-management)
- [--export EXPORT](#--export-export)
- [--import IMPORT](#--import-import)
- [Deprecated Arguments](#deprecated-arguments)
- [-x, --extract](#-x---extract)
- [Feedback & Contributions](#feedback--contributions)
Expand Down Expand Up @@ -123,6 +126,10 @@ which is useful if you're trying the latest code from
comma-separated list of checkers to disable
-r RUNS, --runs RUNS comma-separated list of checkers to enable

Database Management:
--export EXPORT export database filename
--import IMPORT import database filename

Deprecated:
-x, --extract autoextract compressed files

Expand Down Expand Up @@ -818,6 +825,16 @@ This option allows you to merge intermediate reports created using `-a` or `--ap

This allows you to filter out intermediate reports based on the tag. This can be useful while merging multiple intermediate reports from a single path. See detailed guide on [`filter intermediate reports`](how_to_guides/filter_intermediate_reports.md) for more information.

## Database Management

### --export EXPORT

This option allows you to make a copy of the database. This is typically required as part of setting up offline operation of the tool. If no database exists, this operation has no effect.

### --import IMPORT

This option allows you to import a copy of the database (typically created using the `--export` option). If the specified file does not exist, this operation has no effect.

## Deprecated Arguments

### -x, --extract
Expand Down
16 changes: 14 additions & 2 deletions doc/how_to_guides/offline.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,23 @@ $ cve-bin-tool --update now
```
NOTE The tool will error with InsufficientArgs because no directory was specified for a scan. This is expected behaviour.

## Export the database

Run the tool to export the latest version of the vulnerability database.
```
$ cve-bin-tool --export <filename>
```

## Transfer the vulnerability database file into a directory in the offline environment
The way of transfer depends on the environment. The files to be transferred are in "~/.cache/cve-bin-tool"

The way of transfer depends on the environment.

## Import the vulnerability database file on the offline system
The vulnerability database should be copied into ~/.cache/cve-bin-tool.

Run the tool to import the transferred copy of the vulnerability database.
```
$ cve-bin-tool --import <filename>
```

The cve-bin-tool will fail to operate in offline mode if a vulnerability database is not present on the system.

Expand Down