Skip to content

Commit 7703f97

Browse files
author
Benno Evers
committed
Enable hostname validation for server certificates
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.
1 parent cae5ef3 commit 7703f97

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

libcaf_openssl/src/openssl/session.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,13 @@ bool session::try_connect(native_socket fd, const std::string& sni_servername) {
159159
CAF_BLOCK_SIGPIPE();
160160
SSL_set_fd(ssl_, fd);
161161
SSL_set_connect_state(ssl_);
162+
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
163+
// Enable hostname validation.
164+
SSL_set_hostflags(ssl_, X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS);
165+
if (SSL_set1_host(ssl_, sni_servername.c_str()) != 1)
166+
return false;
167+
#endif
168+
// Send SNI when connecting.
162169
SSL_set_tlsext_host_name(ssl_, sni_servername.c_str());
163170
auto ret = SSL_connect(ssl_);
164171
if (ret == 1)

0 commit comments

Comments
 (0)