Skip to content

Commit

Permalink
src: simplify ALPN code, remove indirection
Browse files Browse the repository at this point in the history
PR-URL: #44875
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
  • Loading branch information
bnoordhuis authored and danielleadams committed Dec 30, 2022
1 parent c3a9179 commit 007f0bb
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 12 deletions.
6 changes: 0 additions & 6 deletions src/crypto/crypto_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<const uint8_t*>(alpn.data()),
alpn.length()) == 0;
}

MaybeLocal<Value> GetSSLOCSPResponse(
Environment* env,
SSL* ssl,
Expand Down
3 changes: 0 additions & 3 deletions src/crypto/crypto_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<v8::Value> GetSSLOCSPResponse(
Environment* env,
SSL* ssl,
Expand Down
7 changes: 4 additions & 3 deletions src/crypto/crypto_tls.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1529,17 +1529,18 @@ void TLSWrap::SetALPNProtocols(const FunctionCallbackInfo<Value>& 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<char> protos(args[0].As<ArrayBufferView>());
CHECK(SetALPN(w->ssl_, {protos.data(), protos.length()}));
ArrayBufferViewContents<uint8_t> protos(args[0].As<ArrayBufferView>());
CHECK_EQ(0, SSL_set_alpn_protos(ssl, protos.data(), protos.length()));
} else {
CHECK(
w->object()->SetPrivate(
env->context(),
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);
}
Expand Down

0 comments on commit 007f0bb

Please sign in to comment.