@@ -391,17 +391,46 @@ void SecureContext::New(const FunctionCallbackInfo<Value>& args) {
391
391
}
392
392
393
393
394
+ int string_to_tls_protocol (const char * version_str) {
395
+ int version;
396
+
397
+ if (strcmp (version_str, " TLSv1.3" ) == 0 ) {
398
+ version = TLS1_3_VERSION;
399
+ } else if (strcmp (version_str, " TLSv1.2" ) == 0 ) {
400
+ version = TLS1_2_VERSION;
401
+ } else if (strcmp (version_str, " TLSv1.1" ) == 0 ) {
402
+ version = TLS1_1_VERSION;
403
+ } else if (strcmp (version_str, " TLSv1" ) == 0 ) {
404
+ version = TLS1_VERSION;
405
+ } else {
406
+ version = 0 ;
407
+ }
408
+ return version;
409
+ }
410
+
411
+
394
412
void SecureContext::Init (const FunctionCallbackInfo<Value>& args) {
395
413
SecureContext* sc;
396
414
ASSIGN_OR_RETURN_UNWRAP (&sc, args.Holder ());
397
415
Environment* env = sc->env ();
398
416
399
417
int min_version = 0 ;
400
418
int max_version = 0 ;
419
+
420
+ if (args[0 ]->IsString ()) {
421
+ const node::Utf8Value min (env->isolate (), args[0 ]);
422
+ min_version = string_to_tls_protocol (*min);
423
+ }
424
+
425
+ if (args[1 ]->IsString ()) {
426
+ const node::Utf8Value max (env->isolate (), args[1 ]);
427
+ max_version = string_to_tls_protocol (*max);
428
+ }
429
+
401
430
const SSL_METHOD* method = TLS_method ();
402
431
403
- if (args.Length () == 1 && args[0 ]->IsString ()) {
404
- const node::Utf8Value sslmethod (env->isolate (), args[0 ]);
432
+ if (args.Length () == 3 && args[2 ]->IsString ()) {
433
+ const node::Utf8Value sslmethod (env->isolate (), args[2 ]);
405
434
406
435
// Note that SSLv2 and SSLv3 are disallowed but SSLv23_method and friends
407
436
// are still accepted. They are OpenSSL's way of saying that all known
0 commit comments