Skip to content

Commit 00688b6

Browse files
sam-githubBethGriggs
authored andcommittedApr 15, 2019
tls: add code for ERR_TLS_INVALID_PROTOCOL_METHOD
Add an error code property to invalid `secureProtocol` method exceptions. Backport-PR-URL: #26951 PR-URL: #24729 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent bd07ad2 commit 00688b6

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed
 

‎doc/api/errors.md

+6
Original file line numberDiff line numberDiff line change
@@ -1714,6 +1714,12 @@ recommended to use 2048 bits or larger for stronger security.
17141714
A TLS/SSL handshake timed out. In this case, the server must also abort the
17151715
connection.
17161716

1717+
<a id="ERR_TLS_INVALID_PROTOCOL_METHOD"></a>
1718+
### ERR_TLS_INVALID_PROTOCOL_METHOD
1719+
1720+
The specified `secureProtocol` method is invalid. It is either unknown, or
1721+
disabled because it is insecure.
1722+
17171723
<a id="ERR_TLS_INVALID_PROTOCOL_VERSION"></a>
17181724
### ERR_TLS_INVALID_PROTOCOL_VERSION
17191725

‎src/node_crypto.cc

+16-7
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ static const int X509_NAME_FLAGS = ASN1_STRFLGS_ESC_CTRL
6565
namespace node {
6666
namespace crypto {
6767

68+
using node::THROW_ERR_TLS_INVALID_PROTOCOL_METHOD;
69+
6870
using v8::Array;
6971
using v8::ArrayBufferView;
7072
using v8::Boolean;
@@ -424,17 +426,23 @@ void SecureContext::Init(const FunctionCallbackInfo<Value>& args) {
424426
// protocols are supported unless explicitly disabled (which we do below
425427
// for SSLv2 and SSLv3.)
426428
if (strcmp(*sslmethod, "SSLv2_method") == 0) {
427-
return env->ThrowError("SSLv2 methods disabled");
429+
THROW_ERR_TLS_INVALID_PROTOCOL_METHOD(env, "SSLv2 methods disabled");
430+
return;
428431
} else if (strcmp(*sslmethod, "SSLv2_server_method") == 0) {
429-
return env->ThrowError("SSLv2 methods disabled");
432+
THROW_ERR_TLS_INVALID_PROTOCOL_METHOD(env, "SSLv2 methods disabled");
433+
return;
430434
} else if (strcmp(*sslmethod, "SSLv2_client_method") == 0) {
431-
return env->ThrowError("SSLv2 methods disabled");
435+
THROW_ERR_TLS_INVALID_PROTOCOL_METHOD(env, "SSLv2 methods disabled");
436+
return;
432437
} else if (strcmp(*sslmethod, "SSLv3_method") == 0) {
433-
return env->ThrowError("SSLv3 methods disabled");
438+
THROW_ERR_TLS_INVALID_PROTOCOL_METHOD(env, "SSLv3 methods disabled");
439+
return;
434440
} else if (strcmp(*sslmethod, "SSLv3_server_method") == 0) {
435-
return env->ThrowError("SSLv3 methods disabled");
441+
THROW_ERR_TLS_INVALID_PROTOCOL_METHOD(env, "SSLv3 methods disabled");
442+
return;
436443
} else if (strcmp(*sslmethod, "SSLv3_client_method") == 0) {
437-
return env->ThrowError("SSLv3 methods disabled");
444+
THROW_ERR_TLS_INVALID_PROTOCOL_METHOD(env, "SSLv3 methods disabled");
445+
return;
438446
} else if (strcmp(*sslmethod, "SSLv23_method") == 0) {
439447
// noop
440448
} else if (strcmp(*sslmethod, "SSLv23_server_method") == 0) {
@@ -478,7 +486,8 @@ void SecureContext::Init(const FunctionCallbackInfo<Value>& args) {
478486
max_version = TLS1_2_VERSION;
479487
method = TLS_client_method();
480488
} else {
481-
return env->ThrowError("Unknown method");
489+
THROW_ERR_TLS_INVALID_PROTOCOL_METHOD(env, "Unknown method");
490+
return;
482491
}
483492
}
484493

‎src/node_errors.h

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ void FatalException(v8::Isolate* isolate,
5555
V(ERR_SCRIPT_EXECUTION_INTERRUPTED, Error) \
5656
V(ERR_SCRIPT_EXECUTION_TIMEOUT, Error) \
5757
V(ERR_STRING_TOO_LONG, Error) \
58+
V(ERR_TLS_INVALID_PROTOCOL_METHOD, TypeError) \
5859
V(ERR_TRANSFERRING_EXTERNALIZED_SHAREDARRAYBUFFER, TypeError) \
5960

6061
#define V(code, type) \

0 commit comments

Comments
 (0)
Please sign in to comment.