Skip to content

Manage TLS Server Name Indication #405

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion libraries/SocketWrapper/src/MbedClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,15 @@ int arduino::MbedClient::connectSSL(IPAddress ip, uint16_t port) {
return connectSSL(SocketHelpers::socketAddressFromIpAddress(ip, port));
}

int arduino::MbedClient::connectSSL(const char *host, uint16_t port) {
int arduino::MbedClient::connectSSL(const char *host, uint16_t port, bool disableSNI) {
if (!disableSNI) {
if (sock == nullptr) {
sock = new TLSSocket();
_own_socket = true;
}
static_cast<TLSSocket *>(sock)->set_hostname(host);
}

SocketAddress socketAddress = SocketAddress();
socketAddress.set_port(port);
getNetwork()->gethostbyname(host, &socketAddress);
Expand Down
2 changes: 1 addition & 1 deletion libraries/SocketWrapper/src/MbedClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class MbedClient : public arduino::Client {
int connect(const char* host, uint16_t port);
int connectSSL(SocketAddress socketAddress);
int connectSSL(IPAddress ip, uint16_t port);
int connectSSL(const char* host, uint16_t port);
int connectSSL(const char* host, uint16_t port, bool disableSNI = false);
size_t write(uint8_t);
size_t write(const uint8_t* buf, size_t size);
int available();
Expand Down
4 changes: 2 additions & 2 deletions libraries/SocketWrapper/src/MbedSSLClient.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "MbedSSLClient.h"

arduino::MbedSSLClient::MbedSSLClient() {
arduino::MbedSSLClient::MbedSSLClient(): _disableSNI{false} {
onBeforeConnect(mbed::callback(this, &MbedSSLClient::setRootCA));
};
};
9 changes: 7 additions & 2 deletions libraries/SocketWrapper/src/MbedSSLClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,20 @@ class MbedSSLClient : public arduino::MbedClient {
return connectSSL(ip, port);
}
int connect(const char* host, uint16_t port) {
return connectSSL(host, port);
return connectSSL(host, port, _disableSNI);
}
void disableSNI(bool statusSNI) {
_disableSNI = statusSNI;
}

private:
int setRootCA() {
return ((TLSSocket*)sock)->set_root_ca_cert_path("/wlan/");
}

bool _disableSNI;
};

}

#endif /* MBEDSSLCLIENT_H */
#endif /* MBEDSSLCLIENT_H */
4 changes: 2 additions & 2 deletions libraries/WiFi/src/WiFiSSLClient.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "WiFiSSLClient.h"

arduino::WiFiSSLClient::WiFiSSLClient() {
arduino::WiFiSSLClient::WiFiSSLClient(): _disableSNI{false} {
onBeforeConnect(mbed::callback(this, &WiFiSSLClient::setRootCA));
};
};
9 changes: 7 additions & 2 deletions libraries/WiFi/src/WiFiSSLClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,20 @@ class WiFiSSLClient : public arduino::WiFiClient {
return connectSSL(ip, port);
}
int connect(const char* host, uint16_t port) {
return connectSSL(host, port);
return connectSSL(host, port, _disableSNI);
}
void disableSNI(bool statusSNI) {
_disableSNI = statusSNI;
}

private:
int setRootCA() {
return ((TLSSocket*)sock)->set_root_ca_cert_path("/wlan/");
}

bool _disableSNI;
};

}

#endif /* WIFISSLCLIENT_H */
#endif /* WIFISSLCLIENT_H */