Skip to content

Commit ac0147c

Browse files
Merge pull request #2127 from Expensify/tyler-fix-ssl-2.28
Fix SNI on mbedtls 2.28.8
2 parents 0b71271 + 83a0709 commit ac0147c

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

libstuff/SSSLState.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ SSSLState::~SSSLState() {
2222
}
2323

2424
// --------------------------------------------------------------------------
25-
SSSLState* SSSLOpen(int s, SX509* x509) {
25+
SSSLState* SSSLOpen(int s, SX509* x509, const string& hostname) {
2626
// Initialize the SSL state
2727
SASSERT(s >= 0);
2828
SSSLState* state = new SSSLState;
@@ -37,6 +37,12 @@ SSSLState* SSSLOpen(int s, SX509* x509) {
3737
mbedtls_ssl_conf_rng(&state->conf, mbedtls_ctr_drbg_random, &state->ctr_drbg);
3838
mbedtls_ssl_set_bio(&state->ssl, &state->s, mbedtls_net_send, mbedtls_net_recv, 0);
3939

40+
if (hostname.size()) {
41+
if (mbedtls_ssl_set_hostname(&state->ssl, hostname.c_str())) {
42+
STHROW("ssl set hostname failed");
43+
}
44+
}
45+
4046
if (x509) {
4147
// Add the certificate
4248
mbedtls_ssl_conf_ca_chain(&state->conf, x509->srvcert.next, 0);

libstuff/SSSLState.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ struct SSSLState {
2323
};
2424

2525
// SSL helpers
26-
extern SSSLState* SSSLOpen(int s, SX509* x509);
26+
extern SSSLState* SSSLOpen(int s, SX509* x509, const string& hostname = "");
2727
extern int SSSLSend(SSSLState* ssl, const char* buffer, int length);
2828
extern int SSSLSend(SSSLState* ssl, const SFastBuffer& buffer);
2929
extern bool SSSLSendConsume(SSSLState* ssl, SFastBuffer& sendBuffer);

libstuff/STCPManager.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,14 @@ STCPManager::Socket::Socket(const string& host, SX509* x509)
212212
if (s < 0) {
213213
STHROW("Couldn't open socket to " + host);
214214
}
215-
ssl = x509 ? SSSLOpen(s, x509) : nullptr;
215+
216+
string domain;
217+
if (x509) {
218+
uint16_t port;
219+
SParseHost(host, domain, port);
220+
}
221+
222+
ssl = x509 ? SSSLOpen(s, x509, domain) : nullptr;
216223
SASSERT(!x509 || ssl);
217224
}
218225

0 commit comments

Comments
 (0)