Skip to content

Commit 1cfc455

Browse files
committed
tls: zero SSL_CTX freelist for a singleUse socket
When connecting to server with `keepAlive` turned off - make sure that the read/write buffers won't be kept in a single use SSL_CTX instance after the socket will be destroyed. Fix: #1522 PR-URL: #1529 Reviewed-By: Shigeki Ohtsu <[email protected]>
1 parent 74060bb commit 1cfc455

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed

lib/_tls_common.js

+4
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ exports.createSecureContext = function createSecureContext(options, context) {
133133
}
134134
}
135135

136+
// Do not keep read/write buffers in free list
137+
if (options.singleUse)
138+
c.context.setFreeListLength(0);
139+
136140
return c;
137141
};
138142

lib/_tls_wrap.js

+2
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,8 @@ exports.connect = function(/* [port, host], options, cb */) {
862862
};
863863

864864
options = util._extend(defaults, options || {});
865+
if (!options.keepAlive)
866+
options.singleUse = true;
865867

866868
assert(typeof options.checkServerIdentity === 'function');
867869

src/node_crypto.cc

+8
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ void SecureContext::Initialize(Environment* env, Handle<Object> target) {
265265
env->SetProtoMethod(t, "loadPKCS12", SecureContext::LoadPKCS12);
266266
env->SetProtoMethod(t, "getTicketKeys", SecureContext::GetTicketKeys);
267267
env->SetProtoMethod(t, "setTicketKeys", SecureContext::SetTicketKeys);
268+
env->SetProtoMethod(t, "setFreeListLength", SecureContext::SetFreeListLength);
268269
env->SetProtoMethod(t, "getCertificate", SecureContext::GetCertificate<true>);
269270
env->SetProtoMethod(t, "getIssuer", SecureContext::GetCertificate<false>);
270271

@@ -933,6 +934,13 @@ void SecureContext::SetTicketKeys(const FunctionCallbackInfo<Value>& args) {
933934
}
934935

935936

937+
void SecureContext::SetFreeListLength(const FunctionCallbackInfo<Value>& args) {
938+
SecureContext* wrap = Unwrap<SecureContext>(args.Holder());
939+
940+
wrap->ctx_->freelist_max_len = args[0]->Int32Value();
941+
}
942+
943+
936944
void SecureContext::CtxGetter(Local<String> property,
937945
const PropertyCallbackInfo<Value>& info) {
938946
HandleScope scope(info.GetIsolate());

src/node_crypto.h

+2
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ class SecureContext : public BaseObject {
8585
static void LoadPKCS12(const v8::FunctionCallbackInfo<v8::Value>& args);
8686
static void GetTicketKeys(const v8::FunctionCallbackInfo<v8::Value>& args);
8787
static void SetTicketKeys(const v8::FunctionCallbackInfo<v8::Value>& args);
88+
static void SetFreeListLength(
89+
const v8::FunctionCallbackInfo<v8::Value>& args);
8890
static void CtxGetter(v8::Local<v8::String> property,
8991
const v8::PropertyCallbackInfo<v8::Value>& info);
9092

0 commit comments

Comments
 (0)