Skip to content

Commit 2a88dd3

Browse files
postwaitry
authored andcommitted
TLS: Add secureOptions flag
Also, secureOptions flag was added (and passed through) and allows the context to have all supported SSL_OP_* set via createCredentials. All SSL_OP_ flags (outside of ALL) have been added to constants.
1 parent 598792b commit 2a88dd3

5 files changed

Lines changed: 94 additions & 2 deletions

File tree

lib/crypto.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ try {
3636
}
3737

3838

39-
function Credentials(secureProtocol) {
39+
function Credentials(secureProtocol, flags) {
4040
if (!(this instanceof Credentials)) {
4141
return new Credentials(secureProtocol);
4242
}
@@ -53,14 +53,16 @@ function Credentials(secureProtocol) {
5353
this.context.init();
5454
}
5555

56+
if(flags) this.context.setOptions(flags);
57+
5658
}
5759

5860
exports.Credentials = Credentials;
5961

6062

6163
exports.createCredentials = function(options) {
6264
if (!options) options = {};
63-
var c = new Credentials(options.secureProtocol);
65+
var c = new Credentials(options.secureProtocol, options.secureOptions);
6466

6567
if (options.key) c.context.setKey(options.key);
6668

lib/tls.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,7 @@ function Server(/* [options], listener */) {
724724
cert: self.cert,
725725
ca: self.ca,
726726
secureProtocol: self.secureProtocol,
727+
secureOptions: self.secureOptions,
727728
crl: self.crl
728729
});
729730
//creds.context.setCiphers('RC4-SHA:AES128-SHA:AES256-SHA');
@@ -795,6 +796,8 @@ Server.prototype.setOptions = function(options) {
795796
if (options.ca) this.ca = options.ca;
796797
if (options.secureProtocol) this.secureProtocol = options.secureProtocol;
797798
if (options.crl) this.crl = options.crl;
799+
if (options.secureProtocol) this.secureProtocol = options.secureProtocol;
800+
if (options.secureOptions) this.secureOptions = options.secureOptions;
798801
};
799802

800803

src/node_constants.cc

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
# include <platform_win32_winsock.h>
3636
#endif
3737

38+
#ifdef HAVE_OPENSSL
39+
# include <openssl/ssl.h>
40+
#endif
41+
3842
namespace node {
3943

4044
using namespace v8;
@@ -838,6 +842,72 @@ void DefineConstants(Handle<Object> target) {
838842
#ifdef SIGUNUSED
839843
NODE_DEFINE_CONSTANT(target, SIGUNUSED);
840844
#endif
845+
846+
// OpenSSL SSL context options
847+
848+
#ifdef SSL_OP_NO_QUERY_MTU
849+
NODE_DEFINE_CONSTANT(target, SSL_OP_NO_QUERY_MTU);
850+
#endif
851+
852+
#ifdef SSL_OP_COOKIE_EXCHANGE
853+
NODE_DEFINE_CONSTANT(target, SSL_OP_COOKIE_EXCHANGE);
854+
#endif
855+
856+
#ifdef SSL_OP_NO_TICKET
857+
NODE_DEFINE_CONSTANT(target, SSL_OP_NO_TICKET);
858+
#endif
859+
860+
#ifdef SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION
861+
NODE_DEFINE_CONSTANT(target, SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION);
862+
#endif
863+
864+
#ifdef SSL_OP_SINGLE_ECDH_USE
865+
NODE_DEFINE_CONSTANT(target, SSL_OP_SINGLE_ECDH_USE);
866+
#endif
867+
868+
#ifdef SSL_OP_SINGLE_DH_USE
869+
NODE_DEFINE_CONSTANT(target, SSL_OP_SINGLE_DH_USE);
870+
#endif
871+
872+
#ifdef SSL_OP_EPHEMERAL_RSA
873+
NODE_DEFINE_CONSTANT(target, SSL_OP_EPHEMERAL_RSA);
874+
#endif
875+
876+
#ifdef SSL_OP_CIPHER_SERVER_PREFERENCE
877+
NODE_DEFINE_CONSTANT(target, SSL_OP_CIPHER_SERVER_PREFERENCE);
878+
#endif
879+
880+
#ifdef SSL_OP_TLS_ROLLBACK_BUG
881+
NODE_DEFINE_CONSTANT(target, SSL_OP_TLS_ROLLBACK_BUG);
882+
#endif
883+
884+
#ifdef SSL_OP_NO_SSLv2
885+
NODE_DEFINE_CONSTANT(target, SSL_OP_NO_SSLv2);
886+
#endif
887+
888+
#ifdef SSL_OP_NO_SSLv3
889+
NODE_DEFINE_CONSTANT(target, SSL_OP_NO_SSLv3);
890+
#endif
891+
892+
#ifdef SSL_OP_NO_TLSv1
893+
NODE_DEFINE_CONSTANT(target, SSL_OP_NO_TLSv1);
894+
#endif
895+
896+
#ifdef SSL_OP_PKCS1_CHECK_1
897+
NODE_DEFINE_CONSTANT(target, SSL_OP_PKCS1_CHECK_1);
898+
#endif
899+
900+
#ifdef SSL_OP_PKCS1_CHECK_2
901+
NODE_DEFINE_CONSTANT(target, SSL_OP_PKCS1_CHECK_2);
902+
#endif
903+
904+
#ifdef SSL_OP_NETSCAPE_CA_DN_BUG
905+
NODE_DEFINE_CONSTANT(target, SSL_OP_NETSCAPE_CA_DN_BUG);
906+
#endif
907+
908+
#ifdef SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG
909+
NODE_DEFINE_CONSTANT(target, SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG);
910+
#endif
841911
}
842912

843913
} // namespace node

src/node_crypto.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ void SecureContext::Initialize(Handle<Object> target) {
7373
NODE_SET_PROTOTYPE_METHOD(t, "addCRL", SecureContext::AddCRL);
7474
NODE_SET_PROTOTYPE_METHOD(t, "addRootCerts", SecureContext::AddRootCerts);
7575
NODE_SET_PROTOTYPE_METHOD(t, "setCiphers", SecureContext::SetCiphers);
76+
NODE_SET_PROTOTYPE_METHOD(t, "setOptions", SecureContext::SetOptions);
7677
NODE_SET_PROTOTYPE_METHOD(t, "close", SecureContext::Close);
7778

7879
target->Set(String::NewSymbol("SecureContext"), t->GetFunction());
@@ -426,6 +427,21 @@ Handle<Value> SecureContext::SetCiphers(const Arguments& args) {
426427
return True();
427428
}
428429

430+
Handle<Value> SecureContext::SetOptions(const Arguments& args) {
431+
HandleScope scope;
432+
433+
SecureContext *sc = ObjectWrap::Unwrap<SecureContext>(args.Holder());
434+
435+
if (args.Length() != 1 || !args[0]->IsUint32()) {
436+
return ThrowException(Exception::TypeError(String::New("Bad parameter")));
437+
}
438+
439+
unsigned int opts = args[0]->Uint32Value();
440+
441+
SSL_CTX_set_options(sc->ctx_, opts);
442+
443+
return True();
444+
}
429445

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

src/node_crypto.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class SecureContext : ObjectWrap {
5858
static v8::Handle<v8::Value> AddCRL(const v8::Arguments& args);
5959
static v8::Handle<v8::Value> AddRootCerts(const v8::Arguments& args);
6060
static v8::Handle<v8::Value> SetCiphers(const v8::Arguments& args);
61+
static v8::Handle<v8::Value> SetOptions(const v8::Arguments& args);
6162
static v8::Handle<v8::Value> Close(const v8::Arguments& args);
6263

6364
SecureContext() : ObjectWrap() {

0 commit comments

Comments
 (0)