33Date: Wed, 12 Feb 2020 15:08:04 -0800
44Subject: fix: use crypto impls for compat
55
6- BoringSSL does not export DSA_get0_q. This patch works around that problem
7- by using the implementations of those functions as found in the OpenSSL repo.
8- I plan to try and upstream a version of this.
6+ BoringSSL does not export DSA_get0_q, OPENSSL_secure_malloc, or
7+ OPENSSL_secure_clear_free.
8+
9+ This patch works around the DSA_get0_q problem by using the
10+ implementations of that function as found in the OpenSSL repo.
11+
12+ Node.js added the malloc/free incompatibilities in https://github.com/nodejs/node/pull/36729
13+ though they don't use secure heap at the moment. This makes it equivalent
14+ to swap these out with OPENSSL_malloc and OPENSSL_clear_free at present.
15+ We can revisit this once that happens and determine a more mutually
16+ compatible path forward either by upstreaming a shim to BoringSSL or
17+ adapting Node.js.
918
1019diff --git a/src/node_crypto.cc b/src/node_crypto.cc
11- index 79e781fb3e6ec63334c2c5d4b24d2a6049be79fc..c0baf86802a67f00830c81d325f448bcea7d4e40 100644
20+ index 79e781fb3e6ec63334c2c5d4b24d2a6049be79fc..c119b2314f18d1710bb3cbf1910c86ff994ec951 100644
1221--- a/src/node_crypto.cc
1322+++ b/src/node_crypto.cc
1423@@ -4574,7 +4574,7 @@ static unsigned int GetBytesOfRS(const ManagedEVPPKey& pkey) {
@@ -20,3 +29,21 @@ index 79e781fb3e6ec63334c2c5d4b24d2a6049be79fc..c0baf86802a67f00830c81d325f448bc
2029 } else if (base_id == EVP_PKEY_EC) {
2130 EC_KEY* ec_key = EVP_PKEY_get0_EC_KEY(pkey.get());
2231 const EC_GROUP* ec_group = EC_KEY_get0_group(ec_key);
32+ @@ -6949,7 +6949,7 @@ void SecureBuffer(const FunctionCallbackInfo<Value>& args) {
33+ CHECK(args[0]->IsUint32());
34+ Environment* env = Environment::GetCurrent(args);
35+ uint32_t len = args[0].As<Uint32>()->Value();
36+ - char* data = static_cast<char*>(OPENSSL_secure_malloc(len));
37+ + char* data = static_cast<char*>(OPENSSL_malloc(len));
38+ if (data == nullptr) {
39+ // There's no memory available for the allocation.
40+ // Return nothing.
41+ @@ -6961,7 +6961,7 @@ void SecureBuffer(const FunctionCallbackInfo<Value>& args) {
42+ data,
43+ len,
44+ [](void* data, size_t len, void* deleter_data) {
45+ - OPENSSL_secure_clear_free(data, len);
46+ + OPENSSL_clear_free(data, len);
47+ },
48+ data);
49+ Local<ArrayBuffer> buffer = ArrayBuffer::New(env->isolate(), store);
0 commit comments