30
30
#include " mbedtls/ctr_drbg.h"
31
31
#include " mbedtls/error.h"
32
32
#include " mbedtls/debug.h"
33
+ #include " mbedtls/x509.h"
33
34
34
35
#include < stdint.h>
35
36
#include < string.h>
@@ -295,8 +296,10 @@ int HelloHttpsClient::configureTlsContexts()
295
296
*/
296
297
mbedtls_ssl_conf_authmode (&ssl_conf, MBEDTLS_SSL_VERIFY_REQUIRED);
297
298
298
- # if HELLO_HTTPS_CLIENT_DEBUG_LEVEL > 0
299
+ /* Configure certificate verification function to clear time/date flags */
299
300
mbedtls_ssl_conf_verify (&ssl_conf, sslVerify, this );
301
+
302
+ #if HELLO_HTTPS_CLIENT_DEBUG_LEVEL > 0
300
303
mbedtls_ssl_conf_dbg (&ssl_conf, sslDebug, NULL );
301
304
mbedtls_debug_set_threshold (HELLO_HTTPS_CLIENT_DEBUG_LEVEL);
302
305
#endif /* HELLO_HTTPS_CLIENT_DEBUG_LEVEL > 0 */
@@ -363,9 +366,18 @@ void HelloHttpsClient::sslDebug(void *ctx, int level, const char *file,
363
366
int HelloHttpsClient::sslVerify (void *ctx, mbedtls_x509_crt *crt, int depth,
364
367
uint32_t *flags)
365
368
{
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;
367
378
368
- int ret = -1 ;
379
+ #if HELLO_HTTPS_CLIENT_DEBUG_LEVEL > 0
380
+ HelloHttpsClient *client = static_cast <HelloHttpsClient *>(ctx);
369
381
370
382
ret = mbedtls_x509_crt_info (client->gp_buf , sizeof (gp_buf), " \r " , crt);
371
383
if (ret < 0 ) {
@@ -375,6 +387,7 @@ int HelloHttpsClient::sslVerify(void *ctx, mbedtls_x509_crt *crt, int depth,
375
387
mbedtls_printf (" Verifying certificate at depth %d:\n %s\n " ,
376
388
depth, client->gp_buf );
377
389
}
390
+ #endif /* HELLO_HTTPS_CLIENT_DEBUG_LEVEL > 0 */
378
391
379
392
return ret;
380
393
}
0 commit comments