3
3
import fs from "node:fs" ;
4
4
import { join } from "node:path" ;
5
5
import process from "node:process" ;
6
- import { URL } from "node:url" ;
7
6
import jws from "jws" ;
8
7
import yargs from "yargs" ;
9
8
import { hideBin } from "yargs/helpers" ;
10
9
import { dirNameStr } from "../lib/helpers/utils.js" ;
10
+ import { getBomWithOras } from "../lib/managers/oci.js" ;
11
11
12
12
const dirName = dirNameStr ;
13
13
@@ -26,6 +26,7 @@ const args = yargs(hideBin(process.argv))
26
26
. scriptName ( "cdx-verify" )
27
27
. version ( )
28
28
. help ( "h" )
29
+ . alias ( "h" , "help" )
29
30
. wrap ( Math . min ( 120 , yargs ( ) . terminalWidth ( ) ) ) . argv ;
30
31
31
32
if ( args . version ) {
@@ -43,7 +44,25 @@ if (process.env?.CDXGEN_NODE_OPTIONS) {
43
44
process . env . NODE_OPTIONS = `${ process . env . NODE_OPTIONS || "" } ${ process . env . CDXGEN_NODE_OPTIONS } ` ;
44
45
}
45
46
46
- const bomJson = JSON . parse ( fs . readFileSync ( args . input , "utf8" ) ) ;
47
+ function getBom ( args ) {
48
+ if ( fs . existsSync ( args . input ) ) {
49
+ return JSON . parse ( fs . readFileSync ( args . input , "utf8" ) ) ;
50
+ }
51
+ if (
52
+ args . input . includes ( ":" ) ||
53
+ args . input . includes ( "docker" ) ||
54
+ args . input . includes ( "ghcr" )
55
+ ) {
56
+ return getBomWithOras ( args . input ) ;
57
+ }
58
+ return undefined ;
59
+ }
60
+
61
+ const bomJson = getBom ( args ) ;
62
+ if ( ! bomJson ) {
63
+ console . log ( `${ args . input } is invalid!` ) ;
64
+ process . exit ( 1 ) ;
65
+ }
47
66
let hasInvalidComp = false ;
48
67
// Validate any component signature
49
68
for ( const comp of bomJson . components ) {
@@ -77,7 +96,7 @@ if (!bomSignature) {
77
96
if ( validationResult ) {
78
97
console . log ( "Signature is valid!" ) ;
79
98
} else {
80
- console . log ( "SBOM signature is invalid!" ) ;
99
+ console . log ( "BOM signature is invalid!" ) ;
81
100
process . exit ( 1 ) ;
82
101
}
83
102
}
0 commit comments