summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTobias Nießen <tniessen@tnie.de>2018-12-25 13:13:52 +0100
committerAnna Henningsen <anna@addaleax.net>2019-01-08 00:20:09 +0100
commitae2d1f0e05449221ee770a393e5c967b359d9b1b (patch)
tree5d43c4d7b0509e47ca51ad7e6cfb4d3192c29f61 /src
parent27a03b84c42a021c94649b3f601800b7502a9c15 (diff)
downloadandroid-node-v8-ae2d1f0e05449221ee770a393e5c967b359d9b1b.tar.gz
android-node-v8-ae2d1f0e05449221ee770a393e5c967b359d9b1b.tar.bz2
android-node-v8-ae2d1f0e05449221ee770a393e5c967b359d9b1b.zip
crypto: always accept private keys as public keys
Some APIs already accept private keys instead of public keys. This changes all relevant crypto APIs to do so. PR-URL: https://github.com/nodejs/node/pull/25217 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/node_crypto.cc28
1 files changed, 2 insertions, 26 deletions
diff --git a/src/node_crypto.cc b/src/node_crypto.cc
index ab35568888..ff3713eeec 100644
--- a/src/node_crypto.cc
+++ b/src/node_crypto.cc
@@ -3012,30 +3012,6 @@ static PublicKeyEncodingConfig GetPublicKeyEncodingFromJs(
return result;
}
-static ManagedEVPPKey GetPublicKeyFromJs(
- const FunctionCallbackInfo<Value>& args,
- unsigned int* offset,
- bool allow_key_object) {
- if (args[*offset]->IsString() || Buffer::HasInstance(args[*offset])) {
- Environment* env = Environment::GetCurrent(args);
- ByteSource key = ByteSource::FromStringOrBuffer(env, args[(*offset)++]);
- PublicKeyEncodingConfig config =
- GetPublicKeyEncodingFromJs(args, offset, kKeyContextInput);
- EVPKeyPointer pkey;
- ParsePublicKey(&pkey, config, key.get(), key.size());
- if (!pkey)
- ThrowCryptoError(env, ERR_get_error(), "Failed to read public key");
- return ManagedEVPPKey(pkey.release());
- } else {
- CHECK(args[*offset]->IsObject() && allow_key_object);
- KeyObject* key;
- ASSIGN_OR_RETURN_UNWRAP(&key, args[*offset].As<Object>(), ManagedEVPPKey());
- CHECK_EQ(key->GetKeyType(), kKeyTypePublic);
- (*offset) += 3;
- return key->GetAsymmetricKey();
- }
-}
-
static NonCopyableMaybe<PrivateKeyEncodingConfig> GetPrivateKeyEncodingFromJs(
const FunctionCallbackInfo<Value>& args,
unsigned int* offset,
@@ -3397,7 +3373,7 @@ void KeyObject::Init(const FunctionCallbackInfo<Value>& args) {
CHECK_EQ(args.Length(), 3);
offset = 0;
- pkey = GetPublicKeyFromJs(args, &offset, false);
+ pkey = GetPublicOrPrivateKeyFromJs(args, &offset, false);
if (!pkey)
return;
key->InitPublic(pkey);
@@ -4679,7 +4655,7 @@ void Verify::VerifyFinal(const FunctionCallbackInfo<Value>& args) {
ASSIGN_OR_RETURN_UNWRAP(&verify, args.Holder());
unsigned int offset = 0;
- ManagedEVPPKey pkey = GetPublicKeyFromJs(args, &offset, true);
+ ManagedEVPPKey pkey = GetPublicOrPrivateKeyFromJs(args, &offset, true);
char* hbuf = Buffer::Data(args[offset]);
ssize_t hlen = Buffer::Length(args[offset]);