Skip to content

Commit 1744370

Browse files
committed
feat(tool): Add VEX file validation tool
1 parent 5ecff54 commit 1744370

File tree

3 files changed

+735
-1
lines changed

3 files changed

+735
-1
lines changed

cve_bin_tool/cli.py

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
from cve_bin_tool.version import VERSION
8080
from cve_bin_tool.version_scanner import VersionScanner
8181
from cve_bin_tool.vex_manager.parse import VEXParse
82+
from cve_bin_tool.vex_manager.validate import validate_vex_file
8283

8384
sys.excepthook = excepthook # Always install excepthook for entrypoint module.
8485

@@ -394,6 +395,13 @@ def main(argv=None):
394395
default=False,
395396
help="Filter cves based on triage data from Vex file",
396397
)
398+
vex_output_group.add_argument(
399+
"--vex-file-to-validate",
400+
action="store",
401+
help="VEX file path to validate (used with vex-validate command)",
402+
default="",
403+
)
404+
397405
parser.add_argument(
398406
"-e",
399407
"--exclude",
@@ -567,11 +575,37 @@ def main(argv=None):
567575
default=False,
568576
)
569577

578+
parser.add_argument(
579+
"command",
580+
nargs="?",
581+
choices=["vex-validate"],
582+
help="Command to run: vex-validate to validate VEX files",
583+
)
584+
585+
# Change directory to be optional when using commands
586+
input_group.add_argument(
587+
"directory", help="directory to scan", nargs="?", default=""
588+
)
589+
570590
with ErrorHandler(mode=ErrorMode.NoTrace):
571591
raw_args = parser.parse_args(argv[1:])
572592
args = {key: value for key, value in vars(raw_args).items() if value}
573593
defaults = {key: parser.get_default(key) for key in vars(raw_args)}
574594

595+
# Handle vex-validate command early
596+
if raw_args.command == "vex-validate":
597+
if not raw_args.vex_file_to_validate and not raw_args.directory:
598+
parser.error(
599+
"vex-validate command requires either --vex-file-to-validate or a VEX file path as directory argument"
600+
)
601+
602+
# Use directory as file path if vex_file_to_validate not provided
603+
vex_file_path = raw_args.vex_file_to_validate or raw_args.directory
604+
605+
# Import and run validation
606+
exit_code = validate_vex_file(vex_file_path)
607+
return exit_code
608+
575609
configs = {}
576610
if args.get("config"):
577611
conf = ConfigParser(args["config"])
@@ -741,6 +775,24 @@ def main(argv=None):
741775

742776
return 0
743777

778+
# Handle vex-validate command
779+
if args.get("command") == "vex-validate":
780+
from cve_bin_tool.vex_manager.validate import validate_vex_file
781+
782+
# Determine VEX file path
783+
vex_file_path = args.get("vex_file_to_validate") or args.get("directory")
784+
785+
if not vex_file_path:
786+
LOGGER.error(
787+
"Please provide a VEX file path using --vex-file-to-validate or as a positional argument"
788+
)
789+
parser.print_usage()
790+
return ERROR_CODES[InsufficientArgs]
791+
792+
# Validate the VEX file
793+
exit_code = validate_vex_file(vex_file_path, LOGGER)
794+
return exit_code
795+
744796
# Offline processing
745797
if args["offline"]:
746798
# Override version check and database update arguments
@@ -967,11 +1019,12 @@ def main(argv=None):
9671019
and not args["merge"]
9681020
and not args["sbom_file"]
9691021
and not args["vex_file"]
1022+
and not raw_args.command
9701023
):
9711024
parser.print_usage()
9721025
with ErrorHandler(logger=LOGGER, mode=ErrorMode.NoTrace):
9731026
raise InsufficientArgs(
974-
"Please specify a directory to scan or an input file required"
1027+
"Please specify a directory to scan, an input file, or use vex-validate command"
9751028
)
9761029

9771030
# Output validation

0 commit comments

Comments
 (0)