From 17a697c794f2525c9789fd92c2206a1b634cf473 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Mon, 26 Aug 2019 12:18:50 -0700 Subject: [PATCH] crypto: don't expose openssl internals MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/29325 Reviewed-By: Ujjwal Sharma Reviewed-By: James M Snell Reviewed-By: Ben Noordhuis Reviewed-By: Tobias Nießen --- src/node_crypto.cc | 15 ++++++++++----- src/node_crypto.h | 2 +- src/node_errors.h | 2 ++ 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 5634d8b1dc5..65683b70d84 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -5203,7 +5203,7 @@ template & args) { const node::Utf8Value oaep_str(env->isolate(), args[offset + 2]); const char* oaep_hash = args[offset + 2]->IsString() ? *oaep_str : nullptr; + const EVP_MD* digest = nullptr; + if (oaep_hash != nullptr) { + digest = EVP_get_digestbyname(oaep_hash); + if (digest == nullptr) + return THROW_ERR_OSSL_EVP_INVALID_DIGEST(env); + } AllocatedBuffer out; @@ -5268,7 +5273,7 @@ void PublicKeyCipher::Cipher(const FunctionCallbackInfo& args) { env, pkey, padding, - oaep_hash, + digest, buf.data(), buf.length(), &out); diff --git a/src/node_crypto.h b/src/node_crypto.h index a121c822959..99e6c481177 100644 --- a/src/node_crypto.h +++ b/src/node_crypto.h @@ -713,7 +713,7 @@ class PublicKeyCipher { static bool Cipher(Environment* env, const ManagedEVPPKey& pkey, int padding, - const char* oaep_hash, + const EVP_MD* digest, const unsigned char* data, int len, AllocatedBuffer* out); diff --git a/src/node_errors.h b/src/node_errors.h index 939f93a4899..261c6077bb8 100644 --- a/src/node_errors.h +++ b/src/node_errors.h @@ -42,6 +42,7 @@ void PrintErrorString(const char* format, ...); V(ERR_CONSTRUCT_CALL_REQUIRED, TypeError) \ V(ERR_CONSTRUCT_CALL_INVALID, TypeError) \ V(ERR_INVALID_ARG_VALUE, TypeError) \ + V(ERR_OSSL_EVP_INVALID_DIGEST, Error) \ V(ERR_INVALID_ARG_TYPE, TypeError) \ V(ERR_INVALID_MODULE_SPECIFIER, TypeError) \ V(ERR_INVALID_PACKAGE_CONFIG, SyntaxError) \ @@ -89,6 +90,7 @@ void PrintErrorString(const char* format, ...); V(ERR_CONSTRUCT_CALL_REQUIRED, "Cannot call constructor without `new`") \ V(ERR_INVALID_TRANSFER_OBJECT, "Found invalid object in transferList") \ V(ERR_MEMORY_ALLOCATION_FAILED, "Failed to allocate memory") \ + V(ERR_OSSL_EVP_INVALID_DIGEST, "Invalid digest used") \ V(ERR_MISSING_MESSAGE_PORT_IN_TRANSFER_LIST, \ "MessagePort was found in message but not listed in transferList") \ V(ERR_MISSING_PLATFORM_FOR_WORKER, \