From e93d9c36029c4137f45352801926301c6d6162c6 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Mon, 3 Oct 2022 13:00:53 +0200 Subject: [PATCH] src: simplify ALPN code, remove indirection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/44875 Reviewed-By: James M Snell Reviewed-By: Tobias Nießen --- src/crypto/crypto_common.cc | 6 ------ src/crypto/crypto_common.h | 3 --- src/crypto/crypto_tls.cc | 7 ++++--- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/crypto/crypto_common.cc b/src/crypto/crypto_common.cc index 97777371265510..f070d3e8064b98 100644 --- a/src/crypto/crypto_common.cc +++ b/src/crypto/crypto_common.cc @@ -89,12 +89,6 @@ void LogSecret( keylog_cb(ssl.get(), line.c_str()); } -bool SetALPN(const SSLPointer& ssl, std::string_view alpn) { - return SSL_set_alpn_protos(ssl.get(), - reinterpret_cast(alpn.data()), - alpn.length()) == 0; -} - MaybeLocal GetSSLOCSPResponse( Environment* env, SSL* ssl, diff --git a/src/crypto/crypto_common.h b/src/crypto/crypto_common.h index 55401252cffc1f..cf26b82ba60590 100644 --- a/src/crypto/crypto_common.h +++ b/src/crypto/crypto_common.h @@ -33,9 +33,6 @@ void LogSecret( const unsigned char* secret, size_t secretlen); -// TODO(tniessen): use std::u8string_view when we switch to C++20. -bool SetALPN(const SSLPointer& ssl, std::string_view alpn); - v8::MaybeLocal GetSSLOCSPResponse( Environment* env, SSL* ssl, diff --git a/src/crypto/crypto_tls.cc b/src/crypto/crypto_tls.cc index 849b21f28dfda8..d653fb70e5d2d1 100644 --- a/src/crypto/crypto_tls.cc +++ b/src/crypto/crypto_tls.cc @@ -1529,9 +1529,10 @@ void TLSWrap::SetALPNProtocols(const FunctionCallbackInfo& args) { if (args.Length() < 1 || !Buffer::HasInstance(args[0])) return env->ThrowTypeError("Must give a Buffer as first argument"); + SSL* ssl = w->ssl_.get(); if (w->is_client()) { - ArrayBufferViewContents protos(args[0].As()); - CHECK(SetALPN(w->ssl_, {protos.data(), protos.length()})); + ArrayBufferViewContents protos(args[0].As()); + CHECK_EQ(0, SSL_set_alpn_protos(ssl, protos.data(), protos.length())); } else { CHECK( w->object()->SetPrivate( @@ -1539,7 +1540,7 @@ void TLSWrap::SetALPNProtocols(const FunctionCallbackInfo& args) { env->alpn_buffer_private_symbol(), args[0]).FromJust()); // Server should select ALPN protocol from list of advertised by client - SSL_CTX_set_alpn_select_cb(SSL_get_SSL_CTX(w->ssl_.get()), + SSL_CTX_set_alpn_select_cb(SSL_get_SSL_CTX(ssl), SelectALPNCallback, nullptr); }