node/test/addons/openssl-get-ssl-ctx/binding.cc
Filip Skokan bbf51ad24c test: update tls/crypto behaviour expectations when using BoringSSL
Signed-off-by: Filip Skokan <panva.ip@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/63161
Reviewed-By: Tim Perry <pimterry@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
2026-05-08 19:27:18 +00:00

52 lines
1.7 KiB
C++

#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 a function available
// across OpenSSL-compatible TLS backends and checking context-owned state.
STACK_OF(SSL_CIPHER)* ciphers = SSL_CTX_get_ciphers(ctx);
if (ciphers == nullptr) {
isolate->ThrowException(v8::Exception::Error(
v8::String::NewFromUtf8(isolate, "SSL_CTX_get_ciphers 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)