Skip to content
Open
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
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
"@types/fs-extra": "^11.0.1",
"@types/jest": "^29.2.3",
"@types/node": "^25.3.0",
"@types/node-jose": "^1.1.13",
"@typescript-eslint/eslint-plugin": "^8.56.0",
"@typescript-eslint/parser": "^8.56.0",
"@yao-pkg/pkg": "^6.12.0",
Expand Down
26 changes: 13 additions & 13 deletions src/cli/FrodoCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const {
RETRY_STRATEGIES,
RETRY_NOTHING_KEY,
} = constants;
const { convertPrivateKeyToPem } = frodo.utils.crypto;
const { getPrivateKey } = frodo.utils.crypto;

// Default heading for grouped subcommands.
const COMMANDS_HEADING = 'Commands:';
Expand Down Expand Up @@ -496,7 +496,7 @@ const amsterPrivateKeyPassphraseOption = withHelpGroup(
const amsterPrivateKeyFileOption = withHelpGroup(
new Option(
'--private-key <file>',
'File containing the private key for authenticating with Amster. Supported formats include PEM (both PKCS#1 and PKCS#8 variants), OpenSSH, DNSSEC, and JWK.'
'File containing the private key for authenticating with Amster. Supported formats include OpenSSH, DNSSEC, and JWK.'
),
AUTHENTICATION_OPTIONS_HEADING
);
Expand Down Expand Up @@ -669,24 +669,24 @@ const stateMap = {
// This is needed in the case the passphrase is an option, but the private key is an environment variable.
process.env.FRODO_AMSTER_PASSPHRASE = passphrase;
},
[amsterPrivateKeyFileOption.attributeName()]: (
[amsterPrivateKeyFileOption.attributeName()]: async (
file: string,
options: Record<string, string | boolean>
) => {
const passphrase =
(options[amsterPrivateKeyPassphraseOption.attributeName()] as string) ||
process.env.FRODO_AMSTER_PASSPHRASE;
try {
// Store as PEM format (PKCS#8 variant specifically) since Jose supports PEM and since PKCS#8 supports more algorithms than PKCS#1
state.setAmsterPrivateKey(
convertPrivateKeyToPem(
fs.readFileSync(file, 'utf8'),
passphrase,
file
.replaceAll('\\', '/')
.substring(file.replaceAll('\\', '/').lastIndexOf('/') + 1)
)
const key = await getPrivateKey(
fs.readFileSync(file, 'utf8'),
passphrase,
file
.replaceAll('\\', '/')
.substring(file.replaceAll('\\', '/').lastIndexOf('/') + 1)
);

// Store as JWK format
state.setAmsterPrivateKey(key);
} catch (error) {
printMessage(
`Error parsing private key from file ${file}: ${error.message}`,
Expand Down Expand Up @@ -811,7 +811,7 @@ const environmentVariables: EnvironmentVariableDescriptor[] = [
{
name: 'FRODO_AMSTER_PRIVATE_KEY',
description:
"Amster private key. Overridden by '--private-key' option but takes the actual private key as a value (i.e. the file contents), not a file name. Supported formats include PEM (both PKCS#1 and PKCS#8 variants), OpenSSH, DNSSEC, and JWK.",
"Amster private key. Overridden by '--private-key' option but takes the actual private key as a value (i.e. the file contents), not a file name. Supported formats include OpenSSH, DNSSEC, and JWK.",
group: AUTHENTICATION_ENVIRONMENT_VARIABLES_HEADING,
scope: 'classic-only',
include: (command) =>
Expand Down
4 changes: 2 additions & 2 deletions src/cli/esv/esv-secret-create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ export default function setup() {
.addOption(
new Option(
'-f, --file [file]',
'Name of the file to read pem or base64hmac encoded secret from. Ignored if --value is specified'
'Name of the file to read jwk or base64hmac encoded secret from. Ignored if --value is specified'
)
)
.option('--description [description]', 'Secret description.')
.addOption(
new Option('--encoding [encoding]', 'Secret encoding')
.choices(['generic', 'pem', 'base64hmac'])
.choices(['generic', 'jwk', 'base64hmac'])
.default('generic', 'generic')
)
.addOption(
Expand Down
2 changes: 1 addition & 1 deletion src/cli/esv/esv-secret-version-create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default function setup() {
.addOption(
new Option(
'-f, --file [file]',
'Name of the file to read pem or base64hmac encoded secret from. Ignored if --value is specified'
'Name of the file to read jwk or base64hmac encoded secret from. Ignored if --value is specified'
)
)
.action(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ Deployment: Cloud-only

Options:
--description [description] Secret description.
--encoding [encoding] Secret encoding (choices: "generic", "pem",
--encoding [encoding] Secret encoding (choices: "generic", "jwk",
"base64hmac", default: generic)
-f, --file [file] Name of the file to read pem or base64hmac
-f, --file [file] Name of the file to read jwk or base64hmac
encoded secret from. Ignored if --value is
specified
-i, --secret-id <secret-id> Secret id.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Arguments:
Deployment: Cloud-only

Options:
-f, --file [file] Name of the file to read pem or base64hmac
-f, --file [file] Name of the file to read jwk or base64hmac
encoded secret from. Ignored if --value is
specified
-i, --secret-id <secret-id> Secret id.
Expand Down
12 changes: 3 additions & 9 deletions test/e2e/__snapshots__/esv-secret-create.e2e.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@

exports[`frodo esv secret create "frodo esv secret create --secret-id esv-test-secret-pi-generic2 --value "3.141592653589793238462643383279502884" --description "This is a test secret containing the value pi." --encoding generic --no-use-in-placeholders": should create an esv secret with the value of pi base64hmac encoded that cannot be used in placeholders 1`] = `""`;

exports[`frodo esv secret create "frodo esv secret create -i esv-test-secret-cert-pem --file test/e2e/test-data/esv/key-pair-base64.pem --description "This is a test secret from a pem encoded cert file." --encoding pem": should create an esv secret with a pem encoded cert file 1`] = `""`;

exports[`frodo esv secret create "frodo esv secret create -i esv-test-secret-cert-pem-raw --file test/e2e/test-data/esv/key-pair.pem --encoding pem --description "This is a test secret from a pem encoded cert file (raw)."": should create an esv secret with a pem encoded cert file 1`] = `""`;

exports[`frodo esv secret create "frodo esv secret create -i esv-test-secret-file-base64hmac --file test/e2e/test-data/esv/hmac-key-base64.txt --description "This is a test secret from base64 encoded hmac key file." --encoding base64hmac": should create an esv secret with base64hmac encoded file 1`] = `""`;

exports[`frodo esv secret create "frodo esv secret create -i esv-test-secret-file-base64hmac-raw --file test/e2e/test-data/esv/hmac-key.txt --encoding base64hmac --description "This is a test secret from base64 encoded hmac key file (raw)."": should create an esv secret with base64hmac encoded file 1`] = `""`;

exports[`frodo esv secret create "frodo esv secret create -i esv-test-secret-pi-generic --value "3.141592653589793238462643383279502884" --description "This is a test secret containing the value pi."": should create an esv secret with the value of pi generically encoded. 1`] = `""`;

exports[`frodo esv secret create "frodo esv secret create -i esv-test-secret-pi-unknown --value "3.141592653589793238462643383279502884" --description "This is a test secret containing the value pi." --encoding unknown": should display an error when creating an esv secret with unknown encoding 1`] = `
"error: option '--encoding [encoding]' argument 'unknown' is invalid. Allowed choices are generic, pem, base64hmac.
"error: option '--encoding [encoding]' argument 'unknown' is invalid. Allowed choices are generic, jwk, base64hmac.

Usage: frodo esv secret create [options] [host] [username] [password]

Expand All @@ -33,9 +29,9 @@ Deployment: Cloud-only

Options:
--description [description] Secret description.
--encoding [encoding] Secret encoding (choices: "generic", "pem",
--encoding [encoding] Secret encoding (choices: "generic", "jwk",
"base64hmac", default: generic)
-f, --file [file] Name of the file to read pem or base64hmac
-f, --file [file] Name of the file to read jwk or base64hmac
encoded secret from. Ignored if --value is
specified
-i, --secret-id <secret-id> Secret id.
Expand All @@ -49,5 +45,3 @@ Options:
`;

exports[`frodo esv secret create "frodo esv secret create -i esv-test-secret-value-base64hmac --value "d2t0UU05Snp2a1Bsb2JmYVdlaUlkODFXcWllR1JpZWY4ekl4R0pud1laZz0=" --description "This is a test secret from base64 encoded hmac key." --encoding base64hmac": should create an esv secret with hmac key string 1`] = `""`;

exports[`frodo esv secret create "frodo esv secret create -i esv-test-secret-value-pem --value "LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0tLQpNQnNDQVFBQ0FVMENBUWNDQVNzQ0FRY0NBUXNDQVFFQ0FRTUNBUUk9Ci0tLS0tRU5EIFJTQSBQUklWQVRFIEtFWS0tLS0t" --encoding pem --description "This is a test secret from pem encoded string."": should create an esv secret with pem encoded string 1`] = `""`;
36 changes: 18 additions & 18 deletions test/e2e/esv-secret-create.e2e.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@
/*
FRODO_MOCK=record FRODO_NO_CACHE=1 FRODO_HOST=https://openam-frodo-dev.forgeblocks.com/am frodo esv secret create -i esv-test-secret-pi-generic --value "3.141592653589793238462643383279502884" --description "This is a test secret containing the value pi."
FRODO_MOCK=record FRODO_NO_CACHE=1 FRODO_HOST=https://openam-frodo-dev.forgeblocks.com/am frodo esv secret create --secret-id esv-test-secret-pi-generic2 --value "3.141592653589793238462643383279502884" --description "This is a test secret containing the value pi." --encoding generic --no-use-in-placeholders
FRODO_MOCK=record FRODO_NO_CACHE=1 FRODO_HOST=https://openam-frodo-dev.forgeblocks.com/am frodo esv secret create -i esv-test-secret-value-pem --value "LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0tLQpNQnNDQVFBQ0FVMENBUWNDQVNzQ0FRY0NBUXNDQVFFQ0FRTUNBUUk9Ci0tLS0tRU5EIFJTQSBQUklWQVRFIEtFWS0tLS0t" --encoding pem --description "This is a test secret from pem encoded string."
FRODO_MOCK=record FRODO_NO_CACHE=1 FRODO_HOST=https://openam-frodo-dev.forgeblocks.com/am frodo esv secret create -i esv-test-secret-cert-pem --file test/e2e/test-data/esv/key-pair-base64.pem --description "This is a test secret from a pem encoded cert file." --encoding pem
FRODO_MOCK=record FRODO_NO_CACHE=1 FRODO_HOST=https://openam-frodo-dev.forgeblocks.com/am frodo esv secret create -i esv-test-secret-cert-pem-raw --file test/e2e/test-data/esv/key-pair.pem --encoding pem --description "This is a test secret from a pem encoded cert file (raw)."
FRODO_MOCK=record FRODO_NO_CACHE=1 FRODO_HOST=https://openam-frodo-dev.forgeblocks.com/am frodo esv secret create -i esv-test-secret-value-pem --value "LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0tLQpNQnNDQVFBQ0FVMENBUWNDQVNzQ0FRY0NBUXNDQVFFQ0FRTUNBUUk9Ci0tLS0tRU5EIFJTQSBQUklWQVRFIEtFWS0tLS0t" --encoding jwk --description "This is a test secret from pem encoded string."
FRODO_MOCK=record FRODO_NO_CACHE=1 FRODO_HOST=https://openam-frodo-dev.forgeblocks.com/am frodo esv secret create -i esv-test-secret-cert-pem --file test/e2e/test-data/esv/key-pair-base64.pem --description "This is a test secret from a pem encoded cert file." --encoding jwk
FRODO_MOCK=record FRODO_NO_CACHE=1 FRODO_HOST=https://openam-frodo-dev.forgeblocks.com/am frodo esv secret create -i esv-test-secret-cert-pem-raw --file test/e2e/test-data/esv/key-pair.pem --encoding jwk --description "This is a test secret from a pem encoded cert file (raw)."
FRODO_MOCK=record FRODO_NO_CACHE=1 FRODO_HOST=https://openam-frodo-dev.forgeblocks.com/am frodo esv secret create -i esv-test-secret-value-base64hmac --value "d2t0UU05Snp2a1Bsb2JmYVdlaUlkODFXcWllR1JpZWY4ekl4R0pud1laZz0=" --description "This is a test secret from base64 encoded hmac key." --encoding base64hmac
FRODO_MOCK=record FRODO_NO_CACHE=1 FRODO_HOST=https://openam-frodo-dev.forgeblocks.com/am frodo esv secret create -i esv-test-secret-file-base64hmac --file test/e2e/test-data/esv/hmac-key-base64.txt --description "This is a test secret from base64 encoded hmac key file." --encoding base64hmac
FRODO_MOCK=record FRODO_NO_CACHE=1 FRODO_HOST=https://openam-frodo-dev.forgeblocks.com/am frodo esv secret create -i esv-test-secret-file-base64hmac-raw --file test/e2e/test-data/esv/hmac-key.txt --encoding base64hmac --description "This is a test secret from base64 encoded hmac key file (raw)."
Expand Down Expand Up @@ -80,23 +80,23 @@ describe('frodo esv secret create', () => {
expect(removeAnsiEscapeCodes(stdout)).toMatchSnapshot();
});

test('"frodo esv secret create -i esv-test-secret-value-pem --value "LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0tLQpNQnNDQVFBQ0FVMENBUWNDQVNzQ0FRY0NBUXNDQVFFQ0FRTUNBUUk9Ci0tLS0tRU5EIFJTQSBQUklWQVRFIEtFWS0tLS0t" --encoding pem --description "This is a test secret from pem encoded string."": should create an esv secret with pem encoded string', async () => {
const CMD = `frodo esv secret create -i esv-test-secret-value-pem --value "LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0tLQpNQnNDQVFBQ0FVMENBUWNDQVNzQ0FRY0NBUXNDQVFFQ0FRTUNBUUk9Ci0tLS0tRU5EIFJTQSBQUklWQVRFIEtFWS0tLS0t" --encoding pem --description "This is a test secret from pem encoded string."`;
const { stdout } = await exec(CMD, env);
expect(removeAnsiEscapeCodes(stdout)).toMatchSnapshot();
});
// test('"frodo esv secret create -i esv-test-secret-value-pem --value "LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0tLQpNQnNDQVFBQ0FVMENBUWNDQVNzQ0FRY0NBUXNDQVFFQ0FRTUNBUUk9Ci0tLS0tRU5EIFJTQSBQUklWQVRFIEtFWS0tLS0t" --encoding jwk --description "This is a test secret from pem encoded string."": should create an esv secret with pem encoded string', async () => {
// const CMD = `frodo esv secret create -i esv-test-secret-value-pem --value "LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0tLQpNQnNDQVFBQ0FVMENBUWNDQVNzQ0FRY0NBUXNDQVFFQ0FRTUNBUUk9Ci0tLS0tRU5EIFJTQSBQUklWQVRFIEtFWS0tLS0t" --encoding jwk --description "This is a test secret from pem encoded string."`;
// const { stdout } = await exec(CMD, env);
// expect(removeAnsiEscapeCodes(stdout)).toMatchSnapshot();
// });

test('"frodo esv secret create -i esv-test-secret-cert-pem --file test/e2e/test-data/esv/key-pair-base64.pem --description "This is a test secret from a pem encoded cert file." --encoding pem": should create an esv secret with a pem encoded cert file', async () => {
const CMD = `frodo esv secret create -i esv-test-secret-cert-pem --file test/e2e/test-data/esv/key-pair-base64.pem --description "This is a test secret from a pem encoded cert file." --encoding pem`;
const { stdout } = await exec(CMD, env);
expect(removeAnsiEscapeCodes(stdout)).toMatchSnapshot();
});
// test('"frodo esv secret create -i esv-test-secret-cert-pem --file test/e2e/test-data/esv/key-pair-base64.pem --description "This is a test secret from a pem encoded cert file." --encoding jwk": should create an esv secret with a pem encoded cert file', async () => {
// const CMD = `frodo esv secret create -i esv-test-secret-cert-pem --file test/e2e/test-data/esv/key-pair-base64.pem --description "This is a test secret from a pem encoded cert file." --encoding jwk`;
// const { stdout } = await exec(CMD, env);
// expect(removeAnsiEscapeCodes(stdout)).toMatchSnapshot();
// });

test('"frodo esv secret create -i esv-test-secret-cert-pem-raw --file test/e2e/test-data/esv/key-pair.pem --encoding pem --description "This is a test secret from a pem encoded cert file (raw)."": should create an esv secret with a pem encoded cert file', async () => {
const CMD = `frodo esv secret create -i esv-test-secret-cert-pem-raw --file test/e2e/test-data/esv/key-pair.pem --encoding pem --description "This is a test secret from a pem encoded cert file (raw)."`;
const { stdout } = await exec(CMD, env);
expect(removeAnsiEscapeCodes(stdout)).toMatchSnapshot();
});
// test('"frodo esv secret create -i esv-test-secret-cert-pem-raw --file test/e2e/test-data/esv/key-pair.pem --encoding jwk --description "This is a test secret from a pem encoded cert file (raw)."": should create an esv secret with a pem encoded cert file', async () => {
// const CMD = `frodo esv secret create -i esv-test-secret-cert-pem-raw --file test/e2e/test-data/esv/key-pair.pem --encoding jwk --description "This is a test secret from a pem encoded cert file (raw)."`;
// const { stdout } = await exec(CMD, env);
// expect(removeAnsiEscapeCodes(stdout)).toMatchSnapshot();
// });

test('"frodo esv secret create -i esv-test-secret-value-base64hmac --value "d2t0UU05Snp2a1Bsb2JmYVdlaUlkODFXcWllR1JpZWY4ekl4R0pud1laZz0=" --description "This is a test secret from base64 encoded hmac key." --encoding base64hmac": should create an esv secret with hmac key string', async () => {
const CMD = `frodo esv secret create -i esv-test-secret-value-base64hmac --value "d2t0UU05Snp2a1Bsb2JmYVdlaUlkODFXcWllR1JpZWY4ekl4R0pud1laZz0=" --description "This is a test secret from base64 encoded hmac key." --encoding base64hmac`;
Expand Down