@@ -69,10 +69,14 @@ const char* root_certs[] = {
69
69
NULL
70
70
};
71
71
72
+ bool SSL2_ENABLE = false ;
73
+ bool SSL3_ENABLE = false ;
74
+
72
75
namespace crypto {
73
76
74
77
using namespace v8 ;
75
78
79
+
76
80
// Forcibly clear OpenSSL's error stack on return. This stops stale errors
77
81
// from popping up later in the lifecycle of crypto operations where they
78
82
// would cause spurious failures. It's a rather blunt method, though.
@@ -234,6 +238,24 @@ Handle<Value> SecureContext::New(const Arguments& args) {
234
238
}
235
239
236
240
241
+ bool MaybeThrowSSL3 () {
242
+ if (!SSL3_ENABLE) {
243
+ ThrowException (Exception::Error (String::New (" SSLv3 is considered unsafe, see node --help" )));
244
+ return true ;
245
+ } else {
246
+ return false ;
247
+ }
248
+ }
249
+
250
+ bool MaybeThrowSSL2 () {
251
+ if (!SSL2_ENABLE) {
252
+ ThrowException (Exception::Error (String::New (" SSLv2 is considered unsafe, see node --help" )));
253
+ return true ;
254
+ } else {
255
+ return false ;
256
+ }
257
+ }
258
+
237
259
Handle <Value> SecureContext::Init (const Arguments& args) {
238
260
HandleScope scope;
239
261
@@ -246,28 +268,46 @@ Handle<Value> SecureContext::Init(const Arguments& args) {
246
268
247
269
if (strcmp (*sslmethod, " SSLv2_method" ) == 0 ) {
248
270
#ifndef OPENSSL_NO_SSL2
271
+ if (MaybeThrowSSL2 ()) return Undefined ();
249
272
method = SSLv2_method ();
250
273
#else
251
274
return ThrowException (Exception::Error (String::New (" SSLv2 methods disabled" )));
252
275
#endif
253
276
} else if (strcmp (*sslmethod, " SSLv2_server_method" ) == 0 ) {
254
277
#ifndef OPENSSL_NO_SSL2
278
+ if (MaybeThrowSSL2 ()) return Undefined ();
255
279
method = SSLv2_server_method ();
256
280
#else
257
281
return ThrowException (Exception::Error (String::New (" SSLv2 methods disabled" )));
258
282
#endif
259
283
} else if (strcmp (*sslmethod, " SSLv2_client_method" ) == 0 ) {
260
284
#ifndef OPENSSL_NO_SSL2
285
+ if (MaybeThrowSSL2 ()) return Undefined ();
261
286
method = SSLv2_client_method ();
262
287
#else
263
288
return ThrowException (Exception::Error (String::New (" SSLv2 methods disabled" )));
264
289
#endif
265
290
} else if (strcmp (*sslmethod, " SSLv3_method" ) == 0 ) {
291
+ #ifndef OPENSSL_NO_SSL3
292
+ if (MaybeThrowSSL3 ()) return Undefined ();
266
293
method = SSLv3_method ();
294
+ #else
295
+ return ThrowException (Exception::Error (String::New (" SSLv3 methods disabled" )));
296
+ #endif
267
297
} else if (strcmp (*sslmethod, " SSLv3_server_method" ) == 0 ) {
298
+ #ifndef OPENSSL_NO_SSL3
299
+ if (MaybeThrowSSL3 ()) return Undefined ();
268
300
method = SSLv3_server_method ();
301
+ #else
302
+ return ThrowException (Exception::Error (String::New (" SSLv3 methods disabled" )));
303
+ #endif
269
304
} else if (strcmp (*sslmethod, " SSLv3_client_method" ) == 0 ) {
305
+ #ifndef OPENSSL_NO_SSL3
306
+ if (MaybeThrowSSL3 ()) return Undefined ();
270
307
method = SSLv3_client_method ();
308
+ #else
309
+ return ThrowException (Exception::Error (String::New (" SSLv3 methods disabled" )));
310
+ #endif
271
311
} else if (strcmp (*sslmethod, " SSLv23_method" ) == 0 ) {
272
312
method = SSLv23_method ();
273
313
} else if (strcmp (*sslmethod, " SSLv23_server_method" ) == 0 ) {
@@ -295,6 +335,20 @@ Handle<Value> SecureContext::Init(const Arguments& args) {
295
335
SSL_CTX_sess_set_get_cb (sc->ctx_ , GetSessionCallback);
296
336
SSL_CTX_sess_set_new_cb (sc->ctx_ , NewSessionCallback);
297
337
338
+ int options = 0 ;
339
+
340
+ #ifndef OPENSSL_NO_SSL2
341
+ if (!SSL2_ENABLE)
342
+ options |= SSL_OP_NO_SSLv2;
343
+ #endif
344
+
345
+ #ifndef OPENSSL_NO_SSL3
346
+ if (!SSL3_ENABLE)
347
+ options |= SSL_OP_NO_SSLv3;
348
+ #endif
349
+
350
+ SSL_CTX_set_options (sc->ctx_ , options);
351
+
298
352
sc->ca_store_ = NULL ;
299
353
return True ();
300
354
}
0 commit comments