File rsa-pss-revert.patch of Package nodejs16
444
1
Index: node-v17.3.0/doc/api/crypto.md
2
===================================================================
3
--- node-v17.3.0.orig/doc/api/crypto.md
4
+++ node-v17.3.0/doc/api/crypto.md
5
6
7
<!-- YAML
8
added: v15.7.0
9
-changes:
10
- - version: v16.9.0
11
- pr-url: https://github.com/nodejs/node/pull/39851
12
- description: Expose `RSASSA-PSS-params` sequence parameters
13
- for RSA-PSS keys.
14
-->
15
16
* {Object}
17
* `modulusLength`: {number} Key size in bits (RSA, DSA).
18
* `publicExponent`: {bigint} Public exponent (RSA).
19
- * `hashAlgorithm`: {string} Name of the message digest (RSA-PSS).
20
- * `mgf1HashAlgorithm`: {string} Name of the message digest used by
21
- MGF1 (RSA-PSS).
22
- * `saltLength`: {number} Minimal salt length in bytes (RSA-PSS).
23
* `divisorLength`: {number} Size of `q` in bits (DSA).
24
* `namedCurve`: {string} Name of the curve (EC).
25
26
27
through this property can be used to uniquely identify a key or to compromise
28
the security of the key.
29
30
-For RSA-PSS keys, if the key material contains a `RSASSA-PSS-params` sequence,
31
-the `hashAlgorithm`, `mgf1HashAlgorithm`, and `saltLength` properties will be
32
-set.
33
-
34
-Other key details might be exposed via this API using additional attributes.
35
+RSA-PSS parameters, DH, or any future key type details might be exposed via this
36
+API using additional attributes.
37
38
### `keyObject.asymmetricKeyType`
39
40
Index: node-v17.3.0/src/crypto/crypto_rsa.cc
41
===================================================================
42
--- node-v17.3.0.orig/src/crypto/crypto_rsa.cc
43
+++ node-v17.3.0/src/crypto/crypto_rsa.cc
44
45
reinterpret_cast<unsigned char*>(public_exponent.data());
46
CHECK_EQ(BN_bn2binpad(e, data, len), len);
47
48
- if (target
49
- ->Set(
50
- env->context(),
51
- env->public_exponent_string(),
52
- public_exponent.ToArrayBuffer())
53
- .IsNothing()) {
54
- return Nothing<bool>();
55
- }
56
-
57
- if (type == EVP_PKEY_RSA_PSS) {
58
- // Due to the way ASN.1 encoding works, default values are omitted when
59
- // encoding the data structure. However, there are also RSA-PSS keys for
60
- // which no parameters are set. In that case, the ASN.1 RSASSA-PSS-params
61
- // sequence will be missing entirely and RSA_get0_pss_params will return
62
- // nullptr. If parameters are present but all parameters are set to their
63
- // default values, an empty sequence will be stored in the ASN.1 structure.
64
- // In that case, RSA_get0_pss_params does not return nullptr but all fields
65
- // of the returned RSA_PSS_PARAMS will be set to nullptr.
66
-
67
- const RSA_PSS_PARAMS* params = RSA_get0_pss_params(rsa);
68
- if (params != nullptr) {
69
- int hash_nid = NID_sha1;
70
- int mgf_nid = NID_mgf1;
71
- int mgf1_hash_nid = NID_sha1;
72
- int64_t salt_length = 20;
73
-
74
- if (params->hashAlgorithm != nullptr) {
75
- hash_nid = OBJ_obj2nid(params->hashAlgorithm->algorithm);
76
- }
77
-
78
- if (target
79
- ->Set(
80
- env->context(),
81
- env->hash_algorithm_string(),
82
- OneByteString(env->isolate(), OBJ_nid2ln(hash_nid)))
83
- .IsNothing()) {
84
- return Nothing<bool>();
85
- }
86
-
87
- if (params->maskGenAlgorithm != nullptr) {
88
- mgf_nid = OBJ_obj2nid(params->maskGenAlgorithm->algorithm);
89
- if (mgf_nid == NID_mgf1) {
90
- mgf1_hash_nid = OBJ_obj2nid(params->maskHash->algorithm);
91
- }
92
- }
93
-
94
- // If, for some reason, the MGF is not MGF1, then the MGF1 hash function
95
- // is intentionally not added to the object.
96
- if (mgf_nid == NID_mgf1) {
97
- if (target
98
- ->Set(
99
- env->context(),
100
- env->mgf1_hash_algorithm_string(),
101
- OneByteString(env->isolate(), OBJ_nid2ln(mgf1_hash_nid)))
102
- .IsNothing()) {
103
- return Nothing<bool>();
104
- }
105
- }
106
-
107
- if (params->saltLength != nullptr) {
108
- if (ASN1_INTEGER_get_int64(&salt_length, params->saltLength) != 1) {
109
- ThrowCryptoError(env, ERR_get_error(), "ASN1_INTEGER_get_in64 error");
110
- return Nothing<bool>();
111
- }
112
- }
113
-
114
- if (target
115
- ->Set(
116
- env->context(),
117
- env->salt_length_string(),
118
- Number::New(env->isolate(), static_cast<double>(salt_length)))
119
- .IsNothing()) {
120
- return Nothing<bool>();
121
- }
122
- }
123
- }
124
-
125
- return Just<bool>(true);
126
+ return target->Set(
127
+ env->context(),
128
+ env->public_exponent_string(),
129
+ public_exponent.ToArrayBuffer());
130
}
131
132
namespace RSAAlg {
133
Index: node-v17.3.0/src/env.h
134
===================================================================
135
--- node-v17.3.0.orig/src/env.h
136
+++ node-v17.3.0/src/env.h
137
138
V(gid_string, "gid") \
139
V(h2_string, "h2") \
140
V(handle_string, "handle") \
141
- V(hash_algorithm_string, "hashAlgorithm") \
142
V(help_text_string, "helpText") \
143
V(homedir_string, "homedir") \
144
V(host_string, "host") \
145
146
V(message_port_string, "messagePort") \
147
V(message_string, "message") \
148
V(messageerror_string, "messageerror") \
149
- V(mgf1_hash_algorithm_string, "mgf1HashAlgorithm") \
150
V(minttl_string, "minttl") \
151
V(module_string, "module") \
152
V(modulus_string, "modulus") \
153
154
V(replacement_string, "replacement") \
155
V(require_string, "require") \
156
V(retry_string, "retry") \
157
- V(salt_length_string, "saltLength") \
158
V(scheme_string, "scheme") \
159
V(scopeid_string, "scopeid") \
160
V(serial_number_string, "serialNumber") \
161
Index: node-v17.3.0/test/fixtures/keys/Makefile
162
===================================================================
163
--- node-v17.3.0.orig/test/fixtures/keys/Makefile
164
+++ node-v17.3.0/test/fixtures/keys/Makefile
165
166
rsa_pss_private_2048.pem \
167
rsa_pss_private_2048_sha256_sha256_16.pem \
168
rsa_pss_private_2048_sha512_sha256_20.pem \
169
- rsa_pss_private_2048_sha1_sha1_20.pem \
170
rsa_pss_public_2048.pem \
171
rsa_pss_public_2048_sha256_sha256_16.pem \
172
rsa_pss_public_2048_sha512_sha256_20.pem \
173
- rsa_pss_public_2048_sha1_sha1_20.pem \
174
ed25519_private.pem \
175
ed25519_public.pem \
176
x25519_private.pem \
177
178
rsa_pss_private_2048_sha512_sha256_20.pem:
179
openssl genpkey -algorithm RSA-PSS -pkeyopt rsa_keygen_bits:2048 -pkeyopt rsa_keygen_pubexp:65537 -pkeyopt rsa_pss_keygen_md:sha512 -pkeyopt rsa_pss_keygen_mgf1_md:sha256 -pkeyopt rsa_pss_keygen_saltlen:20 -out rsa_pss_private_2048_sha512_sha256_20.pem
180
181
-rsa_pss_private_2048_sha1_sha1_20.pem:
182
- openssl genpkey -algorithm RSA-PSS -pkeyopt rsa_keygen_bits:2048 -pkeyopt rsa_keygen_pubexp:65537 -pkeyopt rsa_pss_keygen_md:sha1 -pkeyopt rsa_pss_keygen_mgf1_md:sha1 -pkeyopt rsa_pss_keygen_saltlen:20 -out rsa_pss_private_2048_sha1_sha1_20.pem
183
-
184
rsa_pss_public_2048.pem: rsa_pss_private_2048.pem
185
openssl pkey -in rsa_pss_private_2048.pem -pubout -out rsa_pss_public_2048.pem
186
187
188
rsa_pss_public_2048_sha512_sha256_20.pem: rsa_pss_private_2048_sha512_sha256_20.pem
189
openssl pkey -in rsa_pss_private_2048_sha512_sha256_20.pem -pubout -out rsa_pss_public_2048_sha512_sha256_20.pem
190
191
-rsa_pss_public_2048_sha1_sha1_20.pem: rsa_pss_private_2048_sha1_sha1_20.pem
192
- openssl pkey -in rsa_pss_private_2048_sha1_sha1_20.pem -pubout -out rsa_pss_public_2048_sha1_sha1_20.pem
193
-
194
ed25519_private.pem:
195
openssl genpkey -algorithm ED25519 -out ed25519_private.pem
196
197
Index: node-v17.3.0/test/fixtures/keys/rsa_pss_private_2048_sha1_sha1_20.pem
198
===================================================================
199
--- node-v17.3.0.orig/test/fixtures/keys/rsa_pss_private_2048_sha1_sha1_20.pem
200
+++ /dev/null
201
202
------BEGIN PRIVATE KEY-----
203
-MIIEvQIBADANBgkqhkiG9w0BAQowAASCBKcwggSjAgEAAoIBAQCpdutzsPFQ1100
204
-ouR5aAwYry8aAtG0c+zX9UqNXGCpRDWzPPpXHUZSB1BmTTL4EhK2tkAfblYNqzRu
205
-CAYlKHbFpFLs2zLEorfp0WsFNPaBHE9JHpLIM4oXxPCUypZ7JAn56Z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13ED6dYwjrDDhBTCXb7NEjELZnvATsOhc/6zJ
222
-gfSowvUQVN6K4aJ7jgAHZOKQT7ZDw7YvMpzyo4AmSQXRgG8TR34+rRu5AoGACApP
223
-9+SjSPmbFl0HQWw9Aj4xOvEHfMTcwzQmRN/23nLOZzhETJ6lzpS2VmVt8TVN9lzW
224
-nohAXdpOhQrP0HwQZjfxtlJ3J0ZUh9g8OQG3t2LO5bWbXRkBb3aKyFqRflSuDOaG
225
-4X9NagC/14R7U2loglPuf71d0SDIWQBLvZJt94ECgYEAnY7aKHnWdLszcB8uyEkJ
226
-EJkUEaa+K/nTqOzqffZ01cTWJmUG7a2KuvQ+UQM2BHk2+wBmUo45Iz/dyePOJY0B
227
-Fu2agiV4+R4z2XVQnIvXgY5HaPxvLz0THksY/pD58gBmFaLMx4ADEwQ+s4Y2g12H
228
-ABsKNRHfSnKTwOm/dYvcVqs=
229
------END PRIVATE KEY-----
230
Index: node-v17.3.0/test/fixtures/keys/rsa_pss_public_2048_sha1_sha1_20.pem
231
===================================================================
232
--- node-v17.3.0.orig/test/fixtures/keys/rsa_pss_public_2048_sha1_sha1_20.pem
233
+++ /dev/null
234
235
------BEGIN PUBLIC KEY-----
236
-MIIBIjANBgkqhkiG9w0BAQowAAOCAQ8AMIIBCgKCAQEAqXbrc7DxUNddNKLkeWgM
237
-GK8vGgLRtHPs1/VKjVxgqUQ1szz6Vx1GUgdQZk0y+BIStrZAH25WDas0bggGJSh2
238
-xaRS7NsyxKK36dFrBTT2gRxPSR6SyDOKF8TwlMqWeyQJ+emWKJ2AmfCJefEsw/Wq
239
-BeNUUxJqXMd15C9kUGtNtkYknHGGSsf8s7JFFAHU7072Mrox9TJL7H1T/jbOW0S+
240
-iFaqMBXd8b+nLb30DMc9K5bYEwvsDptwhbZ/hut8uj/2dFNg0XWnLDZDejxRlwCA
241
-dJErys7PIFaHBAYksDJHE/yg90evD2NfG9mrqmhnJvIAPoGlSd+igFuHTgI22PmI
242
-rQIDAQAB
243
------END PUBLIC KEY-----
244
Index: node-v17.3.0/test/parallel/test-crypto-key-objects.js
245
===================================================================
246
--- node-v17.3.0.orig/test/parallel/test-crypto-key-objects.js
247
+++ node-v17.3.0/test/parallel/test-crypto-key-objects.js
248
249
const publicKey = createPublicKey(publicPem);
250
const privateKey = createPrivateKey(privatePem);
251
252
- // Because no RSASSA-PSS-params appears in the PEM, no defaults should be
253
- // added for the PSS parameters. This is different from an empty
254
- // RSASSA-PSS-params sequence (see test below).
255
- const expectedKeyDetails = {
256
- modulusLength: 2048,
257
- publicExponent: 65537n
258
- };
259
-
260
assert.strictEqual(publicKey.type, 'public');
261
assert.strictEqual(publicKey.asymmetricKeyType, 'rsa-pss');
262
- assert.deepStrictEqual(publicKey.asymmetricKeyDetails, expectedKeyDetails);
263
264
assert.strictEqual(privateKey.type, 'private');
265
assert.strictEqual(privateKey.asymmetricKeyType, 'rsa-pss');
266
- assert.deepStrictEqual(privateKey.asymmetricKeyDetails, expectedKeyDetails);
267
268
assert.throws(
269
() => publicKey.export({ format: 'jwk' }),
270
271
}
272
273
{
274
- // This key pair enforces sha1 as the message digest and the MGF1
275
- // message digest and a salt length of 20 bytes.
276
-
277
- const publicPem = fixtures.readKey('rsa_pss_public_2048_sha1_sha1_20.pem');
278
- const privatePem =
279
- fixtures.readKey('rsa_pss_private_2048_sha1_sha1_20.pem');
280
-
281
- const publicKey = createPublicKey(publicPem);
282
- const privateKey = createPrivateKey(privatePem);
283
-
284
- // Unlike the previous key pair, this key pair contains an RSASSA-PSS-params
285
- // sequence. However, because all values in the RSASSA-PSS-params are set to
286
- // their defaults (see RFC 3447), the ASN.1 structure contains an empty
287
- // sequence. Node.js should add the default values to the key details.
288
- const expectedKeyDetails = {
289
- modulusLength: 2048,
290
- publicExponent: 65537n,
291
- hashAlgorithm: 'sha1',
292
- mgf1HashAlgorithm: 'sha1',
293
- saltLength: 20
294
- };
295
-
296
- assert.strictEqual(publicKey.type, 'public');
297
- assert.strictEqual(publicKey.asymmetricKeyType, 'rsa-pss');
298
- assert.deepStrictEqual(publicKey.asymmetricKeyDetails, expectedKeyDetails);
299
-
300
- assert.strictEqual(privateKey.type, 'private');
301
- assert.strictEqual(privateKey.asymmetricKeyType, 'rsa-pss');
302
- assert.deepStrictEqual(privateKey.asymmetricKeyDetails, expectedKeyDetails);
303
- }
304
-
305
- {
306
// This key pair enforces sha256 as the message digest and the MGF1
307
// message digest and a salt length of at least 16 bytes.
308
const publicPem =
309
310
const publicKey = createPublicKey(publicPem);
311
const privateKey = createPrivateKey(privatePem);
312
313
- const expectedKeyDetails = {
314
- modulusLength: 2048,
315
- publicExponent: 65537n,
316
- hashAlgorithm: 'sha512',
317
- mgf1HashAlgorithm: 'sha256',
318
- saltLength: 20
319
- };
320
-
321
assert.strictEqual(publicKey.type, 'public');
322
assert.strictEqual(publicKey.asymmetricKeyType, 'rsa-pss');
323
- assert.deepStrictEqual(publicKey.asymmetricKeyDetails, expectedKeyDetails);
324
325
assert.strictEqual(privateKey.type, 'private');
326
assert.strictEqual(privateKey.asymmetricKeyType, 'rsa-pss');
327
- assert.deepStrictEqual(privateKey.asymmetricKeyDetails, expectedKeyDetails);
328
329
// Node.js usually uses the same hash function for the message and for MGF1.
330
// However, when a different MGF1 message digest algorithm has been
331
Index: node-v17.3.0/test/parallel/test-crypto-keygen.js
332
===================================================================
333
--- node-v17.3.0.orig/test/parallel/test-crypto-keygen.js
334
+++ node-v17.3.0/test/parallel/test-crypto-keygen.js
335
336
assert.strictEqual(publicKey.asymmetricKeyType, 'rsa-pss');
337
assert.deepStrictEqual(publicKey.asymmetricKeyDetails, {
338
modulusLength: 512,
339
- publicExponent: 65537n,
340
- hashAlgorithm: 'sha256',
341
- mgf1HashAlgorithm: 'sha256',
342
- saltLength: 16
343
+ publicExponent: 65537n
344
});
345
346
assert.strictEqual(privateKey.type, 'private');
347
assert.strictEqual(privateKey.asymmetricKeyType, 'rsa-pss');
348
assert.deepStrictEqual(privateKey.asymmetricKeyDetails, {
349
modulusLength: 512,
350
- publicExponent: 65537n,
351
- hashAlgorithm: 'sha256',
352
- mgf1HashAlgorithm: 'sha256',
353
- saltLength: 16
354
+ publicExponent: 65537n
355
});
356
357
// Unlike RSA, RSA-PSS does not allow encryption.
358
359
}, common.mustSucceed((publicKey, privateKey) => {
360
const expectedKeyDetails = {
361
modulusLength: 512,
362
- publicExponent: 65537n,
363
- hashAlgorithm: 'sha256',
364
- mgf1HashAlgorithm: 'sha256',
365
- saltLength: 16
366
+ publicExponent: 65537n
367
};
368
assert.deepStrictEqual(publicKey.asymmetricKeyDetails, expectedKeyDetails);
369
assert.deepStrictEqual(privateKey.asymmetricKeyDetails, expectedKeyDetails);
370
371
}, common.mustSucceed((publicKey, privateKey) => {
372
const expectedKeyDetails = {
373
modulusLength: 512,
374
- publicExponent: 65537n,
375
- hashAlgorithm: 'sha512',
376
- mgf1HashAlgorithm: 'sha512',
377
- saltLength: 64
378
+ publicExponent: 65537n
379
};
380
assert.deepStrictEqual(publicKey.asymmetricKeyDetails, expectedKeyDetails);
381
assert.deepStrictEqual(privateKey.asymmetricKeyDetails, expectedKeyDetails);
382
383
}, common.mustSucceed((publicKey, privateKey) => {
384
const expectedKeyDetails = {
385
modulusLength: 512,
386
- publicExponent: 65537n,
387
- hashAlgorithm: 'sha512',
388
- mgf1HashAlgorithm: 'sha512',
389
- saltLength: 0
390
+ publicExponent: 65537n
391
};
392
assert.deepStrictEqual(publicKey.asymmetricKeyDetails, expectedKeyDetails);
393
assert.deepStrictEqual(privateKey.asymmetricKeyDetails, expectedKeyDetails);
394
395
assert.strictEqual(publicKey.asymmetricKeyType, 'rsa-pss');
396
assert.deepStrictEqual(publicKey.asymmetricKeyDetails, {
397
modulusLength: 512,
398
- publicExponent: 65537n,
399
- hashAlgorithm: 'sha256',
400
- mgf1HashAlgorithm: 'sha256',
401
- saltLength: 16
402
+ publicExponent: 65537n
403
});
404
405
assert.strictEqual(privateKey.type, 'private');
406
assert.strictEqual(privateKey.asymmetricKeyType, 'rsa-pss');
407
assert.deepStrictEqual(privateKey.asymmetricKeyDetails, {
408
modulusLength: 512,
409
- publicExponent: 65537n,
410
- hashAlgorithm: 'sha256',
411
- mgf1HashAlgorithm: 'sha256',
412
- saltLength: 16
413
+ publicExponent: 65537n
414
});
415
}));
416
}
417
Index: node-v17.3.0/test/parallel/test-crypto-keygen-deprecation.js
418
===================================================================
419
--- node-v17.3.0.orig/test/parallel/test-crypto-keygen-deprecation.js
420
+++ node-v17.3.0/test/parallel/test-crypto-keygen-deprecation.js
421
422
assert.strictEqual(publicKey.asymmetricKeyType, 'rsa-pss');
423
assert.deepStrictEqual(publicKey.asymmetricKeyDetails, {
424
modulusLength: 512,
425
- publicExponent: 65537n,
426
- hashAlgorithm: 'sha256',
427
- mgf1HashAlgorithm: 'sha256',
428
- saltLength: 16
429
+ publicExponent: 65537n
430
});
431
432
assert.strictEqual(privateKey.type, 'private');
433
assert.strictEqual(privateKey.asymmetricKeyType, 'rsa-pss');
434
assert.deepStrictEqual(privateKey.asymmetricKeyDetails, {
435
modulusLength: 512,
436
- publicExponent: 65537n,
437
- hashAlgorithm: 'sha256',
438
- mgf1HashAlgorithm: 'sha256',
439
- saltLength: 16
440
+ publicExponent: 65537n
441
});
442
}));
443
}
444