Skip to content

Commit 15a32dd

Browse files
bnoordhuisFishrock123
authored andcommittedJul 6, 2016
build: export openssl symbols on windows
Export symbols from the bundled openssl for add-ons to link against. Fixes: nodejs/node-v0.x-archive#4051 PR-URL: #6274 Reviewed-By: James M Snell <[email protected]>
1 parent b829a49 commit 15a32dd

File tree

5 files changed

+152
-0
lines changed

5 files changed

+152
-0
lines changed
 

‎node.gyp

+56
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@
109109
}, {
110110
'node_target_type%': 'executable',
111111
}],
112+
[ 'OS=="win" and '
113+
'node_use_openssl=="true" and '
114+
'node_shared_openssl=="false"', {
115+
'use_openssl_def': 1,
116+
}, {
117+
'use_openssl_def': 0,
118+
}],
112119
],
113120
},
114121

@@ -358,6 +365,9 @@
358365
'-Wl,--no-whole-archive',
359366
],
360367
}],
368+
['use_openssl_def==1', {
369+
'sources': ['<(SHARED_INTERMEDIATE_DIR)/openssl.def'],
370+
}],
361371
],
362372
}],
363373
],
@@ -534,6 +544,52 @@
534544
}],
535545
],
536546
},
547+
{
548+
'target_name': 'mkssldef',
549+
'type': 'none',
550+
# TODO(bnoordhuis) Make all platforms export the same list of symbols.
551+
# Teach mkssldef.py to generate linker maps that UNIX linkers understand.
552+
'conditions': [
553+
[ 'use_openssl_def==1', {
554+
'variables': {
555+
'mkssldef_flags': [
556+
# Categories to export.
557+
'-CAES,BF,BIO,DES,DH,DSA,EC,ECDH,ECDSA,ENGINE,EVP,HMAC,MD4,MD5,'
558+
'NEXTPROTONEG,PSK,RC2,RC4,RSA,SHA,SHA0,SHA1,SHA256,SHA512,TLSEXT',
559+
# Defines.
560+
'-DWIN32',
561+
# Symbols to filter from the export list.
562+
'-X^DSO',
563+
'-X^_',
564+
'-X^private_',
565+
],
566+
},
567+
'conditions': [
568+
['openssl_fips!=""', {
569+
'variables': { 'mkssldef_flags': ['-DOPENSSL_FIPS'] },
570+
}],
571+
],
572+
'actions': [
573+
{
574+
'action_name': 'mkssldef',
575+
'inputs': [
576+
'deps/openssl/openssl/util/libeay.num',
577+
'deps/openssl/openssl/util/ssleay.num',
578+
],
579+
'outputs': ['<(SHARED_INTERMEDIATE_DIR)/openssl.def'],
580+
'action': [
581+
'python',
582+
'tools/mkssldef.py',
583+
'<@(mkssldef_flags)',
584+
'-o',
585+
'<@(_outputs)',
586+
'<@(_inputs)',
587+
],
588+
},
589+
],
590+
}],
591+
],
592+
},
537593
# generate ETW header and resource files
538594
{
539595
'target_name': 'node_etw',
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include "node.h"
2+
#include "../../../src/util.h"
3+
#include "../../../src/util-inl.h"
4+
5+
#include <assert.h>
6+
#include <openssl/rand.h>
7+
8+
namespace {
9+
10+
inline void RandomBytes(const v8::FunctionCallbackInfo<v8::Value>& info) {
11+
assert(info[0]->IsArrayBufferView());
12+
auto view = info[0].As<v8::ArrayBufferView>();
13+
auto byte_offset = view->ByteOffset();
14+
auto byte_length = view->ByteLength();
15+
assert(view->HasBuffer());
16+
auto buffer = view->Buffer();
17+
auto contents = buffer->GetContents();
18+
auto data = static_cast<unsigned char*>(contents.Data()) + byte_offset;
19+
assert(RAND_poll());
20+
auto rval = RAND_bytes(data, static_cast<int>(byte_length));
21+
info.GetReturnValue().Set(rval > 0);
22+
}
23+
24+
inline void Initialize(v8::Local<v8::Object> exports,
25+
v8::Local<v8::Value> module,
26+
v8::Local<v8::Context> context) {
27+
auto isolate = context->GetIsolate();
28+
auto key = v8::String::NewFromUtf8(isolate, "randomBytes");
29+
auto value = v8::FunctionTemplate::New(isolate, RandomBytes)->GetFunction();
30+
assert(exports->Set(context, key, value).IsJust());
31+
}
32+
33+
} // anonymous namespace
34+
35+
NODE_MODULE_CONTEXT_AWARE(binding, Initialize)
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
'targets': [
3+
{
4+
'target_name': 'binding',
5+
'sources': ['binding.cc'],
6+
'include_dirs': ['../../../deps/openssl/openssl/include'],
7+
},
8+
]
9+
}

‎test/addons/openssl-binding/test.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'use strict';
2+
3+
require('../../common');
4+
const assert = require('assert');
5+
const binding = require('./build/Release/binding');
6+
const bytes = new Uint8Array(1024);
7+
assert(binding.randomBytes(bytes));
8+
assert(bytes.reduce((v, a) => v + a) > 0);

‎tools/mkssldef.py

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env python
2+
3+
from __future__ import print_function
4+
import re
5+
import sys
6+
7+
categories = []
8+
defines = []
9+
excludes = []
10+
11+
if __name__ == '__main__':
12+
out = sys.stdout
13+
filenames = sys.argv[1:]
14+
15+
while filenames and filenames[0].startswith('-'):
16+
option = filenames.pop(0)
17+
if option == '-o': out = open(filenames.pop(0), 'w')
18+
elif option.startswith('-C'): categories += option[2:].split(',')
19+
elif option.startswith('-D'): defines += option[2:].split(',')
20+
elif option.startswith('-X'): excludes += option[2:].split(',')
21+
22+
excludes = map(re.compile, excludes)
23+
exported = []
24+
25+
for filename in filenames:
26+
for line in open(filename).readlines():
27+
name, _, meta, _ = re.split('\s+', line)
28+
if any(map(lambda p: p.match(name), excludes)): continue
29+
meta = meta.split(':')
30+
assert meta[0] in ('EXIST', 'NOEXIST')
31+
assert meta[2] in ('FUNCTION', 'VARIABLE')
32+
if meta[0] != 'EXIST': continue
33+
if meta[2] != 'FUNCTION': continue
34+
def satisfy(expr, rules):
35+
def test(expr):
36+
if expr.startswith('!'): return not expr[1:] in rules
37+
return expr == '' or expr in rules
38+
return all(map(test, expr.split(',')))
39+
if not satisfy(meta[1], defines): continue
40+
if not satisfy(meta[3], categories): continue
41+
exported.append(name)
42+
43+
print('EXPORTS', file=out)
44+
for name in sorted(exported): print(' ', name, file=out)

0 commit comments

Comments
 (0)
Please sign in to comment.