From e2663fd524f54b0a3798afe637209c0632027e86 Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Thu, 21 Apr 2022 18:58:05 +0200 Subject: [PATCH] crypto: align webcrypto RSA key import/export with other implementations closes #39959 see https://github.com/w3c/webcrypto/issues/307 see https://github.com/w3c/webcrypto/pull/305 --- lib/internal/crypto/rsa.js | 9 +--- .../test-webcrypto-export-import-rsa.js | 42 ------------------- .../parallel/test-webcrypto-rsa-pss-params.js | 40 ------------------ 3 files changed, 1 insertion(+), 90 deletions(-) delete mode 100644 test/parallel/test-webcrypto-rsa-pss-params.js diff --git a/lib/internal/crypto/rsa.js b/lib/internal/crypto/rsa.js index 8e4b6af571dda3..524227fef69659 100644 --- a/lib/internal/crypto/rsa.js +++ b/lib/internal/crypto/rsa.js @@ -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'); } diff --git a/test/parallel/test-webcrypto-export-import-rsa.js b/test/parallel/test-webcrypto-export-import-rsa.js index ab7aa77394ac99..3a2ea7b279852d 100644 --- a/test/parallel/test-webcrypto-export-import-rsa.js +++ b/test/parallel/test-webcrypto-export-import-rsa.js @@ -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')); diff --git a/test/parallel/test-webcrypto-rsa-pss-params.js b/test/parallel/test-webcrypto-rsa-pss-params.js deleted file mode 100644 index 964eaf32e890fd..00000000000000 --- a/test/parallel/test-webcrypto-rsa-pss-params.js +++ /dev/null @@ -1,40 +0,0 @@ -'use strict'; - -const common = require('../common'); - -if (!common.hasCrypto) - common.skip('missing crypto'); - -const { - createPrivateKey, - createPublicKey, - webcrypto: { - subtle - } -} = require('crypto'); - -const fixtures = require('../common/fixtures'); - -{ - const rsaPssKeyWithoutParams = fixtures.readKey('rsa_pss_private_2048.pem'); - - const pkcs8 = createPrivateKey(rsaPssKeyWithoutParams).export({ - type: 'pkcs8', - format: 'der' - }); - const spki = createPublicKey(rsaPssKeyWithoutParams).export({ - type: 'spki', - format: 'der' - }); - - const hashes = ['SHA-1', 'SHA-256', 'SHA-384', 'SHA-512']; - - const tasks = []; - for (const hash of hashes) { - const algorithm = { name: 'RSA-PSS', hash }; - tasks.push(subtle.importKey('pkcs8', pkcs8, algorithm, true, ['sign'])); - tasks.push(subtle.importKey('spki', spki, algorithm, true, ['verify'])); - } - - Promise.all(tasks).then(common.mustCall()); -}