Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: export more OpenSSL symbols on Windows #45486

Merged
merged 2 commits into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion node.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,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
22 changes: 22 additions & 0 deletions test/addons/openssl-binding/binding.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <openssl/md5.h>
#include <openssl/rand.h>
#include <openssl/ssl.h>
#include <node.h>
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));