Skip to content

Commit ac69b95

Browse files
panvaMylesBorins
authored andcommitted
crypto: use correct webcrypto RSASSA-PKCS1-v1_5 algorithm name
PR-URL: #38029 Refs: https://www.w3.org/TR/WebCryptoAPI/#rsassa-pkcs1 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
1 parent afc6ab2 commit ac69b95

10 files changed

+52
-47
lines changed

lib/internal/crypto/keygen.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const {
1616
kCryptoJobAsync,
1717
kCryptoJobSync,
1818
kKeyVariantRSA_PSS,
19-
kKeyVariantRSA_SSA_PKCS1_V1_5,
19+
kKeyVariantRSA_SSA_PKCS1_v1_5,
2020
EVP_PKEY_ED25519,
2121
EVP_PKEY_ED448,
2222
EVP_PKEY_X25519,
@@ -183,7 +183,7 @@ function createJob(mode, type, options) {
183183
if (type === 'rsa') {
184184
return new RsaKeyPairGenJob(
185185
mode,
186-
kKeyVariantRSA_SSA_PKCS1_V1_5, // Used also for RSA-OAEP
186+
kKeyVariantRSA_SSA_PKCS1_v1_5, // Used also for RSA-OAEP
187187
modulusLength,
188188
publicExponent,
189189
...encoding);

lib/internal/crypto/rsa.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const {
1414
kCryptoJobAsync,
1515
kSignJobModeSign,
1616
kSignJobModeVerify,
17-
kKeyVariantRSA_SSA_PKCS1_V1_5,
17+
kKeyVariantRSA_SSA_PKCS1_v1_5,
1818
kKeyVariantRSA_PSS,
1919
kKeyVariantRSA_OAEP,
2020
kKeyTypePrivate,
@@ -66,7 +66,7 @@ const {
6666
} = require('internal/crypto/keygen');
6767

6868
const kRsaVariants = {
69-
'RSASSA-PKCS1-V1_5': kKeyVariantRSA_SSA_PKCS1_V1_5,
69+
'RSASSA-PKCS1-v1_5': kKeyVariantRSA_SSA_PKCS1_v1_5,
7070
'RSA-PSS': kKeyVariantRSA_PSS,
7171
'RSA-OAEP': kKeyVariantRSA_OAEP,
7272
};

lib/internal/crypto/util.js

+31-26
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ const {
66
BigInt,
77
FunctionPrototypeBind,
88
Number,
9+
ObjectKeys,
910
Promise,
1011
StringPrototypeToLowerCase,
11-
StringPrototypeToUpperCase,
1212
Symbol,
1313
} = primordials;
1414

@@ -159,31 +159,32 @@ const kAesKeyLengths = [128, 192, 256];
159159

160160
// These are the only algorithms we currently support
161161
// via the Web Crypto API
162-
const kAlgorithms = [
163-
'rsassa-pkcs1-v1_5',
164-
'rsa-pss',
165-
'rsa-oaep',
166-
'ecdsa',
167-
'ecdh',
168-
'aes-ctr',
169-
'aes-cbc',
170-
'aes-gcm',
171-
'aes-kw',
172-
'hmac',
173-
'sha-1',
174-
'sha-256',
175-
'sha-384',
176-
'sha-512',
177-
'hkdf',
178-
'pbkdf2',
162+
const kAlgorithms = {
163+
'rsassa-pkcs1-v1_5': 'RSASSA-PKCS1-v1_5',
164+
'rsa-pss': 'RSA-PSS',
165+
'rsa-oaep': 'RSA-OAEP',
166+
'ecdsa': 'ECDSA',
167+
'ecdh': 'ECDH',
168+
'aes-ctr': 'AES-CTR',
169+
'aes-cbc': 'AES-CBC',
170+
'aes-gcm': 'AES-GCM',
171+
'aes-kw': 'AES-KW',
172+
'hmac': 'HMAC',
173+
'sha-1': 'SHA-1',
174+
'sha-256': 'SHA-256',
175+
'sha-384': 'SHA-384',
176+
'sha-512': 'SHA-512',
177+
'hkdf': 'HKDF',
178+
'pbkdf2': 'PBKDF2',
179179
// Following here are Node.js specific extensions. All
180180
// should be prefixed with 'node-'
181-
'node-dsa',
182-
'node-dh',
183-
'node-scrypt',
184-
'node-ed25519',
185-
'node-ed448',
186-
];
181+
'node-dsa': 'NODE-DSA',
182+
'node-dh': 'NODE-DH',
183+
'node-scrypt': 'NODE-SCRYPT',
184+
'node-ed25519': 'NODE-ED25519',
185+
'node-ed448': 'NODE-ED448',
186+
};
187+
const kAlgorithmsKeys = ObjectKeys(kAlgorithms);
187188

188189
// These are the only export and import formats we currently
189190
// support via the Web Crypto API
@@ -221,7 +222,7 @@ function normalizeAlgorithm(algorithm, label = 'algorithm') {
221222
let hash;
222223
if (typeof name !== 'string' ||
223224
!ArrayPrototypeIncludes(
224-
kAlgorithms,
225+
kAlgorithmsKeys,
225226
StringPrototypeToLowerCase(name))) {
226227
throw lazyDOMException('Unrecognized name.', 'NotSupportedError');
227228
}
@@ -230,7 +231,11 @@ function normalizeAlgorithm(algorithm, label = 'algorithm') {
230231
if (!ArrayPrototypeIncludes(kHashTypes, hash.name))
231232
throw lazyDOMException('Unrecognized name.', 'NotSupportedError');
232233
}
233-
return { ...algorithm, name: StringPrototypeToUpperCase(name), hash };
234+
return {
235+
...algorithm,
236+
name: kAlgorithms[StringPrototypeToLowerCase(name)],
237+
hash,
238+
};
234239
}
235240
}
236241
throw lazyDOMException('Unrecognized name.', 'NotSupportedError');

lib/internal/crypto/webcrypto.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ async function generateKey(
7171
validateBoolean(extractable, 'extractable');
7272
validateArray(keyUsages, 'keyUsages');
7373
switch (algorithm.name) {
74-
case 'RSASSA-PKCS1-V1_5':
74+
case 'RSASSA-PKCS1-v1_5':
7575
// Fall through
7676
case 'RSA-PSS':
7777
// Fall through
@@ -199,7 +199,7 @@ async function deriveKey(
199199

200200
async function exportKeySpki(key) {
201201
switch (key.algorithm.name) {
202-
case 'RSASSA-PKCS1-V1_5':
202+
case 'RSASSA-PKCS1-v1_5':
203203
// Fall through
204204
case 'RSA-PSS':
205205
// Fall through
@@ -242,7 +242,7 @@ async function exportKeySpki(key) {
242242

243243
async function exportKeyPkcs8(key) {
244244
switch (key.algorithm.name) {
245-
case 'RSASSA-PKCS1-V1_5':
245+
case 'RSASSA-PKCS1-v1_5':
246246
// Fall through
247247
case 'RSA-PSS':
248248
// Fall through
@@ -321,7 +321,7 @@ async function exportKeyJWK(key) {
321321
ext: key.extractable,
322322
});
323323
switch (key.algorithm.name) {
324-
case 'RSASSA-PKCS1-V1_5':
324+
case 'RSASSA-PKCS1-v1_5':
325325
jwk.alg = normalizeHashName(
326326
key.algorithm.hash.name,
327327
normalizeHashName.kContextJwkRsa);
@@ -461,7 +461,7 @@ async function importKey(
461461
validateBoolean(extractable, 'extractable');
462462
validateArray(keyUsages, 'keyUsages');
463463
switch (algorithm.name) {
464-
case 'RSASSA-PKCS1-V1_5':
464+
case 'RSASSA-PKCS1-v1_5':
465465
// Fall through
466466
case 'RSA-PSS':
467467
// Fall through
@@ -588,7 +588,7 @@ function signVerify(algorithm, key, data, signature) {
588588
switch (algorithm.name) {
589589
case 'RSA-PSS':
590590
// Fall through
591-
case 'RSASSA-PKCS1-V1_5':
591+
case 'RSASSA-PKCS1-v1_5':
592592
return lazyRequire('internal/crypto/rsa')
593593
.rsaSignVerify(key, data, algorithm, signature);
594594
case 'NODE-ED25519':

src/crypto/crypto_rsa.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ void Initialize(Environment* env, Local<Object> target) {
559559
RSAKeyExportJob::Initialize(env, target);
560560
RSACipherJob::Initialize(env, target);
561561

562-
NODE_DEFINE_CONSTANT(target, kKeyVariantRSA_SSA_PKCS1_V1_5);
562+
NODE_DEFINE_CONSTANT(target, kKeyVariantRSA_SSA_PKCS1_v1_5);
563563
NODE_DEFINE_CONSTANT(target, kKeyVariantRSA_PSS);
564564
NODE_DEFINE_CONSTANT(target, kKeyVariantRSA_OAEP);
565565
}

src/crypto/crypto_rsa.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
namespace node {
1616
namespace crypto {
1717
enum RSAKeyVariant {
18-
kKeyVariantRSA_SSA_PKCS1_V1_5,
18+
kKeyVariantRSA_SSA_PKCS1_v1_5,
1919
kKeyVariantRSA_PSS,
2020
kKeyVariantRSA_OAEP
2121
};
@@ -53,7 +53,7 @@ struct RsaKeyGenTraits final {
5353
using RSAKeyPairGenJob = KeyGenJob<KeyPairGenTraits<RsaKeyGenTraits>>;
5454

5555
struct RSAKeyExportConfig final : public MemoryRetainer {
56-
RSAKeyVariant variant = kKeyVariantRSA_SSA_PKCS1_V1_5;
56+
RSAKeyVariant variant = kKeyVariantRSA_SSA_PKCS1_v1_5;
5757
SET_NO_MEMORY_INFO()
5858
SET_MEMORY_INFO_NAME(RSAKeyExportConfig)
5959
SET_SELF_SIZE(RSAKeyExportConfig)

test/parallel/test-webcrypto-export-import-rsa.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ const testVectors = [
457457
publicUsages: ['verify']
458458
},
459459
{
460-
name: 'RSASSA-PKCS1-V1_5',
460+
name: 'RSASSA-PKCS1-v1_5',
461461
privateUsages: ['sign'],
462462
publicUsages: ['verify']
463463
}

test/parallel/test-webcrypto-keygen.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const vectors = {
6565
],
6666
mandatoryUsages: []
6767
},
68-
'RSASSA-PKCS1-V1_5': {
68+
'RSASSA-PKCS1-v1_5': {
6969
algorithm: {
7070
modulusLength: 1024,
7171
publicExponent: new Uint8Array([1, 0, 1]),
@@ -317,7 +317,7 @@ const vectors = {
317317

318318
const kTests = [
319319
[
320-
'RSASSA-PKCS1-V1_5',
320+
'RSASSA-PKCS1-v1_5',
321321
1024,
322322
Buffer.from([1, 0, 1]),
323323
'SHA-256',

test/parallel/test-webcrypto-sign-verify.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,23 @@ const { subtle } = require('crypto').webcrypto;
1111
// This is only a partial test. The WebCrypto Web Platform Tests
1212
// will provide much greater coverage.
1313

14-
// Test Sign/Verify RSASSA-PKCS1-V1_5
14+
// Test Sign/Verify RSASSA-PKCS1-v1_5
1515
{
1616
async function test(data) {
1717
const ec = new TextEncoder();
1818
const { publicKey, privateKey } = await subtle.generateKey({
19-
name: 'RSASSA-PKCS1-V1_5',
19+
name: 'RSASSA-PKCS1-v1_5',
2020
modulusLength: 1024,
2121
publicExponent: new Uint8Array([1, 0, 1]),
2222
hash: 'SHA-256'
2323
}, true, ['sign', 'verify']);
2424

2525
const signature = await subtle.sign({
26-
name: 'RSASSA-PKCS1-V1_5'
26+
name: 'RSASSA-PKCS1-v1_5'
2727
}, privateKey, ec.encode(data));
2828

2929
assert(await subtle.verify({
30-
name: 'RSASSA-PKCS1-V1_5'
30+
name: 'RSASSA-PKCS1-v1_5'
3131
}, publicKey, signature, ec.encode(data)));
3232
}
3333

test/parallel/test-webcrypto-wrap-unwrap.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ async function generateKeysToWrap() {
6464
const parameters = [
6565
{
6666
algorithm: {
67-
name: 'RSASSA-PKCS1-V1_5',
67+
name: 'RSASSA-PKCS1-v1_5',
6868
modulusLength: 1024,
6969
publicExponent: new Uint8Array([1, 0, 1]),
7070
hash: 'SHA-256'

0 commit comments

Comments
 (0)