Skip to content

Commit f7cb8f6

Browse files
committed
Fix: Include the Server Name Indication (SNI) in the TLS client handshake.
1 parent 3fa4f66 commit f7cb8f6

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

trunk/src/protocol/srs_protocol_http_client.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ SrsSslClient::~SrsSslClient()
5656

5757
#pragma GCC diagnostic push
5858
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
59-
srs_error_t SrsSslClient::handshake()
59+
srs_error_t SrsSslClient::handshake(const std::string& hostname)
6060
{
6161
srs_error_t err = srs_success;
6262

@@ -88,6 +88,11 @@ srs_error_t SrsSslClient::handshake()
8888
// SSL setup active, as client role.
8989
SSL_set_connect_state(ssl);
9090
SSL_set_mode(ssl, SSL_MODE_ENABLE_PARTIAL_WRITE);
91+
// If the server address is not in IP address format, set the hostname
92+
// in the Server Name Indication (SNI) field.
93+
if (! srs_check_ip_addr_valid(hostname)) {
94+
SSL_set_tlsext_host_name(ssl, hostname.c_str());
95+
}
9196

9297
// Send ClientHello.
9398
int r0 = SSL_do_handshake(ssl); int r1 = SSL_get_error(ssl, r0); ERR_clear_error();
@@ -468,7 +473,7 @@ srs_error_t SrsHttpClient::connect()
468473

469474
srs_utime_t starttime = srs_update_system_time();
470475

471-
if ((err = ssl_transport->handshake()) != srs_success) {
476+
if ((err = ssl_transport->handshake(host)) != srs_success) {
472477
disconnect();
473478
return srs_error_wrap(err, "http: ssl connect %s %s:%d to=%dms, rto=%dms",
474479
schema_.c_str(), host.c_str(), port, srsu2msi(timeout), srsu2msi(recv_timeout));

trunk/src/protocol/srs_protocol_http_client.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class SrsSslClient : public ISrsReader, public ISrsStreamWriter
4343
SrsSslClient(SrsTcpClient* tcp);
4444
virtual ~SrsSslClient();
4545
public:
46-
virtual srs_error_t handshake();
46+
virtual srs_error_t handshake(const std::string& hostname);
4747
public:
4848
virtual srs_error_t read(void* buf, size_t size, ssize_t* nread);
4949
virtual srs_error_t write(void* buf, size_t size, ssize_t* nwrite);

0 commit comments

Comments
 (0)