Skip to content

Commit

Permalink
Merge branch 'assertion-verification-cli' of https://github.com/opent…
Browse files Browse the repository at this point in the history
…df/web-sdk into assertion-verification-cli
  • Loading branch information
elizabethhealy committed Dec 9, 2024
2 parents 0e59845 + 4a5c453 commit fe5d1cf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
26 changes: 18 additions & 8 deletions cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ function addParams(client: AnyNanoClient, argv: Partial<mainArgs>) {
log('SILLY', `Built encrypt params dissems: ${client.dissems}, attrs: ${client.dataAttributes}`);
}

async function parseAssertionVerificationKeys(s: string): Promise<assertions.AssertionVerificationKeys> {
async function parseAssertionVerificationKeys(
s: string
): Promise<assertions.AssertionVerificationKeys> {
const u = JSON.parse(s);
if (typeof u !== 'object' || u === null) {
throw new Error('Invalid input: The input must be an object');
Expand All @@ -135,10 +137,13 @@ async function parseAssertionVerificationKeys(s: string): Promise<assertions.Ass
}

if (typeof assertionKey.key !== 'string' || typeof assertionKey.alg !== 'string') {
throw new CLIError('CRITICAL', `Invalid assertion for ${assertionName}: Missing or invalid 'key' or 'alg'`);
throw new CLIError(
'CRITICAL',
`Invalid assertion for ${assertionName}: Missing or invalid 'key' or 'alg'`
);
}
try {
u[assertionName].key = await correctAssertionKeys(assertionKey.alg, assertionKey.key)
u[assertionName].key = await correctAssertionKeys(assertionKey.alg, assertionKey.key);
} catch (err) {
throw new CLIError('CRITICAL', `Issue converting assertion key from string: ${err.message}`);
}
Expand All @@ -151,7 +156,9 @@ async function tdf3DecryptParamsFor(argv: Partial<mainArgs>): Promise<DecryptPar
c.withNoVerifyAssertions(true);
}
if (argv.assertionVerificationKeys) {
c.withAssertionVerificaitonKeys(await parseAssertionVerificationKeys(argv.assertionVerificationKeys))
c.withAssertionVerificaitonKeys(
await parseAssertionVerificationKeys(argv.assertionVerificationKeys)
);
}
if (argv.concurrencyLimit) {
c.withConcurrencyLimit(argv.concurrencyLimit);
Expand All @@ -162,7 +169,7 @@ async function tdf3DecryptParamsFor(argv: Partial<mainArgs>): Promise<DecryptPar
return c.build();
}

async function correctAssertionKeys(alg: string, key: string): Promise<KeyLike | Uint8Array> {
async function correctAssertionKeys(alg: string, key: string): Promise<KeyLike | Uint8Array> {
if (alg === 'HS256') {
// Convert key string to Uint8Array
if (typeof key !== 'string') {
Expand All @@ -175,7 +182,7 @@ async function correctAssertionKeys(alg: string, key: string): Promise<KeyLike
throw new CLIError('CRITICAL', 'RS256 key must be a PEM string');
}
try {
return await importPKCS8(key, 'RS256'); // Import private key
return await importPKCS8(key, 'RS256'); // Import private key
} catch (err) {
// If importing as a private key fails, try importing as a public key
try {
Expand Down Expand Up @@ -204,9 +211,12 @@ async function parseAssertionConfig(s: string): Promise<assertions.AssertionConf
if (assertion.signingKey) {
const { alg, key } = assertion.signingKey;
try {
a[i].signingKey.key = await correctAssertionKeys(alg, key)
a[i].signingKey.key = await correctAssertionKeys(alg, key);
} catch (err) {
throw new CLIError('CRITICAL', `Issue converting assertion key from string: ${err.message}`);
throw new CLIError(
'CRITICAL',
`Issue converting assertion key from string: ${err.message}`
);
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion lib/tdf3/src/client/builders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,9 @@ class DecryptParamsBuilder {
* @param {AssertionVerificationKeys} assertionVerificationKeys - An array of assertion configurations to be set.
* @returns {DecryptParamsBuilder} The current instance of the EncryptParamsBuilder for method chaining.
*/
withAssertionVerificaitonKeys(assertionVerificationKeys: AssertionVerificationKeys): DecryptParamsBuilder {
withAssertionVerificaitonKeys(
assertionVerificationKeys: AssertionVerificationKeys
): DecryptParamsBuilder {
this._params.assertionVerificationKeys = assertionVerificationKeys;
return this;
}
Expand Down

0 comments on commit fe5d1cf

Please sign in to comment.