Skip to content

Commit

Permalink
Update tdf.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
dmihalcik-virtru committed Feb 21, 2025
1 parent 5742ee8 commit 5ccf6f5
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/tdf3/src/tdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -674,20 +674,23 @@ async function unwrapKey({
const url = `${keySplitInfo.url}/v2/rewrap`;
let ephemeralEncryptionKeysRaw: AnyKeyPair;
let ephemeralEncryptionKeys: PemKeyPair;
let algorithm: string;
if (wrappingKeyAlgorithm === 'ec:secp256r1') {
ephemeralEncryptionKeysRaw = await generateKeyPair();
ephemeralEncryptionKeys = await cryptoService.cryptoToPemPair(ephemeralEncryptionKeysRaw);
algorithm = 'ES256';
} else if (wrappingKeyAlgorithm === 'rsa:2048' || !wrappingKeyAlgorithm) {
ephemeralEncryptionKeysRaw = await cryptoService.generateKeyPair();
ephemeralEncryptionKeys = await cryptoService.cryptoToPemPair(ephemeralEncryptionKeysRaw);
algorithm = 'RS256';
} else {
throw new ConfigurationError(`Unsupported wrapping key algorithm [${wrappingKeyAlgorithm}]`);
}

const clientPublicKey = ephemeralEncryptionKeys.publicKey;

const requestBodyStr = JSON.stringify({
algorithm: 'RS256',
algorithm,
keyAccess: keySplitInfo,
policy: manifest.encryptionInformation.policy,
clientPublicKey,
Expand Down

0 comments on commit 5ccf6f5

Please sign in to comment.