Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit 6cc3aff

Browse files
committed
Fix an issue in wrap_socket() results exception when no certificate validation is needed
1 parent 79ee9bf commit 6cc3aff

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

esp32/mods/modussl.c

+15-7
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ static int32_t mod_ssl_setup_socket (mp_obj_ssl_socket_t *ssl_sock, const mbedtl
168168

169169
mbedtls_ssl_set_bio(&ssl_sock->ssl, &ssl_sock->context_fd, mbedtls_net_send, NULL, mbedtls_net_recv_timeout);
170170

171-
// printf("Performing the SSL/TLS handshake...\n");
171+
//printf("Performing the SSL/TLS handshake...\n");
172172
int count = 0;
173173
while ((ret = mbedtls_ssl_handshake(&ssl_sock->ssl)) != 0)
174174
{
@@ -182,13 +182,21 @@ static int32_t mod_ssl_setup_socket (mp_obj_ssl_socket_t *ssl_sock, const mbedtl
182182
}
183183
}
184184

185-
// printf("Verifying peer X.509 certificate...\n");
186-
if ((ret = mbedtls_ssl_get_verify_result(&ssl_sock->ssl)) != 0) {
187-
/* In real life, we probably want to close connection if ret != 0 */
188-
// printf("Failed to verify peer certificate!\n");
185+
//printf("Verifying peer X.509 certificate...\n");
186+
ret = mbedtls_ssl_get_verify_result(&ssl_sock->ssl);
187+
if (ret == 0) {
188+
//printf("Certificate verified.\n");
189+
return 0;
190+
}
191+
// If no verification is needed the mbedtls_ssl_get_verify_result() returns with MBEDTLS_X509_BADCERT_SKIP_VERIFY
192+
else if((ssl_verify == MBEDTLS_SSL_VERIFY_NONE) && (ret == MBEDTLS_X509_BADCERT_SKIP_VERIFY)) {
193+
//printf("Certification validation skipped.\n");
194+
return 0;
195+
}
196+
else {
197+
/* In real life, we probably want to close connection in this case */
198+
//printf("Failed to verify peer certificate!\n");
189199
return -1;
190-
} else {
191-
// printf("Certificate verified.\n");
192200
}
193201
}
194202

0 commit comments

Comments
 (0)