Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crypto: align webcrypto RSA key import/export with other implementations #42816

Merged
merged 1 commit into from
May 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a test that covers this error case? If not, please add one.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is.

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.