diff --git a/src/node_crypto.cc b/src/node_crypto.cc index b95a1b8f3e24df..00f24cd9aa21e2 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -572,73 +572,65 @@ void SecureContext::Init(const FunctionCallbackInfo& args) { // are still accepted. They are OpenSSL's way of saying that all known // protocols below TLS 1.3 are supported unless explicitly disabled (which // we do below for SSLv2 and SSLv3.) - if (strcmp(*sslmethod, "SSLv2_method") == 0) { + if (sslmethod == "SSLv2_method" || + sslmethod == "SSLv2_server_method" || + sslmethod == "SSLv2_client_method") { THROW_ERR_TLS_INVALID_PROTOCOL_METHOD(env, "SSLv2 methods disabled"); return; - } else if (strcmp(*sslmethod, "SSLv2_server_method") == 0) { - THROW_ERR_TLS_INVALID_PROTOCOL_METHOD(env, "SSLv2 methods disabled"); - return; - } else if (strcmp(*sslmethod, "SSLv2_client_method") == 0) { - THROW_ERR_TLS_INVALID_PROTOCOL_METHOD(env, "SSLv2 methods disabled"); - return; - } else if (strcmp(*sslmethod, "SSLv3_method") == 0) { - THROW_ERR_TLS_INVALID_PROTOCOL_METHOD(env, "SSLv3 methods disabled"); - return; - } else if (strcmp(*sslmethod, "SSLv3_server_method") == 0) { - THROW_ERR_TLS_INVALID_PROTOCOL_METHOD(env, "SSLv3 methods disabled"); - return; - } else if (strcmp(*sslmethod, "SSLv3_client_method") == 0) { + } else if (sslmethod == "SSLv3_method" || + sslmethod == "SSLv3_server_method" || + sslmethod == "SSLv3_client_method") { THROW_ERR_TLS_INVALID_PROTOCOL_METHOD(env, "SSLv3 methods disabled"); return; - } else if (strcmp(*sslmethod, "SSLv23_method") == 0) { + } else if (sslmethod == "SSLv23_method") { max_version = TLS1_2_VERSION; - } else if (strcmp(*sslmethod, "SSLv23_server_method") == 0) { + } else if (sslmethod == "SSLv23_server_method") { max_version = TLS1_2_VERSION; method = TLS_server_method(); - } else if (strcmp(*sslmethod, "SSLv23_client_method") == 0) { + } else if (sslmethod == "SSLv23_client_method") { max_version = TLS1_2_VERSION; method = TLS_client_method(); - } else if (strcmp(*sslmethod, "TLS_method") == 0) { + } else if (sslmethod == "TLS_method") { min_version = 0; max_version = MAX_SUPPORTED_VERSION; - } else if (strcmp(*sslmethod, "TLS_server_method") == 0) { + } else if (sslmethod == "TLS_server_method") { min_version = 0; max_version = MAX_SUPPORTED_VERSION; method = TLS_server_method(); - } else if (strcmp(*sslmethod, "TLS_client_method") == 0) { + } else if (sslmethod == "TLS_client_method") { min_version = 0; max_version = MAX_SUPPORTED_VERSION; method = TLS_client_method(); - } else if (strcmp(*sslmethod, "TLSv1_method") == 0) { + } else if (sslmethod == "TLSv1_method") { min_version = TLS1_VERSION; max_version = TLS1_VERSION; - } else if (strcmp(*sslmethod, "TLSv1_server_method") == 0) { + } else if (sslmethod == "TLSv1_server_method") { min_version = TLS1_VERSION; max_version = TLS1_VERSION; method = TLS_server_method(); - } else if (strcmp(*sslmethod, "TLSv1_client_method") == 0) { + } else if (sslmethod == "TLSv1_client_method") { min_version = TLS1_VERSION; max_version = TLS1_VERSION; method = TLS_client_method(); - } else if (strcmp(*sslmethod, "TLSv1_1_method") == 0) { + } else if (sslmethod == "TLSv1_1_method") { min_version = TLS1_1_VERSION; max_version = TLS1_1_VERSION; - } else if (strcmp(*sslmethod, "TLSv1_1_server_method") == 0) { + } else if (sslmethod == "TLSv1_1_server_method") { min_version = TLS1_1_VERSION; max_version = TLS1_1_VERSION; method = TLS_server_method(); - } else if (strcmp(*sslmethod, "TLSv1_1_client_method") == 0) { + } else if (sslmethod == "TLSv1_1_client_method") { min_version = TLS1_1_VERSION; max_version = TLS1_1_VERSION; method = TLS_client_method(); - } else if (strcmp(*sslmethod, "TLSv1_2_method") == 0) { + } else if (sslmethod == "TLSv1_2_method") { min_version = TLS1_2_VERSION; max_version = TLS1_2_VERSION; - } else if (strcmp(*sslmethod, "TLSv1_2_server_method") == 0) { + } else if (sslmethod == "TLSv1_2_server_method") { min_version = TLS1_2_VERSION; max_version = TLS1_2_VERSION; method = TLS_server_method(); - } else if (strcmp(*sslmethod, "TLSv1_2_client_method") == 0) { + } else if (sslmethod == "TLSv1_2_client_method") { min_version = TLS1_2_VERSION; max_version = TLS1_2_VERSION; method = TLS_client_method(); diff --git a/src/util.h b/src/util.h index dc0d97f1df7dd2..a50cc1cf23b8a3 100644 --- a/src/util.h +++ b/src/util.h @@ -486,6 +486,10 @@ class Utf8Value : public MaybeStackBuffer { explicit Utf8Value(v8::Isolate* isolate, v8::Local value); inline std::string ToString() const { return std::string(out(), length()); } + + inline bool operator==(const char* a) const { + return strcmp(out(), a) == 0; + } }; class TwoByteValue : public MaybeStackBuffer {