Skip to content

Commit 11c3c83

Browse files
authored
Merge pull request #987 from pennam/sni-fix
Fix and simplify sni setting
2 parents 26ff735 + 4081c6b commit 11c3c83

File tree

5 files changed

+12
-14
lines changed

5 files changed

+12
-14
lines changed

libraries/SocketWrapper/src/AClient.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ int arduino::AClient::connectSSL(IPAddress ip, uint16_t port) {
4646
return client->connectSSL(ip, port);
4747
}
4848

49-
int arduino::AClient::connectSSL(const char *host, uint16_t port, bool disableSNI) {
49+
int arduino::AClient::connectSSL(const char *host, uint16_t port) {
5050
if (!client) {
5151
newMbedClient();
5252
}
53-
return client->connectSSL(host, port, disableSNI);
53+
return client->connectSSL(host, port);
5454
}
5555

5656
void arduino::AClient::stop() {

libraries/SocketWrapper/src/AClient.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class AClient : public Client {
3232
virtual int connect(IPAddress ip, uint16_t port);
3333
virtual int connect(const char *host, uint16_t port);
3434
int connectSSL(IPAddress ip, uint16_t port);
35-
int connectSSL(const char* host, uint16_t port, bool disableSNI = false);
35+
int connectSSL(const char* host, uint16_t port);
3636
virtual void stop();
3737

3838
virtual explicit operator bool();

libraries/SocketWrapper/src/MbedClient.cpp

+1-9
Original file line numberDiff line numberDiff line change
@@ -186,15 +186,7 @@ int arduino::MbedClient::connectSSL(IPAddress ip, uint16_t port) {
186186
return connectSSL(SocketHelpers::socketAddressFromIpAddress(ip, port));
187187
}
188188

189-
int arduino::MbedClient::connectSSL(const char *host, uint16_t port, bool disableSNI) {
190-
if (!disableSNI) {
191-
if (sock == nullptr) {
192-
sock = new TLSSocket();
193-
_own_socket = true;
194-
}
195-
static_cast<TLSSocket *>(sock)->set_hostname(host);
196-
}
197-
189+
int arduino::MbedClient::connectSSL(const char *host, uint16_t port) {
198190
SocketAddress socketAddress = SocketAddress();
199191
socketAddress.set_port(port);
200192
SocketHelpers::gethostbyname(getNetwork(), host, &socketAddress);

libraries/SocketWrapper/src/MbedClient.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class MbedClient {
5656
virtual int connect(const char* host, uint16_t port);
5757
int connectSSL(SocketAddress socketAddress);
5858
int connectSSL(IPAddress ip, uint16_t port);
59-
int connectSSL(const char* host, uint16_t port, bool disableSNI = false);
59+
int connectSSL(const char* host, uint16_t port);
6060
size_t write(uint8_t);
6161
size_t write(const uint8_t* buf, size_t size);
6262
int available();

libraries/SocketWrapper/src/MbedSSLClient.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ class MbedSSLClient : public arduino::MbedClient {
4141
return connectSSL(ip, port);
4242
}
4343
int connect(const char* host, uint16_t port) {
44-
return connectSSL(host, port, _disableSNI);
44+
_hostname = host;
45+
return connectSSL(host, port);
4546
}
4647
void disableSNI(bool statusSNI) {
4748
_disableSNI = statusSNI;
@@ -53,6 +54,7 @@ class MbedSSLClient : public arduino::MbedClient {
5354

5455
protected:
5556
const char* _ca_cert_custom = NULL;
57+
const char* _hostname = NULL;
5658

5759
private:
5860
int setRootCA() {
@@ -79,6 +81,10 @@ class MbedSSLClient : public arduino::MbedClient {
7981
}
8082
#endif
8183

84+
if(_hostname && !_disableSNI) {
85+
((TLSSocket*)sock)->set_hostname(_hostname);
86+
}
87+
8288
if(_ca_cert_custom != NULL) {
8389
err = ((TLSSocket*)sock)->append_root_ca_cert(_ca_cert_custom);
8490
}

0 commit comments

Comments
 (0)