Skip to content

Commit 95f0fa1

Browse files
authored
feat: integration-node can produce decrypt manifests (#1580)
For a given encrypt manifest, integration-node now takes `—-decryptManifest` | `-d` This will create a zipped decrypt manifest that can be consumed by decrypt.
1 parent dee213b commit 95f0fa1

File tree

8 files changed

+287
-27
lines changed

8 files changed

+287
-27
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,5 @@ package.json.decrypt
4747
# they track the package.json version
4848
/modules/kms-keyring-browser/src/version.ts
4949
/modules/kms-keyring-node/src/version.ts
50-
/modules/branch-keystore-node/src/version.ts
50+
/modules/branch-keystore-node/src/version.ts
51+
/modules/integration-node/src/version.ts

modules/integration-node/package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
"name": "@aws-crypto/integration-node",
33
"version": "4.1.0",
44
"scripts": {
5+
"prepublishOnly": "npm run generate-version.ts; npm run build",
6+
"generate-version.ts": "npx genversion --es6 src/version.ts",
57
"build": "tsc -b tsconfig.json",
68
"lint": "run-s lint-*",
79
"lint-eslint": "eslint src/*.ts test/*.ts",
@@ -24,7 +26,8 @@
2426
"got": "^11.8.0",
2527
"stream-to-promise": "^3.0.0",
2628
"tslib": "^2.3.0",
27-
"yargs": "^17.0.1"
29+
"yargs": "^17.0.1",
30+
"yazl": "^3.3.1"
2831
},
2932
"sideEffects": false,
3033
"main": "./build/main/src/index.js",

modules/integration-node/src/cli.ts

+15-6
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,13 @@ const cli = yargs
4747
.option('decryptOracle', {
4848
alias: 'o',
4949
describe: 'a url to the decrypt oracle',
50-
demandOption: true,
50+
demandOption: false,
51+
type: 'string',
52+
})
53+
.option('decryptManifest', {
54+
alias: 'd',
55+
describe: 'a file path for to create a decrypt manifest zip file',
56+
demandOption: false,
5157
type: 'string',
5258
})
5359
)
@@ -103,15 +109,18 @@ const cli = yargs
103109
concurrency
104110
)
105111
} else if (command === 'encrypt') {
106-
const { manifestFile, keyFile, decryptOracle } = argv as unknown as {
107-
manifestFile: string
108-
keyFile: string
109-
decryptOracle: string
110-
}
112+
const { manifestFile, keyFile, decryptOracle, decryptManifest } =
113+
argv as unknown as {
114+
manifestFile: string
115+
keyFile: string
116+
decryptOracle?: string
117+
decryptManifest?: string
118+
}
111119
result = await integrationEncryptTestVectors(
112120
manifestFile,
113121
keyFile,
114122
decryptOracle,
123+
decryptManifest,
115124
tolerateFailures,
116125
testName,
117126
concurrency
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
export const KEYS_MANIFEST_NAME_FILENAME = 'keys.json'
5+
export const MANIFEST_NAME_FILENAME = 'manifest.json'
6+
export const DECRYPT_MANIFEST_TYPE = 'awses-decrypt'
7+
export const DECRYPT_MANIFEST_CLIENT_NAME = 'aws/aws-encryption-sdk-javascript'
8+
export const MANIFEST_URI_PREFIX = 'file://'
9+
export const MANIFEST_PLAINTEXT_PATH = 'plaintexts/'
10+
export const MANIFEST_CIPHERTEXT_PATH = 'ciphertexts/'

modules/integration-node/src/get_encrypt_test_iterator.ts

+28-3
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,51 @@ import {
1414
import { URL } from 'url'
1515
import { readFileSync } from 'fs'
1616
import got from 'got'
17+
import { ZipFile } from 'yazl'
18+
import {
19+
KEYS_MANIFEST_NAME_FILENAME,
20+
MANIFEST_PLAINTEXT_PATH,
21+
} from './constants'
1722

1823
export async function getEncryptTestVectorIterator(
1924
manifestFile: string,
20-
keyFile: string
25+
keyFile: string,
26+
manifestZip?: ZipFile
2127
) {
2228
const [manifest, keys]: [EncryptManifestList, KeyList] = await Promise.all([
2329
getParsedJSON(manifestFile),
2430
getParsedJSON(keyFile),
2531
])
2632

27-
return _getEncryptTestVectorIterator(manifest, keys)
33+
return _getEncryptTestVectorIterator(manifest, keys, manifestZip)
2834
}
2935

3036
/* Just a simple more testable function */
3137
export function _getEncryptTestVectorIterator(
3238
{ tests, plaintexts }: EncryptManifestList,
33-
{ keys }: KeyList
39+
keysManifest: KeyList,
40+
manifestZip?: ZipFile
3441
) {
42+
if (manifestZip) {
43+
// We assume that the keys manifest given for encrypt
44+
// has all the keys required for decrypt.
45+
manifestZip.addBuffer(
46+
Buffer.from(JSON.stringify(keysManifest)),
47+
`${KEYS_MANIFEST_NAME_FILENAME}`
48+
)
49+
}
50+
const { keys } = keysManifest
3551
const plaintextBytes: { [name: string]: Buffer } = {}
3652

3753
Object.keys(plaintexts).forEach((name) => {
3854
plaintextBytes[name] = randomBytes(plaintexts[name])
55+
56+
if (manifestZip) {
57+
manifestZip.addBuffer(
58+
plaintextBytes[name],
59+
`${MANIFEST_PLAINTEXT_PATH}${name}`
60+
)
61+
}
3962
})
4063

4164
return (function* nextTest(): IterableIterator<EncryptTestVectorInfo> {
@@ -60,6 +83,7 @@ export function _getEncryptTestVectorIterator(
6083
name,
6184
keysInfo,
6285
plainTextData: plaintextBytes[plaintext],
86+
plaintextName: plaintext,
6387
encryptOp: { suiteId, frameLength, encryptionContext },
6488
}
6589
}
@@ -70,6 +94,7 @@ export interface EncryptTestVectorInfo {
7094
name: string
7195
keysInfo: KeyInfoTuple[]
7296
plainTextData: Buffer
97+
plaintextName: string
7398
encryptOp: {
7499
suiteId: AlgorithmSuiteIdentifier
75100
frameLength: number

0 commit comments

Comments
 (0)