diff options
author | Filip Skokan <panva.ip@gmail.com> | 2022-05-25 17:31:14 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-25 17:31:14 +0300 |
commit | 12af4319b5de979fd474341c18b3f2b60ffcbf0f (patch) | |
tree | aea6e0f73bb5f52c404fcc40f859c3d7b1bddcef | |
parent | f9f22b4b6978ccf6573f244a971f8f1e4fbe40ee (diff) |
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
PR-URL: https://github.com/nodejs/node/pull/42816
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
-rw-r--r-- | lib/internal/crypto/rsa.js | 9 | ||||
-rw-r--r-- | test/parallel/test-webcrypto-export-import-rsa.js | 42 | ||||
-rw-r--r-- | test/parallel/test-webcrypto-rsa-pss-params.js | 40 |
3 files changed, 1 insertions, 90 deletions
diff --git a/lib/internal/crypto/rsa.js b/lib/internal/crypto/rsa.js index 8e4b6af571d..524227fef69 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 ab7aa77394a..3a2ea7b2798 100644 --- a/test/parallel/test-webcrypto-export-import-rsa.js +++ b/test/parallel/test-webcrypto-export-import-rsa.js @@ -482,48 +482,6 @@ const testVectors = [ })().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')); const ecPrivate = crypto.createPrivateKey( 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 964eaf32e89..00000000000 --- 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()); -} |