Skip to content

feat: integration-node can produce decrypt manifests #1580

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 5 commits into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@ package.json.decrypt
# they track the package.json version
/modules/kms-keyring-browser/src/version.ts
/modules/kms-keyring-node/src/version.ts
/modules/branch-keystore-node/src/version.ts
/modules/branch-keystore-node/src/version.ts
/modules/integration-node/src/version.ts
5 changes: 4 additions & 1 deletion modules/integration-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
"name": "@aws-crypto/integration-node",
"version": "4.1.0",
"scripts": {
"prepublishOnly": "npm run generate-version.ts; npm run build",
"generate-version.ts": "npx genversion --es6 src/version.ts",
"build": "tsc -b tsconfig.json",
"lint": "run-s lint-*",
"lint-eslint": "eslint src/*.ts test/*.ts",
Expand All @@ -24,7 +26,8 @@
"got": "^11.8.0",
"stream-to-promise": "^3.0.0",
"tslib": "^2.3.0",
"yargs": "^17.0.1"
"yargs": "^17.0.1",
"yazl": "^3.3.1"
},
"sideEffects": false,
"main": "./build/main/src/index.js",
Expand Down
21 changes: 15 additions & 6 deletions modules/integration-node/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@ const cli = yargs
.option('decryptOracle', {
alias: 'o',
describe: 'a url to the decrypt oracle',
demandOption: true,
demandOption: false,
type: 'string',
})
.option('decryptManifest', {
alias: 'd',
describe: 'a file path for to create a decrypt manifest zip file',
demandOption: false,
type: 'string',
})
)
Expand Down Expand Up @@ -103,15 +109,18 @@ const cli = yargs
concurrency
)
} else if (command === 'encrypt') {
const { manifestFile, keyFile, decryptOracle } = argv as unknown as {
manifestFile: string
keyFile: string
decryptOracle: string
}
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
Expand Down
10 changes: 10 additions & 0 deletions modules/integration-node/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

export const KEYS_MANIFEST_NAME_FILENAME = 'keys.json'
export const MANIFEST_NAME_FILENAME = 'manifest.json'
export const DECRYPT_MANIFEST_TYPE = 'awses-decrypt'
export const DECRYPT_MANIFEST_CLIENT_NAME = 'aws/aws-encryption-sdk-javascript'
export const MANIFEST_URI_PREFIX = 'file://'
export const MANIFEST_PLAINTEXT_PATH = 'plaintexts/'
export const MANIFEST_CIPHERTEXT_PATH = 'ciphertexts/'
31 changes: 28 additions & 3 deletions modules/integration-node/src/get_encrypt_test_iterator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,51 @@ import {
import { URL } from 'url'
import { readFileSync } from 'fs'
import got from 'got'
import { ZipFile } from 'yazl'
import {
KEYS_MANIFEST_NAME_FILENAME,
MANIFEST_PLAINTEXT_PATH,
} from './constants'

export async function getEncryptTestVectorIterator(
manifestFile: string,
keyFile: string
keyFile: string,
manifestZip?: ZipFile
) {
const [manifest, keys]: [EncryptManifestList, KeyList] = await Promise.all([
getParsedJSON(manifestFile),
getParsedJSON(keyFile),
])

return _getEncryptTestVectorIterator(manifest, keys)
return _getEncryptTestVectorIterator(manifest, keys, manifestZip)
}

/* Just a simple more testable function */
export function _getEncryptTestVectorIterator(
{ tests, plaintexts }: EncryptManifestList,
{ keys }: KeyList
keysManifest: KeyList,
manifestZip?: ZipFile
) {
if (manifestZip) {
// We assume that the keys manifest given for encrypt
// has all the keys required for decrypt.
manifestZip.addBuffer(
Buffer.from(JSON.stringify(keysManifest)),
`${KEYS_MANIFEST_NAME_FILENAME}`
)
}
const { keys } = keysManifest
const plaintextBytes: { [name: string]: Buffer } = {}

Object.keys(plaintexts).forEach((name) => {
plaintextBytes[name] = randomBytes(plaintexts[name])

if (manifestZip) {
manifestZip.addBuffer(
plaintextBytes[name],
`${MANIFEST_PLAINTEXT_PATH}${name}`
)
}
})

return (function* nextTest(): IterableIterator<EncryptTestVectorInfo> {
Expand All @@ -60,6 +83,7 @@ export function _getEncryptTestVectorIterator(
name,
keysInfo,
plainTextData: plaintextBytes[plaintext],
plaintextName: plaintext,
encryptOp: { suiteId, frameLength, encryptionContext },
}
}
Expand All @@ -70,6 +94,7 @@ export interface EncryptTestVectorInfo {
name: string
keysInfo: KeyInfoTuple[]
plainTextData: Buffer
plaintextName: string
encryptOp: {
suiteId: AlgorithmSuiteIdentifier
frameLength: number
Expand Down
Loading