Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upcrypto: reject public keys properly #29913
Conversation
|
||
// This should not abort either: https://github.com/nodejs/node/issues/29904 | ||
assert.throws(() => { | ||
createPrivateKey({ key: Buffer.alloc(0), format: 'der', type: 'spki' }); |
This comment has been minimized.
This comment has been minimized.
sam-github
Oct 10, 2019
Member
There are other formats for public keys, perhaps its worth testing them all?
This comment has been minimized.
This comment has been minimized.
tniessen
Oct 10, 2019
Author
Member
I think the only other supported type is pkcs1
which behaves differently, but I added a test case for that as well.
This comment has been minimized.
This comment has been minimized.
Line 3349 in 7f22aaf enum PKEncodingType . I suggest changing the if..if else ..else to a switch(config.type_.ToChecked()) { case .... with either a default that returns ParseKeyResult::kParseKeyFailed , or probably better, no default. I think gcc will warn when a switch doesn't handle all values of an enum in its case statements, so the code will be more future proof. Just a suggestion.
|
This comment has been minimized.
This comment has been minimized.
I understand your point. My main problem with a In my opinion, the current behavior of |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Aborts at the js-to-c++ layer make a lot of sense to me, where its easy to add type check calls in js just before calling C++ it should be very difficult to reach those abort arg checks. But since users are managing to get unexpected things to happen multiple layers down in the C++, then actual error returns make more sense. I don't feel strongly about it, but I notice that changing the fallback in the code in question to an error return, see #29904 (comment), prevented the abort. The user would still get an error, of course, but that was already possible for reasons of malformed input. That was exploratory code, I'm not suggesting using it as-is, but having the return be the default/final-else case would make the code more robust. |
This comment has been minimized.
This comment has been minimized.
It would be more robust in the sense that the process would not abort, but what kind of error should we throw here? Reaching this point is definitely a bug, and an error code that indicates otherwise will only be misleading. So the error should very clearly say: "Hey, this is a bug in node!". However, if we just throw the error, it might get lost, whereas aborting the process will send a very clear message. |
This comment has been minimized.
This comment has been minimized.
Landed in c64ed10 |
Fixes: nodejs#29904 PR-URL: nodejs#29913 Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
tniessen commentedOct 10, 2019
•
edited
If the underlying operation requires a private key,
isPublic
must be set tofalse
instead ofundefined
. (The latter means that both public and private keys are accepted.)Fixes: #29904
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes