@@ -1543,44 +1543,65 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
1543
1543
}
1544
1544
}
1545
1545
1546
- if ( ! common . hasOpenSSL3 ) {
1547
- // Passing an empty passphrase string should not cause OpenSSL's default
1548
- // passphrase prompt in the terminal.
1549
- // See https://github.com/nodejs/node/issues/35898.
1550
-
1551
- for ( const type of [ 'pkcs1' , 'pkcs8' ] ) {
1552
- generateKeyPair ( 'rsa' , {
1553
- modulusLength : 1024 ,
1554
- privateKeyEncoding : {
1555
- type,
1556
- format : 'pem' ,
1557
- cipher : 'aes-256-cbc' ,
1558
- passphrase : ''
1559
- }
1560
- } , common . mustSucceed ( ( publicKey , privateKey ) => {
1561
- assert . strictEqual ( publicKey . type , 'public' ) ;
1546
+ // Passing an empty passphrase string should not cause OpenSSL's default
1547
+ // passphrase prompt in the terminal.
1548
+ // See https://github.com/nodejs/node/issues/35898.
1562
1549
1563
- for ( const passphrase of [ '' , Buffer . alloc ( 0 ) ] ) {
1564
- const privateKeyObject = createPrivateKey ( {
1565
- passphrase,
1566
- key : privateKey
1567
- } ) ;
1568
- assert . strictEqual ( privateKeyObject . asymmetricKeyType , 'rsa' ) ;
1569
- }
1550
+ for ( const type of [ 'pkcs1' , 'pkcs8' ] ) {
1551
+ generateKeyPair ( 'rsa' , {
1552
+ modulusLength : 1024 ,
1553
+ privateKeyEncoding : {
1554
+ type,
1555
+ format : 'pem' ,
1556
+ cipher : 'aes-256-cbc' ,
1557
+ passphrase : ''
1558
+ }
1559
+ } , common . mustSucceed ( ( publicKey , privateKey ) => {
1560
+ assert . strictEqual ( publicKey . type , 'public' ) ;
1570
1561
1571
- // Encrypting with an empty passphrase is not the same as not encrypting
1572
- // the key, and not specifying a passphrase should fail when decoding it.
1573
- assert . throws ( ( ) => {
1574
- return testSignVerify ( publicKey , privateKey ) ;
1575
- } , {
1576
- name : 'TypeError' ,
1577
- code : 'ERR_MISSING_PASSPHRASE' ,
1578
- message : 'Passphrase required for encrypted key'
1562
+ for ( const passphrase of [ '' , Buffer . alloc ( 0 ) ] ) {
1563
+ const privateKeyObject = createPrivateKey ( {
1564
+ passphrase,
1565
+ key : privateKey
1579
1566
} ) ;
1580
- } ) ) ;
1581
- }
1567
+ assert . strictEqual ( privateKeyObject . asymmetricKeyType , 'rsa' ) ;
1568
+ }
1569
+
1570
+ // Encrypting with an empty passphrase is not the same as not encrypting
1571
+ // the key, and not specifying a passphrase should fail when decoding it.
1572
+ assert . throws ( ( ) => {
1573
+ return testSignVerify ( publicKey , privateKey ) ;
1574
+ } , common . hasOpenSSL3 ? {
1575
+ name : 'Error' ,
1576
+ code : 'ERR_OSSL_CRYPTO_INTERRUPTED_OR_CANCELLED' ,
1577
+ message : 'error:07880109:common libcrypto routines::interrupted or cancelled'
1578
+ } : {
1579
+ name : 'TypeError' ,
1580
+ code : 'ERR_MISSING_PASSPHRASE' ,
1581
+ message : 'Passphrase required for encrypted key'
1582
+ } ) ;
1583
+ } ) ) ;
1582
1584
}
1583
1585
1586
+ // Passing an empty passphrase string should not throw ERR_OSSL_CRYPTO_MALLOC_FAILURE even on OpenSSL 3.
1587
+ // Regression test for https://github.com/nodejs/node/issues/41428.
1588
+ generateKeyPair ( 'rsa' , {
1589
+ modulusLength : 4096 ,
1590
+ publicKeyEncoding : {
1591
+ type : 'spki' ,
1592
+ format : 'pem'
1593
+ } ,
1594
+ privateKeyEncoding : {
1595
+ type : 'pkcs8' ,
1596
+ format : 'pem' ,
1597
+ cipher : 'aes-256-cbc' ,
1598
+ passphrase : ''
1599
+ }
1600
+ } , common . mustSucceed ( ( publicKey , privateKey ) => {
1601
+ assert . strictEqual ( typeof publicKey , 'string' ) ;
1602
+ assert . strictEqual ( typeof privateKey , 'string' ) ;
1603
+ } ) ) ;
1604
+
1584
1605
{
1585
1606
// Proprietary Web Cryptography API ECDH/ECDSA namedCurve parameters
1586
1607
// should not be recognized in this API.
0 commit comments