Skip to content

Commit

Permalink
Set the SNI value from the TLS inspector server name if it isn't avai…
Browse files Browse the repository at this point in the history
…lable on the connection/socket.

Signed-off-by: Marc Barry <4965634+marc-barry@users.noreply.github.com>
  • Loading branch information
marc-barry committed May 12, 2024
1 parent 4b0495b commit 4496677
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions source/extensions/filters/common/ext_authz/check_request_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,15 @@ void CheckRequestUtils::createHttpCheck(
cb->decodingBuffer(), headers, max_request_bytes, pack_as_bytes,
encode_raw_headers, request_header_matchers);

if (include_tls_session && cb->connection()->ssl() != nullptr) {
setTLSSession(*attrs->mutable_tls_session(), cb->connection()->ssl());
if (include_tls_session) {
// Try to get the SNI from the TLS session. If not available there then try the
// data from the TLS inspector (i.e. the server name)
if (cb->connection()->ssl() != nullptr) {
setTLSSession(*attrs->mutable_tls_session(), cb->connection()->ssl());
} else if (!cb->connection()->requestedServerName().empty()) {
std::string sni{b->connection()->requestedServerName()};
attrs->mutable_tls_session()->set_sni(sni);
}
}
(*attrs->mutable_destination()->mutable_labels()) = destination_labels;
// Fill in the context extensions and metadata context.
Expand All @@ -272,8 +279,16 @@ void CheckRequestUtils::createTcpCheck(
include_peer_certificate);
setAttrContextPeer(*attrs->mutable_destination(), cb->connection(), server_name, true,
include_peer_certificate);
if (include_tls_session && cb->connection().ssl() != nullptr) {
setTLSSession(*attrs->mutable_tls_session(), cb->connection().ssl());

// Try to get the SNI from the TLS session. If not available there then try the
// data from the TLS inspector (i.e. the server name)
if (include_tls_session) {
if (cb->connection()->ssl() != nullptr) {
setTLSSession(*attrs->mutable_tls_session(), cb->connection()->ssl());
} else if (!cb->connection()->requestedServerName().empty()) {
std::string sni{b->connection()->requestedServerName()};
attrs->mutable_tls_session()->set_sni(sni);
}
}
(*attrs->mutable_destination()->mutable_labels()) = destination_labels;
}
Expand Down

0 comments on commit 4496677

Please sign in to comment.