Skip to content

Commit

Permalink
build: export more OpenSSL symbols on Windows
Browse files Browse the repository at this point in the history
PR-URL: #45486
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
  • Loading branch information
mohd-akram authored and ruyadorno committed Jan 31, 2023
1 parent 729642f commit 8c6c433
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
3 changes: 2 additions & 1 deletion node.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,8 @@
'-CAES,BF,BIO,DES,DH,DSA,EC,ECDH,ECDSA,ENGINE,EVP,HMAC,MD4,MD5,'
'PSK,RC2,RC4,RSA,SHA,SHA0,SHA1,SHA256,SHA512,SOCK,STDIO,TLSEXT,'
'UI,FP_API,TLS1_METHOD,TLS1_1_METHOD,TLS1_2_METHOD,SCRYPT,OCSP,'
'NEXTPROTONEG,RMD160,CAST,DEPRECATEDIN_1_1_0,DEPRECATEDIN_1_2_0',
'NEXTPROTONEG,RMD160,CAST,DEPRECATEDIN_1_1_0,DEPRECATEDIN_1_2_0,'
'DEPRECATEDIN_3_0',
# Defines.
'-DWIN32',
# Symbols to filter from the export list.
Expand Down
26 changes: 24 additions & 2 deletions test/addons/openssl-binding/binding.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include <assert.h>
#include <node.h>
#include <openssl/md5.h>
#include <openssl/rand.h>
#include <openssl/ssl.h>
#include <node.h>
#include <assert.h>

namespace {

Expand All @@ -19,6 +20,21 @@ inline void RandomBytes(const v8::FunctionCallbackInfo<v8::Value>& info) {
info.GetReturnValue().Set(rval > 0);
}

inline void Hash(const v8::FunctionCallbackInfo<v8::Value>& info) {
assert(info[0]->IsArrayBufferView());
auto view = info[0].As<v8::ArrayBufferView>();
auto byte_offset = view->ByteOffset();
auto len = view->ByteLength();
assert(view->HasBuffer());
auto buffer = view->Buffer();
auto contents = buffer->GetBackingStore();
auto data = static_cast<unsigned char*>(contents->Data()) + byte_offset;
unsigned char md[MD5_DIGEST_LENGTH];
MD5_CTX c;
auto rval = MD5_Init(&c) && MD5_Update(&c, data, len) && MD5_Final(md, &c);
info.GetReturnValue().Set(rval > 0);
}

inline void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> module,
v8::Local<v8::Context> context) {
Expand All @@ -32,6 +48,12 @@ inline void Initialize(v8::Local<v8::Object> exports,

const SSL_METHOD* method = TLSv1_2_server_method();
assert(method != nullptr);

key = v8::String::NewFromUtf8(isolate, "hash").ToLocalChecked();
value = v8::FunctionTemplate::New(isolate, Hash)
->GetFunction(context)
.ToLocalChecked();
assert(exports->Set(context, key, value).IsJust());
}

} // anonymous namespace
Expand Down
1 change: 1 addition & 0 deletions test/addons/openssl-binding/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ const binding = require(`./build/${common.buildType}/binding`);
const bytes = new Uint8Array(1024);
assert(binding.randomBytes(bytes));
assert(bytes.reduce((v, a) => v + a) > 0);
assert(binding.hash(bytes));

0 comments on commit 8c6c433

Please sign in to comment.