Skip to content

Commit

Permalink
Enable hostname validation for server certificates
Browse files Browse the repository at this point in the history
Without this setting, OpenSSL would only validate that the certificate
has a valid signature from a trusted CA, but not that it actually matches
the host to whom we were trying to connect.
  • Loading branch information
Benno Evers committed Feb 3, 2023
1 parent cae5ef3 commit 2b55680
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions libcaf_openssl/src/openssl/session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ bool session::try_connect(native_socket fd, const std::string& sni_servername) {
CAF_BLOCK_SIGPIPE();
SSL_set_fd(ssl_, fd);
SSL_set_connect_state(ssl_);
// Enable hostname validation.
SSL_set_hostflags(ssl_, X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS);
if (SSL_set1_host(ssl_, sni_servername.c_str()) != 0)
return false;
// Send SNI when connecting.
SSL_set_tlsext_host_name(ssl_, sni_servername.c_str());
auto ret = SSL_connect(ssl_);
if (ret == 1)
Expand Down

0 comments on commit 2b55680

Please sign in to comment.