Skip to content

Commit 84a1b18

Browse files
committed
tls: add code for ERR_TLS_INVALID_PROTOCOL_METHOD
Add an error code property to invalid `secureProtocol` method exceptions. PR-URL: nodejs#24729 Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent a640834 commit 84a1b18

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

doc/api/errors.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1724,6 +1724,12 @@ recommended to use 2048 bits or larger for stronger security.
17241724
A TLS/SSL handshake timed out. In this case, the server must also abort the
17251725
connection.
17261726

1727+
<a id="ERR_TLS_INVALID_PROTOCOL_METHOD"></a>
1728+
### ERR_TLS_INVALID_PROTOCOL_METHOD
1729+
1730+
The specified `secureProtocol` method is invalid. It is either unknown, or
1731+
disabled because it is insecure.
1732+
17271733
<a id="ERR_TLS_INVALID_PROTOCOL_VERSION"></a>
17281734
### ERR_TLS_INVALID_PROTOCOL_VERSION
17291735

src/node_crypto.cc

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ static const int X509_NAME_FLAGS = ASN1_STRFLGS_ESC_CTRL
5454
namespace node {
5555
namespace crypto {
5656

57+
using node::THROW_ERR_TLS_INVALID_PROTOCOL_METHOD;
58+
5759
using v8::Array;
5860
using v8::ArrayBufferView;
5961
using v8::Boolean;
@@ -413,17 +415,23 @@ void SecureContext::Init(const FunctionCallbackInfo<Value>& args) {
413415
// protocols are supported unless explicitly disabled (which we do below
414416
// for SSLv2 and SSLv3.)
415417
if (strcmp(*sslmethod, "SSLv2_method") == 0) {
416-
return env->ThrowError("SSLv2 methods disabled");
418+
THROW_ERR_TLS_INVALID_PROTOCOL_METHOD(env, "SSLv2 methods disabled");
419+
return;
417420
} else if (strcmp(*sslmethod, "SSLv2_server_method") == 0) {
418-
return env->ThrowError("SSLv2 methods disabled");
421+
THROW_ERR_TLS_INVALID_PROTOCOL_METHOD(env, "SSLv2 methods disabled");
422+
return;
419423
} else if (strcmp(*sslmethod, "SSLv2_client_method") == 0) {
420-
return env->ThrowError("SSLv2 methods disabled");
424+
THROW_ERR_TLS_INVALID_PROTOCOL_METHOD(env, "SSLv2 methods disabled");
425+
return;
421426
} else if (strcmp(*sslmethod, "SSLv3_method") == 0) {
422-
return env->ThrowError("SSLv3 methods disabled");
427+
THROW_ERR_TLS_INVALID_PROTOCOL_METHOD(env, "SSLv3 methods disabled");
428+
return;
423429
} else if (strcmp(*sslmethod, "SSLv3_server_method") == 0) {
424-
return env->ThrowError("SSLv3 methods disabled");
430+
THROW_ERR_TLS_INVALID_PROTOCOL_METHOD(env, "SSLv3 methods disabled");
431+
return;
425432
} else if (strcmp(*sslmethod, "SSLv3_client_method") == 0) {
426-
return env->ThrowError("SSLv3 methods disabled");
433+
THROW_ERR_TLS_INVALID_PROTOCOL_METHOD(env, "SSLv3 methods disabled");
434+
return;
427435
} else if (strcmp(*sslmethod, "SSLv23_method") == 0) {
428436
// noop
429437
} else if (strcmp(*sslmethod, "SSLv23_server_method") == 0) {
@@ -467,7 +475,8 @@ void SecureContext::Init(const FunctionCallbackInfo<Value>& args) {
467475
max_version = TLS1_2_VERSION;
468476
method = TLS_client_method();
469477
} else {
470-
return env->ThrowError("Unknown method");
478+
THROW_ERR_TLS_INVALID_PROTOCOL_METHOD(env, "Unknown method");
479+
return;
471480
}
472481
}
473482

src/node_errors.h

Lines changed: 1 addition & 0 deletions
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)