forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinding.cc
More file actions
52 lines (42 loc) · 1.69 KB
/
binding.cc
File metadata and controls
52 lines (42 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <node.h>
#include <openssl/ssl.h>
namespace {
// Test: extract SSL_CTX* from a SecureContext object via
// node::crypto::GetSSLCtx.
void GetSSLCtx(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Isolate* isolate = args.GetIsolate();
v8::Local<v8::Context> context = isolate->GetCurrentContext();
SSL_CTX* ctx = node::crypto::GetSSLCtx(context, args[0]);
if (ctx == nullptr) {
isolate->ThrowException(v8::Exception::Error(
v8::String::NewFromUtf8(
isolate, "GetSSLCtx returned nullptr for a valid SecureContext")
.ToLocalChecked()));
return;
}
// Verify the pointer is a valid SSL_CTX by calling an OpenSSL function.
const SSL_METHOD* method = SSL_CTX_get_ssl_method(ctx);
if (method == nullptr) {
isolate->ThrowException(v8::Exception::Error(
v8::String::NewFromUtf8(isolate,
"SSL_CTX_get_ssl_method returned nullptr")
.ToLocalChecked()));
return;
}
args.GetReturnValue().Set(true);
}
// Test: passing a non-SecureContext value returns nullptr.
void GetSSLCtxInvalid(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Isolate* isolate = args.GetIsolate();
v8::Local<v8::Context> context = isolate->GetCurrentContext();
SSL_CTX* ctx = node::crypto::GetSSLCtx(context, args[0]);
args.GetReturnValue().Set(ctx == nullptr);
}
void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> module,
v8::Local<v8::Context> context) {
NODE_SET_METHOD(exports, "getSSLCtx", GetSSLCtx);
NODE_SET_METHOD(exports, "getSSLCtxInvalid", GetSSLCtxInvalid);
}
} // anonymous namespace
NODE_MODULE_CONTEXT_AWARE(NODE_GYP_MODULE_NAME, Initialize)