-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathcli.ts
137 lines (133 loc) · 3.61 KB
/
cli.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/usr/bin/env node
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import yargs from 'yargs'
import { needs } from '@aws-crypto/client-node'
import { cpus } from 'os'
import {
integrationDecryptTestVectors,
integrationEncryptTestVectors,
} from './integration_tests'
const cli = yargs
.command('decrypt', 'verify decrypt vectors', (y) =>
y
.option('vectorFile', {
alias: 'v',
describe: 'a vector zip file from aws-encryption-sdk-test-vectors',
demandOption: true,
type: 'string',
})
.option('CVE-2023-46809', {
alias: 'C',
describe:
'Attempt RSA_PKCS1_OAEP_PADDING decrypt vectors, requires node process started with --security-revert=CVE-2023-46809',
default: false,
demandOption: false,
type: 'boolean',
})
)
.command('encrypt', 'verify encrypt manifest', (y) =>
y
.option('manifestFile', {
alias: 'm',
describe:
'a path/url to aws-crypto-tools-test-vector-framework canonical manifest',
demandOption: true,
type: 'string',
})
.option('keyFile', {
alias: 'k',
describe:
'a path/url to aws-crypto-tools-test-vector-framework canonical key list',
demandOption: true,
type: 'string',
})
.option('decryptOracle', {
alias: 'o',
describe: 'a url to the decrypt oracle',
demandOption: false,
type: 'string',
})
.option('decryptManifest', {
alias: 'd',
describe: 'a file path for to create a decrypt manifest zip file',
demandOption: false,
type: 'string',
})
)
.option('tolerateFailures', {
alias: 'f',
describe: 'an optional number of failures to tolerate before exiting',
type: 'number',
default: 0,
})
.option('testName', {
alias: 't',
describe: 'an optional test name to execute',
type: 'string',
})
.option('concurrency', {
alias: 'c',
describe: `an optional concurrency for running tests, pass 'cpu' to maximize`,
default: 1,
coerce: (value: any) => {
if (typeof value === 'string') {
needs(
value.toLowerCase() === 'cpu',
`The only supported string is 'cpu'`
)
return cpus().length - 1
}
needs(
typeof value === 'number' && value > 0,
`Must be a number greater than 0`
)
return value
},
})
.demandCommand()
;(async (argv) => {
const {
_: [command],
tolerateFailures,
testName,
['CVE-2023-46809']: CVE202346809,
concurrency,
} = await argv
/* I set the result to 1 so that if I fall through the exit condition is a failure */
let result = 1
if (command === 'decrypt') {
const { vectorFile } = argv as unknown as { vectorFile: string }
result = await integrationDecryptTestVectors(
vectorFile,
tolerateFailures,
testName,
!!CVE202346809,
concurrency
)
} else if (command === 'encrypt') {
const { manifestFile, keyFile, decryptOracle, decryptManifest } =
argv as unknown as {
manifestFile: string
keyFile: string
decryptOracle?: string
decryptManifest?: string
}
result = await integrationEncryptTestVectors(
manifestFile,
keyFile,
decryptOracle,
decryptManifest,
tolerateFailures,
testName,
concurrency
)
} else {
console.log(`Unknown command ${command}`)
cli.showHelp()
}
if (result) process.exit(result)
})(cli.argv).catch((err) => {
console.log(err)
process.exit(1)
})