-
Notifications
You must be signed in to change notification settings - Fork 784
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
Only 8, 16, 24, or 32 bits supported: 248 #1059
Comments
Unfortunate it's a submitted private key issue. Do you happen to have an example test case that isn't secret? Based on that error it would seem like some DER decoding issue. Maybe there are some edge cases out there that trigger a bug. Or could be bad input to start with and the error is poor. Hard to debug such things without an test case. |
Yes sure - here's a private key that's been revoked
password Computinggraduate and it was generated with the following code:
|
I poked at this for a few minutes. Not sure what the issue is. Unfortunately I don't have time to deep dive debug it at the moment. But here are some thoughts:
This test does a simple decrypt of the test static pem and password. It always fails. Most other passwords I tested will return null. const forge = require('node-forge');
const pem = `\
-----BEGIN ENCRYPTED PRIVATE KEY-----
MIIE6jAcBgoqhkiG9w0BDAEDMA4ECKPGG1SWab+cAgIIAASCBMjLabq/o+YaxNEL
bIcGr/2oO7QfLY2ebondYNqbfF5Ou7t8sEyE1nDZNOdiVRLng29b7CDnlFMOKA6X
Xi30z7Vh61GPsdyfvEEEUU39V26tgpud3NRApJzIcUQ1DkpRQKgKTpo+tx+Qe1z4
ZYKotgIoXl8sWOEJbKMkoGoEfZzbugmbNAO0ICCByIGJoVmFXl8o5D9qhCCaCB1W
XjvDFtLqxNjFlAxrN93vJ2dGYvc+OXId31TciMPQeckzdtLC5UrfDVVaBom7ueWV
OVo+jmHE/Yg5cuZGWM/s0xygmpfJJ7UsTCpiV4ctFf8uRB5AsM0wdmNl/DK9lhD+
lYt2UfztS58Z/KDPPzoJD5rSEyO9FKRx+QPcAhJBY4l7t+bAZneE2w5ALe+vfp0A
KIW+/rCpNnhA70SdIR9FfkcusQsn540kmv99+AFbX2VQmJ15m7UXw7c/uYrkeY+0
Pyn4tKb2hz6E3J9AhBQPCF44RwVnLlrQrJpL2v+NleXKIHs/rVGGi0Gby3Bzxb5S
9+uKYK7hpsc0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fui2PFGLe2uKf
2fiZMc0hL1oYeZK3Ffg=
-----END ENCRYPTED PRIVATE KEY-----
`;
const pw = 'Computinggraduate';
try {
const privateKey = forge.pki.decryptRsaPrivateKey(pem, pw);
console.log('PASS');
console.log(privateKey);
} catch (ex) {
console.log('FAIL');
console.error(ex);
} If you want to find a key that does something weird, you can loop around with different prefixes just to get nonsense decrypted data. For instance, the below finds a non-null decode for "t17" and fails for "Unparsed DER bytes remain after ASN.1 parsing". let res = null;
let i = 0;
const prefix = 't';
while(res === null) {
console.log(i);
res = forge.pki.decryptRsaPrivateKey(pem, prefix + i++);
} This test does what I think you were doing. It will create private key pem and they try to decrypt it. Uses different keys and passwords to try and trigger and weird data issues. It just keeps looping and not failing. const forge = require('node-forge');
let i = 0;
let run = 1;
while(run) {
const keys = forge.pki.rsa.generateKeyPair({bits: 2048, workers: -1});
const algOpts = {algorithm: '3des'};
const pw = 'Computinggraduate' + i;
const pem = forge.pki.encryptRsaPrivateKey(keys.privateKey, pw, algOpts);
console.log(i++);
console.log(pem);
const privateKey = forge.pki.decryptRsaPrivateKey(pem, pw);
//console.log(privateKey);
if(!privateKey) {
console.log('FAIL');
run = 0;
}
} I'm not sure what the best behavior is here. Maybe the code should catch any errors and return null? It's likely rare people have bad DER that can't parse into ASN.1, but it could happen. It is possible there is bug in either the encryption process or decryption process that gets triggered with the test data. But I'm not really sure how to tell. Do you have any more failing test data? |
I'm sure the password is correct, this is not the only user that has had this problem. |
Hello,
I'm trying to decrypt a private key but am getting the following error when trying to decrypt - I was wondering if anyone has seen this before please?
Weirdly, this only seems to be from 'certain' private keys - we have lots of users that decrypt without issue, but every so often we get this error from Forge,
Thanks,
Will.
The code used is as follows:
The text was updated successfully, but these errors were encountered: