Skip to content

Commit ee1cc59

Browse files
committed
crypto: fix generateKeyPair with encoding 'jwk'
nodejs/node#39319
1 parent b7031d5 commit ee1cc59

File tree

1 file changed

+41
-16
lines changed

1 file changed

+41
-16
lines changed

patches/node/fix_crypto_tests_to_run_with_bssl.patch

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ index af2146982c7a3bf7bd7527f44e4b17a3b605026e..f6b91f675cfea367c608892dee078b56
489489
// Non-XOF hash functions should accept valid outputLength options as well.
490490
assert.strictEqual(crypto.createHash('sha224', { outputLength: 28 })
491491
diff --git a/test/parallel/test-crypto-key-objects.js b/test/parallel/test-crypto-key-objects.js
492-
index aa03a0379a291a4632b68d428d4e1875d60166a3..38d851ba0e76fcf3905978fae3dde7befd643041 100644
492+
index aa03a0379a291a4632b68d428d4e1875d60166a3..a6862ace1fa73473b406fe4513b9e7a99296d365 100644
493493
--- a/test/parallel/test-crypto-key-objects.js
494494
+++ b/test/parallel/test-crypto-key-objects.js
495495
@@ -307,11 +307,11 @@ const privateDsa = fixtures.readKey('dsa_private_encrypted_1025.pem',
@@ -554,6 +554,15 @@ index aa03a0379a291a4632b68d428d4e1875d60166a3..38d851ba0e76fcf3905978fae3dde7be
554554
{
555555
// Reading an encrypted key without a passphrase should fail.
556556
assert.throws(() => createPrivateKey(privateDsa), common.hasOpenSSL3 ? {
557+
@@ -546,7 +548,7 @@ const privateDsa = fixtures.readKey('dsa_private_encrypted_1025.pem',
558+
}), {
559+
message: common.hasOpenSSL3 ?
560+
'error:1E08010C:DECODER routines::unsupported' :
561+
- /bad decrypt/
562+
+ /bad decrypt|error:1e000065:Cipher functions:OPENSSL_internal:BAD_DECRYPT/
563+
});
564+
565+
const publicKey = createPublicKey(publicDsa);
557566
@@ -569,7 +571,7 @@ const privateDsa = fixtures.readKey('dsa_private_encrypted_1025.pem',
558567
() => privateKey.export({ format: 'jwk' }),
559568
{ code: 'ERR_CRYPTO_JWK_UNSUPPORTED_KEY_TYPE' });
@@ -573,14 +582,14 @@ index aa03a0379a291a4632b68d428d4e1875d60166a3..38d851ba0e76fcf3905978fae3dde7be
573582
// Exporting an encrypted private key requires a cipher
574583
const privateKey = createPrivateKey(privatePem);
575584
diff --git a/test/parallel/test-crypto-keygen.js b/test/parallel/test-crypto-keygen.js
576-
index ed5986e6bfd4211a1cc22fa94aaf68fc1013133f..98af3444743467cd39c5b5c2b31b462c85504463 100644
585+
index ed5986e6bfd4211a1cc22fa94aaf68fc1013133f..08986a6793a39b275277c8bf188316f669a53c63 100644
577586
--- a/test/parallel/test-crypto-keygen.js
578587
+++ b/test/parallel/test-crypto-keygen.js
579588
@@ -297,6 +297,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
580589
}));
581590
}
582591

583-
+ /*
592+
+/*
584593
{
585594
// Test RSA-PSS.
586595
generateKeyPair('rsa-pss', {
@@ -590,7 +599,7 @@ index ed5986e6bfd4211a1cc22fa94aaf68fc1013133f..98af3444743467cd39c5b5c2b31b462c
590599
}
591600
+*/
592601

