Repository navigation
DiffieHellman/ECDH Generates invalid keypairs #14628
Description
Activity
- addedcryptoIssues and PRs related to the crypto subsystem.Issues and PRs related to the crypto subsystem.
on Aug 4, 2017 /cc @nodejs/crypto
(also edited the OP to add syntax highlighting)
- addedfeature requestIssues requesting new Node.js features.Issues requesting new Node.js features.
on Aug 4, 2017 Let me confirm that in your sample code you created a DH public and private key pair and tried to use them in
publicEncrypt/publicDecryptby formatting the DH key pair into PEM. It that right?publicEncrypt/publicDecryptonly support RSA not ElGamal. Is that the reason why the error was occurred?This seems like a wrong expectation to me. The documentation is clear that
publicEncrypt()and friends use RSA, nowhere does it mention ElGamal; OpenSSL supports only the former, not the latter.I'll close this out.
- addedinvalidIssues and PRs that are invalid.Issues and PRs that are invalid.and removedfeature requestIssues requesting new Node.js features.Issues requesting new Node.js features.
on Aug 4, 2017 FWIW I have to do the same thing in my
ssh2-streamsmodule before passing a key toverifier.verify(). It's annoying that non-PEM keys are not allowed, but at least the code to wrap it in a PEM format isn't too horrible...I think that is what the OP is requesting, to be able to pass in an RSA, etc. key without the PEM formatting (just binary). That is a valid feature request to me IMHO.
- addedfeature requestIssues requesting new Node.js features.Issues requesting new Node.js features.and removedinvalidIssues and PRs that are invalid.Issues and PRs that are invalid.
on Aug 4, 2017 @mgwhitfield Is ^ what you are requesting?
I'm going to close this out again since OP didn't follow up.
@mscdex If you think this is a worthwhile feature, can you open a new issue with a better description?
I think that is what the OP is requesting, to be able to pass in an RSA, etc. key without the PEM formatting (just binary). That is a valid feature request to me IMHO.
Currently,
verifyer.verify()supports three types of pem formats of an RSA public key as pcks#1, pcks#8 and x509 cert with looking at each pem headers. If we have an additional support of der(binary) format, I guess we need to add an new option to specify such types. So I think the current supporting only pem format is better.Though the heuristics to detect DER are pretty robust, IIRC its 2 fixed bytes at the beginning for a constructed sequence, then a couple bytes for a length that has to match the buffer length, so hard to confuse with PEM.
Yeah, but a DER-encoded value can be one of several things: a public or private RSA, DSA or EC key (maybe more) in PKCS#1, PKCS#8 or PKCS#12 format (again, maybe more.)
I know my crypto standards pretty well and I still wouldn't want to vouch you can parse them unambiguously.
Yes, if its not just PEM vs DER, its more than a quick check. I implemented all three of those PKCS standards for all three of those key types and I'm pretty sure my CLI detected them just fine, but I had a BER decoder API so I could peek into the structure for OIDs and element counts, it might be hard without that. I've added it to my (exceedingly deep) list of things to try, running code being the most convincing.
Error is thrown:
error:0D07207B:asn1 encoding routines:ASN1_get_object:header too long
User Experience Log:
A user should not have to manually wrap the generated keys in the proper "PEM" format since PEM is very precious about spaces. Without wanting to be pejorative, that sucks. The fact that this code example still doesn't work after the fact also sucks.
Suggestion:
Remove/deprecate this API or fix it or provide clearer examples to perform this common functionality.
Workaround:
Utilize
opensslexecutable as a child proc to generate keys instead.