Skip to content
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

Fix and simplify sni setting #987

Merged
merged 1 commit into from
Nov 5, 2024
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
4 changes: 2 additions & 2 deletions libraries/SocketWrapper/src/AClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ int arduino::AClient::connectSSL(IPAddress ip, uint16_t port) {
return client->connectSSL(ip, port);
}

int arduino::AClient::connectSSL(const char *host, uint16_t port, bool disableSNI) {
int arduino::AClient::connectSSL(const char *host, uint16_t port) {
if (!client) {
newMbedClient();
}
return client->connectSSL(host, port, disableSNI);
return client->connectSSL(host, port);
}

void arduino::AClient::stop() {
Expand Down
2 changes: 1 addition & 1 deletion libraries/SocketWrapper/src/AClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class AClient : public Client {
virtual int connect(IPAddress ip, uint16_t port);
virtual int connect(const char *host, uint16_t port);
int connectSSL(IPAddress ip, uint16_t port);
int connectSSL(const char* host, uint16_t port, bool disableSNI = false);
int connectSSL(const char* host, uint16_t port);
virtual void stop();

virtual explicit operator bool();
Expand Down
10 changes: 1 addition & 9 deletions libraries/SocketWrapper/src/MbedClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,7 @@ 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, bool disableSNI) {
if (!disableSNI) {
if (sock == nullptr) {
sock = new TLSSocket();
_own_socket = true;
}
static_cast<TLSSocket *>(sock)->set_hostname(host);
}

int arduino::MbedClient::connectSSL(const char *host, uint16_t port) {
SocketAddress socketAddress = SocketAddress();
socketAddress.set_port(port);
SocketHelpers::gethostbyname(getNetwork(), 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 @@ -56,7 +56,7 @@ class MbedClient {
virtual 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, bool disableSNI = false);
int connectSSL(const char* host, uint16_t port);
size_t write(uint8_t);
size_t write(const uint8_t* buf, size_t size);
int available();
Expand Down
8 changes: 7 additions & 1 deletion libraries/SocketWrapper/src/MbedSSLClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ class MbedSSLClient : public arduino::MbedClient {
return connectSSL(ip, port);
}
int connect(const char* host, uint16_t port) {
return connectSSL(host, port, _disableSNI);
_hostname = host;
return connectSSL(host, port);
}
void disableSNI(bool statusSNI) {
_disableSNI = statusSNI;
Expand All @@ -53,6 +54,7 @@ class MbedSSLClient : public arduino::MbedClient {

protected:
const char* _ca_cert_custom = NULL;
const char* _hostname = NULL;

private:
int setRootCA() {
Expand All @@ -79,6 +81,10 @@ class MbedSSLClient : public arduino::MbedClient {
}
#endif

if(_hostname && !_disableSNI) {
((TLSSocket*)sock)->set_hostname(_hostname);
}

if(_ca_cert_custom != NULL) {
err = ((TLSSocket*)sock)->append_root_ca_cert(_ca_cert_custom);
}
Expand Down