Skip to content

Commit adf7f40

Browse files
committed
crypto: fix JWK RSA-PSS SubtleCrypto.exportKey
nodejs/node#39828
1 parent f77b4e4 commit adf7f40

1 file changed

Lines changed: 70 additions & 14 deletions

File tree

‎patches/node/fix_crypto_tests_to_run_with_bssl.patch‎

Lines changed: 70 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ index c2c47a9ce72f124c78f2743cf88ccd96d714fa1b..fcdbad0262fa1dd8a7858f255d0e5e45
582582
// Exporting an encrypted private key requires a cipher
583583
const privateKey = createPrivateKey(privatePem);
584584
diff --git a/test/parallel/test-crypto-keygen.js b/test/parallel/test-crypto-keygen.js
585-
index 09d43317426e712f60d4eba380cd4e044e3f3cf8..7dbe07c493dd092a88bffb8ccf6a0fbfcd280662 100644
585+
index 09d43317426e712f60d4eba380cd4e044e3f3cf8..43c274b96fbb1c4d8398e2d32b625da21e85d6a6 100644
586586
--- a/test/parallel/test-crypto-keygen.js
587587
+++ b/test/parallel/test-crypto-keygen.js
588588
@@ -297,6 +297,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
@@ -613,31 +613,70 @@ index 09d43317426e712f60d4eba380cd4e044e3f3cf8..7dbe07c493dd092a88bffb8ccf6a0fbf
613613
{
614614
const privateKeyEncoding = {
615615
type: 'pkcs8',
616-
@@ -438,6 +443,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
616+
@@ -417,6 +422,9 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
617+
});
618+
}));
619+
}
620+
+*/
621+
+
622+
+/*
623+
{
624+
// Test async DSA key object generation.
625+
generateKeyPair('dsa', {
626+
@@ -438,7 +446,9 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
617627
});
618628
}));
619629
}
620630
+*/
621631

