Skip to content

Commit 6f8839d

Browse files
committed
crypto: add SecureContext.clearOptions() method
SecureContext.setOptions() is backed by SSL_CTX_set_options() which, contrary to what the name suggests, is additive: it doesn't set options, it adds them to the already active options. Hence the need for SecureContext.clearOptions(), which lets you unset active options.
1 parent 884f689 commit 6f8839d

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

src/node_crypto.cc

+15-12
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ void SecureContext::Initialize(Handle<Object> target) {
166166
NODE_SET_PROTOTYPE_METHOD(t, "addRootCerts", SecureContext::AddRootCerts);
167167
NODE_SET_PROTOTYPE_METHOD(t, "setCiphers", SecureContext::SetCiphers);
168168
NODE_SET_PROTOTYPE_METHOD(t, "setOptions", SecureContext::SetOptions);
169+
NODE_SET_PROTOTYPE_METHOD(t, "clearOptions", SecureContext::ClearOptions);
169170
NODE_SET_PROTOTYPE_METHOD(t, "setSessionIdContext",
170171
SecureContext::SetSessionIdContext);
171172
NODE_SET_PROTOTYPE_METHOD(t, "close", SecureContext::Close);
@@ -540,21 +541,23 @@ Handle<Value> SecureContext::SetCiphers(const Arguments& args) {
540541
return True();
541542
}
542543

543-
Handle<Value> SecureContext::SetOptions(const Arguments& args) {
544-
HandleScope scope;
545-
546-
SecureContext *sc = ObjectWrap::Unwrap<SecureContext>(args.Holder());
547-
548-
if (args.Length() != 1 || !args[0]->IsUint32()) {
549-
return ThrowException(Exception::TypeError(String::New("Bad parameter")));
544+
#define X(name, fn) \
545+
Handle<Value> name(const Arguments& args) { \
546+
HandleScope scope; \
547+
SecureContext *sc = ObjectWrap::Unwrap<SecureContext>(args.Holder()); \
548+
if (args.Length() != 1 || !args[0]->IsInt32()) { \
549+
return ThrowException( \
550+
Exception::TypeError(String::New("Bad parameter"))); \
551+
} \
552+
fn(sc->ctx_, args[0]->Int32Value()); \
553+
return True(); \
550554
}
551555

552-
unsigned int opts = args[0]->Uint32Value();
553-
554-
SSL_CTX_set_options(sc->ctx_, opts);
556+
// can't use templates, SSL_CTX_set_options and SSL_CTX_clear_options are macros
557+
X(SecureContext::SetOptions, SSL_CTX_set_options)
558+
X(SecureContext::ClearOptions, SSL_CTX_clear_options)
555559

556-
return True();
557-
}
560+
#undef X
558561

559562
Handle<Value> SecureContext::SetSessionIdContext(const Arguments& args) {
560563
HandleScope scope;

src/node_crypto.h

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class SecureContext : ObjectWrap {
6666
static v8::Handle<v8::Value> AddRootCerts(const v8::Arguments& args);
6767
static v8::Handle<v8::Value> SetCiphers(const v8::Arguments& args);
6868
static v8::Handle<v8::Value> SetOptions(const v8::Arguments& args);
69+
static v8::Handle<v8::Value> ClearOptions(const v8::Arguments& args);
6970
static v8::Handle<v8::Value> SetSessionIdContext(const v8::Arguments& args);
7071
static v8::Handle<v8::Value> Close(const v8::Arguments& args);
7172

0 commit comments

Comments
 (0)