Skip to content

Commit 0a8e0a7

Browse files
mohd-akramjuanarbol
authored andcommitted
build: export more OpenSSL symbols on Windows
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>
1 parent cf7f3cb commit 0a8e0a7

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

node.gyp

+2-1
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,8 @@
900900
'-CAES,BF,BIO,DES,DH,DSA,EC,ECDH,ECDSA,ENGINE,EVP,HMAC,MD4,MD5,'
901901
'PSK,RC2,RC4,RSA,SHA,SHA0,SHA1,SHA256,SHA512,SOCK,STDIO,TLSEXT,'
902902
'UI,FP_API,TLS1_METHOD,TLS1_1_METHOD,TLS1_2_METHOD,SCRYPT,OCSP,'
903-
'NEXTPROTONEG,RMD160,CAST,DEPRECATEDIN_1_1_0,DEPRECATEDIN_1_2_0',
903+
'NEXTPROTONEG,RMD160,CAST,DEPRECATEDIN_1_1_0,DEPRECATEDIN_1_2_0,'
904+
'DEPRECATEDIN_3_0',
904905
# Defines.
905906
'-DWIN32',
906907
# Symbols to filter from the export list.

test/addons/openssl-binding/binding.cc

+24-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
#include <assert.h>
2+
#include <node.h>
3+
#include <openssl/md5.h>
14
#include <openssl/rand.h>
25
#include <openssl/ssl.h>
3-
#include <node.h>
4-
#include <assert.h>
56

67
namespace {
78

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

23+
inline void Hash(const v8::FunctionCallbackInfo<v8::Value>& info) {
24+
assert(info[0]->IsArrayBufferView());
25+
auto view = info[0].As<v8::ArrayBufferView>();
26+
auto byte_offset = view->ByteOffset();
27+
auto len = view->ByteLength();
28+
assert(view->HasBuffer());
29+
auto buffer = view->Buffer();
30+
auto contents = buffer->GetBackingStore();
31+
auto data = static_cast<unsigned char*>(contents->Data()) + byte_offset;
32+
unsigned char md[MD5_DIGEST_LENGTH];
33+
MD5_CTX c;
34+
auto rval = MD5_Init(&c) && MD5_Update(&c, data, len) && MD5_Final(md, &c);
35+
info.GetReturnValue().Set(rval > 0);
36+
}
37+
2238
inline void Initialize(v8::Local<v8::Object> exports,
2339
v8::Local<v8::Value> module,
2440
v8::Local<v8::Context> context) {
@@ -32,6 +48,12 @@ inline void Initialize(v8::Local<v8::Object> exports,
3248

3349
const SSL_METHOD* method = TLSv1_2_server_method();
3450
assert(method != nullptr);
51+
52+
key = v8::String::NewFromUtf8(isolate, "hash").ToLocalChecked();
53+
value = v8::FunctionTemplate::New(isolate, Hash)
54+
->GetFunction(context)
55+
.ToLocalChecked();
56+
assert(exports->Set(context, key, value).IsJust());
3557
}
3658

3759
} // anonymous namespace

test/addons/openssl-binding/test.js

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ const binding = require(`./build/${common.buildType}/binding`);
99
const bytes = new Uint8Array(1024);
1010
assert(binding.randomBytes(bytes));
1111
assert(bytes.reduce((v, a) => v + a) > 0);
12+
assert(binding.hash(bytes));

0 commit comments

Comments
 (0)