-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exception when using privateEncrypt
/privateDecrypt
with certain encrypted keys
#40814
Comments
privateEncrypt/privateDecrypt
on certain key typesprivateEncrypt
/privateDecrypt
with certain encrypted keys
Thank you for the report. This is an interesting one. I've been debugging this for a while now and something seems very wrong here. Most spectacularly, in Node.js 17 (both on Windows and Ubuntu), the first attempt to load an
|
I'm seeing something similar on node 16.3.1 on Ubuntu 20.04, but with a sightly different error: Error: error:0D0C5006:asn1 encoding routines:ASN1_item_verify:EVP lib It doesn't seem to be a first or second call that always fails, I'm getting this both after a successful call and when this is the fist call.
|
when crypto.generateKeyPairSync comes with certain parameters. Because the error stack is not cleaned up when crypto.generateKeyPairSync exits. Fixes: nodejs#40814
crypto.generateKeyPairSync with certain parameters Because the error stack is not cleaned up when crypto.generateKeyPairSync exits. Fixes: nodejs#40814
crypto.privateEncrypt fails for the first time after crypto.generateKeyPairSync with certain parameters Because the error stack is not cleaned up when crypto.generateKeyPairSync exits. Fixes: nodejs#40814
crypto.privateEncrypt fails for the first time after crypto.generateKeyPairSync with certain parameters Because the error stack is not cleaned up when crypto.generateKeyPairSync exits. Fixes: nodejs#40814
`crypto.privateEncrypt` fails for the first time after `crypto.generateKeyPairSync` with certain parameters because the error stack is not cleaned up when `crypto.generateKeyPairSync` exits. Fixes: #40814 PR-URL: #42793 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Filip Skokan <[email protected]>
`crypto.privateEncrypt` fails for the first time after `crypto.generateKeyPairSync` with certain parameters because the error stack is not cleaned up when `crypto.generateKeyPairSync` exits. Fixes: #40814 PR-URL: #42793 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Filip Skokan <[email protected]>
Alright, fix seemingly works, but for only ECB ciphers, other ciphers like -ccm -ctr -ocb -xts variants and other cipher types are still broken with more or less the same error... or a variant of it const crypto = require("crypto");
crypto.getCiphers().forEach((cipherString) => {
console.log(`Testing: ${cipherString}`);
if(cipherString == "des3-wrap" || cipherString == "aes128-wrap" || cipherString == "aes192-wrap" || cipherString == "aes256-wrap" || cipherString == "id-aes128-wrap" || cipherString == "id-aes128-wrap-pad" || cipherString == "id-aes192-wrap" || cipherString == "id-aes192-wrap-pad" || cipherString == "id-aes256-wrap" || cipherString == "id-aes256-wrap-pad") {
console.log(`\x1b[33m[SKIPPED] ${cipherString} due to segmentation fault`);
console.log("\x1b[37m"); // turn text back to white
return;
}
try {
let { privateKey, publicKey } = crypto.generateKeyPairSync("rsa", {
modulusLength: 2048,
publicKeyEncoding: {
type: "spki",
format: "pem"
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem',
cipher: cipherString,
passphrase: "abcdef"
}
});
const encryptedString = crypto.privateEncrypt({
key: privateKey,
passphrase: "abcdef"
}, Buffer.from("The quick brown fox jumps over the lazy dog")).toString("base64");
const decryptedString = crypto.publicDecrypt(publicKey, Buffer.from(encryptedString, "base64")).toString();
console.log(`\x1b[32m[PASS]`);
console.log(`Encrypted: ${encryptedString}`);
console.log(`Decrypted: ${decryptedString}`);
} catch(err) {
console.log(`\x1b[31m[FAILED] ${err.stack}`);
}
console.log("\x1b[37m"); // turn text back to white
}); Broken ciphers:
Additionally, the following ciphers throw an Segmentation fault:
With the exception of
Versions i tried:
I'm not really sure if these would apply for an separate issue, or it should be an continuation of this issue... or even if it should be valid, in my opinion it is since I would expect this to work with all ciphers at |
@PANCHO7532B you should probably open a new issue, or a directly a PR if you know what is the fix. |
`crypto.privateEncrypt` fails for the first time after `crypto.generateKeyPairSync` with certain parameters because the error stack is not cleaned up when `crypto.generateKeyPairSync` exits. Fixes: #40814 PR-URL: #42793 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Filip Skokan <[email protected]>
`crypto.privateEncrypt` fails for the first time after `crypto.generateKeyPairSync` with certain parameters because the error stack is not cleaned up when `crypto.generateKeyPairSync` exits. Fixes: #40814 PR-URL: #42793 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Filip Skokan <[email protected]>
`crypto.privateEncrypt` fails for the first time after `crypto.generateKeyPairSync` with certain parameters because the error stack is not cleaned up when `crypto.generateKeyPairSync` exits. Fixes: #40814 PR-URL: #42793 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Filip Skokan <[email protected]>
`crypto.privateEncrypt` fails for the first time after `crypto.generateKeyPairSync` with certain parameters because the error stack is not cleaned up when `crypto.generateKeyPairSync` exits. Fixes: #40814 PR-URL: #42793 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Filip Skokan <[email protected]>
Version
v16.13.0
Platform
Linux EURO01 5.4.0-88-generic #99-Ubuntu SMP Thu Sep 23 17:29:00 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
Subsystem
crypto
What steps will reproduce the bug?
aes-128-ecb
oraes-128-ocb
Code:
How often does it reproduce? Is there a required condition?
This only happens with some ciphers, some like
aes-128-ccm
oraes-128-cbc
and other variants works just fine, other ciphers fail with an errorWhat is the expected behavior?
An successful encryption/decryption with the specified ciphers
What do you see instead?
Additional information
In v14.17.3 (the version i had previously) Node.JS would crash with a core dump on some ciphers (like GCM based ciphers)
The text was updated successfully, but these errors were encountered: