Skip to content

Commit 38a5bc7

Browse files
Andres Amaya GarciaAndres Amaya Garcia
authored andcommitted
tls-client: Filter out date/time related failures
1 parent d99ad74 commit 38a5bc7

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

tls-client/HelloHttpsClient.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "mbedtls/ctr_drbg.h"
3131
#include "mbedtls/error.h"
3232
#include "mbedtls/debug.h"
33+
#include "mbedtls/x509.h"
3334

3435
#include <stdint.h>
3536
#include <string.h>
@@ -295,8 +296,10 @@ int HelloHttpsClient::configureTlsContexts()
295296
*/
296297
mbedtls_ssl_conf_authmode(&ssl_conf, MBEDTLS_SSL_VERIFY_REQUIRED);
297298

298-
#if HELLO_HTTPS_CLIENT_DEBUG_LEVEL > 0
299+
/* Configure certificate verification function to clear time/date flags */
299300
mbedtls_ssl_conf_verify(&ssl_conf, sslVerify, this);
301+
302+
#if HELLO_HTTPS_CLIENT_DEBUG_LEVEL > 0
300303
mbedtls_ssl_conf_dbg(&ssl_conf, sslDebug, NULL);
301304
mbedtls_debug_set_threshold(HELLO_HTTPS_CLIENT_DEBUG_LEVEL);
302305
#endif /* HELLO_HTTPS_CLIENT_DEBUG_LEVEL > 0 */
@@ -363,9 +366,18 @@ void HelloHttpsClient::sslDebug(void *ctx, int level, const char *file,
363366
int HelloHttpsClient::sslVerify(void *ctx, mbedtls_x509_crt *crt, int depth,
364367
uint32_t *flags)
365368
{
366-
HelloHttpsClient *client = static_cast<HelloHttpsClient *>(ctx);
369+
int ret = 0;
370+
371+
/*
372+
* If MBEDTLS_HAVE_TIME_DATE is defined, then the certificate date and time
373+
* validity checks will probably fail because this application does not set
374+
* up the clock correctly. We filter out date and time related failures
375+
* instead
376+
*/
377+
*flags &= ~MBEDTLS_X509_BADCERT_FUTURE & ~MBEDTLS_X509_BADCERT_EXPIRED;
367378

368-
int ret = -1;
379+
#if HELLO_HTTPS_CLIENT_DEBUG_LEVEL > 0
380+
HelloHttpsClient *client = static_cast<HelloHttpsClient *>(ctx);
369381

370382
ret = mbedtls_x509_crt_info(client->gp_buf, sizeof(gp_buf), "\r ", crt);
371383
if (ret < 0) {
@@ -375,6 +387,7 @@ int HelloHttpsClient::sslVerify(void *ctx, mbedtls_x509_crt *crt, int depth,
375387
mbedtls_printf("Verifying certificate at depth %d:\n%s\n",
376388
depth, client->gp_buf);
377389
}
390+
#endif /* HELLO_HTTPS_CLIENT_DEBUG_LEVEL > 0 */
378391

379392
return ret;
380393
}

0 commit comments

Comments
 (0)