Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit b927af8

Browse files
[[ Bug 16700 ]] Add support for URLs hosted on SNI aware servers.
1 parent a3b67da commit b927af8

File tree

2 files changed

+51
-42
lines changed

2 files changed

+51
-42
lines changed

docs/notes/bugfix-16700.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# URLs hosted on SNI servers are not supported# URLs hosted on SNI servers are not supported# URLs hosted on SNI servers are not supported

engine/src/opensslsocket.cpp

Lines changed: 50 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1837,7 +1837,25 @@ Boolean MCSocket::sslconnect()
18371837
SSL_set_fd(_ssl_conn, fd);
18381838
}
18391839

1840+
// MM-2014-06-13: [[ Bug 12567 ]] If an end host has been specified, verify against that.
1841+
// Otherwise, use the socket name as before.
1842+
char *t_hostname;
1843+
if (endhostname != NULL)
1844+
t_hostname = strdup(endhostname);
1845+
else
1846+
t_hostname = strdup(name);
1847+
if (strchr(t_hostname, ':') != NULL)
1848+
strchr(t_hostname, ':')[0] = '\0';
1849+
else if (strchr(t_hostname, '|') != NULL)
1850+
strchr(t_hostname, '|')[0] = '\0';
1851+
1852+
// Let the SSL lib know the host we are trying to connect to, ensuring any SNI servers
1853+
// send the correct certificate during the handshake
1854+
SSL_set_tlsext_host_name(_ssl_conn, t_hostname);
1855+
18401856
// Start the SSL connection
1857+
Boolean t_success;
1858+
t_success = True;
18411859

18421860
// MW-2005-02-17: Implement the post-connection check suggested by the SSL Book.
18431861
// The implementation takes the hostname from the string used to open the
@@ -1847,57 +1865,47 @@ Boolean MCSocket::sslconnect()
18471865
{
18481866
if (sslverify)
18491867
{
1850-
// MM-2014-06-13: [[ Bug 12567 ]] If an end host has been specified, verify against that.
1851-
// Otherwise, use the socket name as before.
1852-
char *t_hostname;
1853-
if (endhostname != NULL)
1854-
t_hostname = strdup(endhostname);
1855-
else
1856-
t_hostname = strdup(name);
1857-
if (strchr(t_hostname, ':') != NULL)
1858-
strchr(t_hostname, ':')[0] = '\0';
1859-
else if (strchr(t_hostname, '|') != NULL)
1860-
strchr(t_hostname, '|')[0] = '\0';
1861-
18621868
rc = post_connection_check(_ssl_conn, t_hostname);
1863-
1864-
free(t_hostname);
1865-
18661869
if (rc != X509_V_OK)
18671870
{
18681871
const char *t_message = X509_verify_cert_error_string(rc);
18691872
sslerror = strdup(t_message);
18701873
errno = EPIPE;
1871-
return False;
1874+
t_success = False;
18721875
}
18731876
}
18741877

1875-
sslstate |= SSTATE_CONNECTED;
1876-
setselect(BIONB_TESTREAD | BIONB_TESTWRITE);
1877-
return True;
1878-
}
1879-
1880-
errno = SSL_get_error(_ssl_conn, rc);
1881-
if ((errno != SSL_ERROR_WANT_READ) && (errno != SSL_ERROR_WANT_WRITE))
1882-
{
1883-
return False;
1884-
}
1885-
else
1886-
{
1887-
sslstate |= SSTATE_RETRYCONNECT;
1888-
1889-
if (errno == SSL_ERROR_WANT_WRITE)
1890-
setselect(BIONB_TESTWRITE);
1891-
else if (errno == SSL_ERROR_WANT_READ)
1892-
setselect(BIONB_TESTWRITE);
1893-
1894-
#ifdef _WINDOWS
1895-
1896-
setselect(BIONB_TESTREAD | BIONB_TESTWRITE);
1897-
#endif
1898-
1899-
return True;
1900-
}
1878+
if (t_success)
1879+
{
1880+
sslstate |= SSTATE_CONNECTED;
1881+
setselect(BIONB_TESTREAD | BIONB_TESTWRITE);
1882+
}
1883+
}
1884+
else
1885+
{
1886+
errno = SSL_get_error(_ssl_conn, rc);
1887+
if ((errno != SSL_ERROR_WANT_READ) && (errno != SSL_ERROR_WANT_WRITE))
1888+
{
1889+
t_success = False;
1890+
}
1891+
else
1892+
{
1893+
sslstate |= SSTATE_RETRYCONNECT;
1894+
1895+
if (errno == SSL_ERROR_WANT_WRITE)
1896+
setselect(BIONB_TESTWRITE);
1897+
else if (errno == SSL_ERROR_WANT_READ)
1898+
setselect(BIONB_TESTWRITE);
1899+
1900+
#ifdef _WINDOWS
1901+
1902+
setselect(BIONB_TESTREAD | BIONB_TESTWRITE);
1903+
#endif
1904+
}
1905+
}
1906+
1907+
free(t_hostname);
1908+
return t_success;
19011909
}
19021910

19031911

0 commit comments

Comments
 (0)