Skip to content

Commit

Permalink
crypto: align webcrypto RSA key import/export with other implementations
Browse files Browse the repository at this point in the history
closes #39959
see w3c/webcrypto#307
see w3c/webcrypto#305

PR-URL: #42816
Reviewed-By: Tobias Nießen <[email protected]>
  • Loading branch information
panva authored and bengl committed May 30, 2022
1 parent b187060 commit 920d8c5
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 90 deletions.
9 changes: 1 addition & 8 deletions lib/internal/crypto/rsa.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,14 +326,7 @@ async function rsaImportKey(
'NotSupportedError');
}

if (algorithm.name === 'RSA-PSS') {
if (
keyObject.asymmetricKeyType !== 'rsa' &&
keyObject.asymmetricKeyType !== 'rsa-pss'
) {
throw lazyDOMException('Invalid key type', 'DataError');
}
} else if (keyObject.asymmetricKeyType !== 'rsa') {
if (keyObject.asymmetricKeyType !== 'rsa') {
throw lazyDOMException('Invalid key type', 'DataError');
}

Expand Down
42 changes: 0 additions & 42 deletions test/parallel/test-webcrypto-export-import-rsa.js
Original file line number Diff line number Diff line change
Expand Up @@ -481,48 +481,6 @@ const testVectors = [
await Promise.all(variations);
})().then(common.mustCall());

{
const publicPem = fixtures.readKey('rsa_pss_public_2048.pem', 'ascii');
const privatePem = fixtures.readKey('rsa_pss_private_2048.pem', 'ascii');

const publicDer = Buffer.from(
publicPem.replace(
/(?:-----(?:BEGIN|END) PUBLIC KEY-----|\s)/g,
''
),
'base64'
);
const privateDer = Buffer.from(
privatePem.replace(
/(?:-----(?:BEGIN|END) PRIVATE KEY-----|\s)/g,
''
),
'base64'
);

(async () => {
const key = await subtle.importKey(
'spki',
publicDer,
{ name: 'RSA-PSS', hash: 'SHA-256' },
true,
['verify']);
const jwk = await subtle.exportKey('jwk', key);
assert.strictEqual(jwk.alg, 'PS256');
})().then(common.mustCall());

(async () => {
const key = await subtle.importKey(
'pkcs8',
privateDer,
{ name: 'RSA-PSS', hash: 'SHA-256' },
true,
['sign']);
const jwk = await subtle.exportKey('jwk', key);
assert.strictEqual(jwk.alg, 'PS256');
})().then(common.mustCall());
}

{
const ecPublic = crypto.createPublicKey(
fixtures.readKey('ec_p256_public.pem'));
Expand Down
40 changes: 0 additions & 40 deletions test/parallel/test-webcrypto-rsa-pss-params.js

This file was deleted.

0 comments on commit 920d8c5

Please sign in to comment.