593-
+ /*
602+
+/*
594603
{
595604
const privateKeyEncoding = {
596605
type: 'pkcs8',
@@ -638,35 +647,51 @@ index ed5986e6bfd4211a1cc22fa94aaf68fc1013133f..98af3444743467cd39c5b5c2b31b462c
638647
});
639648
}));
640649

641-
+/*
650+
+ /*
642651
// Test async elliptic curve key generation, e.g. for ECDSA, with an encrypted
643652
// private key with paramEncoding explicit.
644653
generateKeyPair('ec', {
645-
@@ -688,6 +697,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
654+
@@ -686,6 +695,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
655+
}
656+
}
646657
});
658+
+ */
647659
}
648660

649-
+*/
650661
// Test invalid parameter encoding.
651-
{
662+
@@ -709,6 +719,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
663+
message: "The property 'options.paramEncoding' is invalid. " +
664+
"Received 'otherEncoding'"
665+
});
666+
+ /*
667+
assert.throws(() => generateKeyPairSync('dsa', {
668+
modulusLength: 4096,
669+
publicKeyEncoding: {
670+
@@ -722,6 +733,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
671+
code: 'ERR_CRYPTO_JWK_UNSUPPORTED_KEY_TYPE',
672+
message: 'Unsupported JWK Key Type.'
673+
});
674+
+ */
652675
assert.throws(() => generateKeyPairSync('ec', {
653-
@@ -1060,6 +1070,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
676+
namedCurve: 'secp224r1',
677+
publicKeyEncoding: {
678+
@@ -1060,6 +1072,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
654679
}
655680
}
656681

657682
+ /*
658683
// Test DSA parameters.
659684
{
660685
// Test invalid modulus lengths.
661-
@@ -1087,6 +1098,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
686+
@@ -1087,6 +1100,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
662687
});
663688
}
664689
}
665690
+*/
666691

667692
// Test EC parameters.
668693
{
669-
@@ -1131,13 +1143,13 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
694+
@@ -1131,13 +1145,13 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
670695
}));
671696

672697
generateKeyPair('ec', {
@@ -683,7 +708,7 @@ index ed5986e6bfd4211a1cc22fa94aaf68fc1013133f..98af3444743467cd39c5b5c2b31b462c
683708
});
684709
}));
685710
}
686-
@@ -1145,7 +1157,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
711+
@@ -1145,7 +1159,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
687712
// Test EdDSA key generation.
688713
{
689714
if (!/^1\.1\.0/.test(process.versions.openssl)) {
@@ -692,31 +717,31 @@ index ed5986e6bfd4211a1cc22fa94aaf68fc1013133f..98af3444743467cd39c5b5c2b31b462c
692717
generateKeyPair(keyType, common.mustSucceed((publicKey, privateKey) => {
693718
assert.strictEqual(publicKey.type, 'public');
694719
assert.strictEqual(publicKey.asymmetricKeyType, keyType);
695-
@@ -1159,6 +1171,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
720+
@@ -1159,6 +1173,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
696721
}
697722
}
698723

699724
+/*
700725
// Test classic Diffie-Hellman key generation.
701726
{
702727
generateKeyPair('dh', {
703-
@@ -1271,6 +1284,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
728+
@@ -1271,6 +1286,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
704729
});
705730
}
706731
}
707732
+*/
708733

709734
// Test invalid key encoding types.
710735
{
711-
@@ -1471,6 +1485,7 @@ if (!common.hasOpenSSL3) {
736+
@@ -1471,6 +1487,7 @@ if (!common.hasOpenSSL3) {
712737
}, common.mustSucceed((publicKey, privateKey) => {
713738
assert.strictEqual(publicKey.type, 'public');
714739

715740
+ /*
716741
for (const passphrase of ['', Buffer.alloc(0)]) {
717742
const privateKeyObject = createPrivateKey({
718743
passphrase,
719-
@@ -1478,6 +1493,7 @@ if (!common.hasOpenSSL3) {
744+
@@ -1478,6 +1495,7 @@ if (!common.hasOpenSSL3) {
720745
});
721746
assert.strictEqual(privateKeyObject.asymmetricKeyType, 'rsa');
722747
}

0 commit comments

Comments
 (0)