Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
src: simplify ALPN code, remove indirection
  • Loading branch information
bnoordhuis committed Oct 3, 2022
commit 432ca36a2c81aaa468d824a22b3f944ca3dbb1f3
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