Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
crypto: add SecureContext.clearOptions() method
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bnoordhuis committed Jan 2, 2012
1 parent 884f689 commit 6f8839d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/node_crypto.cc
Expand Up @@ -166,6 +166,7 @@ void SecureContext::Initialize(Handle<Object> target) {
NODE_SET_PROTOTYPE_METHOD(t, "addRootCerts", SecureContext::AddRootCerts);
NODE_SET_PROTOTYPE_METHOD(t, "setCiphers", SecureContext::SetCiphers);
NODE_SET_PROTOTYPE_METHOD(t, "setOptions", SecureContext::SetOptions);
NODE_SET_PROTOTYPE_METHOD(t, "clearOptions", SecureContext::ClearOptions);
NODE_SET_PROTOTYPE_METHOD(t, "setSessionIdContext",
SecureContext::SetSessionIdContext);
NODE_SET_PROTOTYPE_METHOD(t, "close", SecureContext::Close);
Expand Down Expand Up @@ -540,21 +541,23 @@ Handle<Value> SecureContext::SetCiphers(const Arguments& args) {
return True();
}

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

SecureContext *sc = ObjectWrap::Unwrap<SecureContext>(args.Holder());

if (args.Length() != 1 || !args[0]->IsUint32()) {
return ThrowException(Exception::TypeError(String::New("Bad parameter")));
#define X(name, fn) \
Handle<Value> name(const Arguments& args) { \
HandleScope scope; \
SecureContext *sc = ObjectWrap::Unwrap<SecureContext>(args.Holder()); \
if (args.Length() != 1 || !args[0]->IsInt32()) { \
return ThrowException( \
Exception::TypeError(String::New("Bad parameter"))); \
} \
fn(sc->ctx_, args[0]->Int32Value()); \
return True(); \
}

unsigned int opts = args[0]->Uint32Value();

SSL_CTX_set_options(sc->ctx_, opts);
// can't use templates, SSL_CTX_set_options and SSL_CTX_clear_options are macros
X(SecureContext::SetOptions, SSL_CTX_set_options)
X(SecureContext::ClearOptions, SSL_CTX_clear_options)

return True();
}
#undef X

Handle<Value> SecureContext::SetSessionIdContext(const Arguments& args) {
HandleScope scope;
Expand Down
1 change: 1 addition & 0 deletions src/node_crypto.h
Expand Up @@ -66,6 +66,7 @@ class SecureContext : ObjectWrap {
static v8::Handle<v8::Value> AddRootCerts(const v8::Arguments& args);
static v8::Handle<v8::Value> SetCiphers(const v8::Arguments& args);
static v8::Handle<v8::Value> SetOptions(const v8::Arguments& args);
static v8::Handle<v8::Value> ClearOptions(const v8::Arguments& args);
static v8::Handle<v8::Value> SetSessionIdContext(const v8::Arguments& args);
static v8::Handle<v8::Value> Close(const v8::Arguments& args);

Expand Down

0 comments on commit 6f8839d

Please sign in to comment.