diff --git a/lib/crypto.js b/lib/crypto.js index d1c9eb5d2ec..2da66ad8f3f 100644 --- a/lib/crypto.js +++ b/lib/crypto.js @@ -37,6 +37,8 @@ try { var crypto = false; } +var constants = process.binding('constants'); + var stream = require('stream'); var util = require('util'); @@ -57,6 +59,8 @@ function toBuf(str, encoding) { var assert = require('assert'); var StringDecoder = require('string_decoder').StringDecoder; +var CONTEXT_DEFAULT_OPTIONS = undefined; + function Credentials(secureProtocol, flags, context) { if (!(this instanceof Credentials)) { return new Credentials(secureProtocol, flags, context); @@ -78,7 +82,20 @@ function Credentials(secureProtocol, flags, context) { } } - if (flags) this.context.setOptions(flags); + if (CONTEXT_DEFAULT_OPTIONS === undefined) { + CONTEXT_DEFAULT_OPTIONS = 0; + + if (!binding.SSL3_ENABLE) + CONTEXT_DEFAULT_OPTIONS |= constants.SSL_OP_NO_SSLv3; + + if (!binding.SSL2_ENABLE) + CONTEXT_DEFAULT_OPTIONS |= constants.SSL_OP_NO_SSLv2; + } + + if (flags === undefined) + flags = CONTEXT_DEFAULT_OPTIONS; + + this.context.setOptions(flags); } exports.Credentials = Credentials; diff --git a/src/node_crypto.cc b/src/node_crypto.cc index fbcdf865129..4bcb954cab8 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -335,16 +335,6 @@ Handle SecureContext::Init(const Arguments& args) { SSL_CTX_sess_set_get_cb(sc->ctx_, GetSessionCallback); SSL_CTX_sess_set_new_cb(sc->ctx_, NewSessionCallback); - int options = 0; - - if (!SSL2_ENABLE) - options |= SSL_OP_NO_SSLv2; - - if (!SSL3_ENABLE) - options |= SSL_OP_NO_SSLv3; - - SSL_CTX_set_options(sc->ctx_, options); - sc->ca_store_ = NULL; return True(); } @@ -705,7 +695,7 @@ Handle SecureContext::SetOptions(const Arguments& args) { SecureContext *sc = ObjectWrap::Unwrap(args.Holder()); - if (args.Length() != 1 || !args[0]->IntegerValue()) { + if (args.Length() != 1 && !args[0]->IsUint32()) { return ThrowException(Exception::TypeError(String::New("Bad parameter"))); } @@ -4295,6 +4285,9 @@ void InitCrypto(Handle target) { name_symbol = NODE_PSYMBOL("name"); version_symbol = NODE_PSYMBOL("version"); ext_key_usage_symbol = NODE_PSYMBOL("ext_key_usage"); + + NODE_DEFINE_CONSTANT(target, SSL3_ENABLE); + NODE_DEFINE_CONSTANT(target, SSL2_ENABLE); } } // namespace crypto