Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 46257c0

Browse filesBrowse files
a-c-sreedhar-reddyme-no-dev
authored andcommitted
handshake in ssl_client.cpp (espressif#2044)
* issue espressif#2041 * handshake timeout * seconds to milliseconds
1 parent 0640964 commit 46257c0
Copy full SHA for 46257c0

File tree

Expand file treeCollapse file tree

4 files changed

+14
-3
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+14
-3
lines changed

‎libraries/WiFiClientSecure/src/WiFiClientSecure.cpp

Copy file name to clipboardExpand all lines: libraries/WiFiClientSecure/src/WiFiClientSecure.cpp
+7-1Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ WiFiClientSecure::WiFiClientSecure()
3535
sslclient = new sslclient_context;
3636
ssl_init(sslclient);
3737
sslclient->socket = -1;
38-
38+
sslclient->handshake_timeout = 120000;
3939
_CA_cert = NULL;
4040
_cert = NULL;
4141
_private_key = NULL;
@@ -50,6 +50,7 @@ WiFiClientSecure::WiFiClientSecure(int sock)
5050
sslclient = new sslclient_context;
5151
ssl_init(sslclient);
5252
sslclient->socket = sock;
53+
sslclient->handshake_timeout = 120000;
5354

5455
if (sock >= 0) {
5556
_connected = true;
@@ -285,3 +286,8 @@ int WiFiClientSecure::lastError(char *buf, const size_t size)
285286
snprintf(buf, size, "%s", error_buf);
286287
return _lastError;
287288
}
289+
290+
void WiFiClientSecure::setHandshakeTimeout(unsigned long handshake_timeout)
291+
{
292+
sslclient->handshake_timeout = handshake_timeout * 1000;
293+
}

‎libraries/WiFiClientSecure/src/WiFiClientSecure.h

Copy file name to clipboardExpand all lines: libraries/WiFiClientSecure/src/WiFiClientSecure.h
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class WiFiClientSecure : public WiFiClient
6262
bool loadCertificate(Stream& stream, size_t size);
6363
bool loadPrivateKey(Stream& stream, size_t size);
6464
bool verify(const char* fingerprint, const char* domain_name);
65+
void setHandshakeTimeout(unsigned long handshake_timeout);
6566

6667
operator bool()
6768
{

‎libraries/WiFiClientSecure/src/ssl_client.cpp

Copy file name to clipboardExpand all lines: libraries/WiFiClientSecure/src/ssl_client.cpp
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,14 @@ int start_ssl_client(sslclient_context *ssl_client, const char *host, uint32_t p
158158
mbedtls_ssl_set_bio(&ssl_client->ssl_ctx, &ssl_client->socket, mbedtls_net_send, mbedtls_net_recv, NULL );
159159

160160
log_v("Performing the SSL/TLS handshake...");
161-
161+
unsigned long handshake_start_time=millis();
162162
while ((ret = mbedtls_ssl_handshake(&ssl_client->ssl_ctx)) != 0) {
163163
if (ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE) {
164164
return handle_error(ret);
165165
}
166-
vTaskDelay(10 / portTICK_PERIOD_MS);
166+
if((millis()-handshake_start_time)>ssl_client->handshake_timeout)
167+
return -1;
168+
vTaskDelay(10 / portTICK_PERIOD_MS);
167169
}
168170

169171

‎libraries/WiFiClientSecure/src/ssl_client.h

Copy file name to clipboardExpand all lines: libraries/WiFiClientSecure/src/ssl_client.h
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ typedef struct sslclient_context {
2323
mbedtls_x509_crt ca_cert;
2424
mbedtls_x509_crt client_cert;
2525
mbedtls_pk_context client_key;
26+
27+
unsigned long handshake_timeout;
2628
} sslclient_context;
2729

2830

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.