632+
+/*
622633
{
623634
// Test async elliptic curve key generation, e.g. for ECDSA, with a SEC1
624-
@@ -593,6 +599,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
635+
// private key.
636+
@@ -552,8 +562,10 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
637+
testSignVerify(publicKey, { key: privateKey, passphrase: 'secret' });
638+
}));
639+
}
640+
+*/
641+
642+
{
643+
+ /*
644+
// Test async elliptic curve key generation, e.g. for ECDSA, with an encrypted
645+
// private key.
646+
generateKeyPair('ec', {
647+
@@ -590,9 +602,11 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
648+
passphrase: 'top secret'
649+
});
650+
}));
651+
+ */
625652

626653
// Test async elliptic curve key generation, e.g. for ECDSA, with an encrypted
627654
// private key with paramEncoding explicit.
628655
+ /*
629656
generateKeyPair('ec', {
630657
namedCurve: 'P-256',
631658
paramEncoding: 'explicit',
632-
@@ -627,6 +634,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
659+
@@ -627,15 +641,16 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
633660
passphrase: 'top secret'
634661
});
635662
}));
636663
+ */
637664

638665
// Test async elliptic curve key generation with 'jwk' encoding
639666
[
640-
@@ -738,6 +746,8 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
667+
- ['ec', ['P-384', 'P-256', 'P-521', 'secp256k1']],
668+
+ ['ec', ['P-384', 'P-256', 'P-521', /*'secp256k1'*/]],
669+
['rsa'],
670+
['ed25519'],
671+
- ['ed448'],
672+
+ // ['ed448'],
673+
['x25519'],
674+
- ['x448'],
675+
+ // ['x448'],
676+
].forEach((types) => {
677+
const [type, options] = types;
678+
switch (type) {
679+
@@ -738,6 +753,8 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
641680
message: "The property 'options.paramEncoding' is invalid. " +
642681
"Received 'otherEncoding'"
643682
});
@@ -646,7 +685,7 @@ index 09d43317426e712f60d4eba380cd4e044e3f3cf8..7dbe07c493dd092a88bffb8ccf6a0fbf
646685
assert.throws(() => generateKeyPairSync('dsa', {
647686
modulusLength: 4096,
648687
publicKeyEncoding: {
649-
@@ -751,6 +761,8 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
688+
@@ -751,6 +768,8 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
650689
code: 'ERR_CRYPTO_JWK_UNSUPPORTED_KEY_TYPE',
651690
message: 'Unsupported JWK Key Type.'
652691
});
@@ -655,23 +694,23 @@ index 09d43317426e712f60d4eba380cd4e044e3f3cf8..7dbe07c493dd092a88bffb8ccf6a0fbf
655694
assert.throws(() => generateKeyPairSync('ec', {
656695
namedCurve: 'secp224r1',
657696
publicKeyEncoding: {
658-
@@ -1089,6 +1101,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
697+
@@ -1089,6 +1108,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
659698
}
660699
}
661700

662701
+/*
663702
// Test DSA parameters.
664703
{
665704
// Test invalid modulus lengths.
666-
@@ -1116,6 +1129,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
705+
@@ -1116,6 +1136,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
667706
});
668707
}
669708
}
670709
+*/
671710

672711
// Test EC parameters.
673712
{
674-
@@ -1160,13 +1174,13 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
713+
@@ -1160,13 +1181,13 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
675714
}));
676715

677716
generateKeyPair('ec', {
@@ -688,7 +727,7 @@ index 09d43317426e712f60d4eba380cd4e044e3f3cf8..7dbe07c493dd092a88bffb8ccf6a0fbf
688727
});
689728
}));
690729
}
691-
@@ -1174,7 +1188,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
730+
@@ -1174,7 +1195,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
692731
// Test EdDSA key generation.
693732
{
694733
if (!/^1\.1\.0/.test(process.versions.openssl)) {
@@ -697,31 +736,31 @@ index 09d43317426e712f60d4eba380cd4e044e3f3cf8..7dbe07c493dd092a88bffb8ccf6a0fbf
697736
generateKeyPair(keyType, common.mustSucceed((publicKey, privateKey) => {
698737
assert.strictEqual(publicKey.type, 'public');
699738
assert.strictEqual(publicKey.asymmetricKeyType, keyType);
700-
@@ -1188,6 +1202,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
739+
@@ -1188,6 +1209,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
701740
}
702741
}
703742

704743
+/*
705744
// Test classic Diffie-Hellman key generation.
706745
{
707746
generateKeyPair('dh', {
708-
@@ -1300,6 +1315,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
747+
@@ -1300,6 +1322,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
709748
});
710749
}
711750
}
712751
+*/
713752

714753
// Test invalid key encoding types.
715754
{
716-
@@ -1500,6 +1516,7 @@ if (!common.hasOpenSSL3) {
755+
@@ -1500,6 +1523,7 @@ if (!common.hasOpenSSL3) {
717756
}, common.mustSucceed((publicKey, privateKey) => {
718757
assert.strictEqual(publicKey.type, 'public');
719758

720759
+ /*
721760
for (const passphrase of ['', Buffer.alloc(0)]) {
722761
const privateKeyObject = createPrivateKey({
723762
passphrase,
724-
@@ -1507,6 +1524,7 @@ if (!common.hasOpenSSL3) {
763+
@@ -1507,6 +1531,7 @@ if (!common.hasOpenSSL3) {
725764
});
726765
assert.strictEqual(privateKeyObject.asymmetricKeyType, 'rsa');
727766
}
@@ -1200,6 +1239,23 @@ index 151eebd36c9765df086a020ba42920b2442b1b77..efe97ff2499cba909ac5500d827364fa
12001239
});
12011240
}
12021241

1242+
diff --git a/test/parallel/test-webcrypto-export-import-rsa.js b/test/parallel/test-webcrypto-export-import-rsa.js
1243+
index 04cf6388fc739d3eab0a8d47857590c7a9b84342..d111e697db652b98dd8a9eb7869b1a98ba6bca79 100644
1244+
--- a/test/parallel/test-webcrypto-export-import-rsa.js
1245+
+++ b/test/parallel/test-webcrypto-export-import-rsa.js
1246+
@@ -480,6 +480,7 @@ const testVectors = [
1247+
await Promise.all(variations);
1248+
})().then(common.mustCall());
1249+
1250+
+/*
1251+
{
1252+
const publicPem = fixtures.readKey('rsa_pss_public_2048.pem', 'ascii');
1253+
const privatePem = fixtures.readKey('rsa_pss_private_2048.pem', 'ascii');
1254+
@@ -521,3 +522,4 @@ const testVectors = [
1255+
assert.strictEqual(jwk.alg, 'PS256');
1256+
})().then(common.mustCall());
1257+
}
1258+
+*/
12031259
diff --git a/test/parallel/test-webcrypto-wrap-unwrap.js b/test/parallel/test-webcrypto-wrap-unwrap.js
12041260
index 1094845c73e14313860ad476fb7baba2a11b5af4..51972b4b34b191ac59145889dbf2da5c0d407dbe 100644
12051261
--- a/test/parallel/test-webcrypto-wrap-unwrap.js

0 commit comments

Comments
 (0)