28
28
#include " mbedtls/ctr_drbg.h"
29
29
#include " mbedtls/error.h"
30
30
#include " mbedtls/debug.h"
31
+ #include " mbedtls/x509.h"
31
32
32
33
#include < stdint.h>
33
34
#include < string.h>
@@ -290,8 +291,10 @@ int HelloHttpsClient::configureTlsContexts()
290
291
*/
291
292
mbedtls_ssl_conf_authmode (&ssl_conf, MBEDTLS_SSL_VERIFY_REQUIRED);
292
293
293
- # if HELLO_HTTPS_CLIENT_DEBUG_LEVEL > 0
294
+ /* Configure certificate verification function to clear time/date flags */
294
295
mbedtls_ssl_conf_verify (&ssl_conf, sslVerify, this );
296
+
297
+ #if HELLO_HTTPS_CLIENT_DEBUG_LEVEL > 0
295
298
mbedtls_ssl_conf_dbg (&ssl_conf, sslDebug, NULL );
296
299
mbedtls_debug_set_threshold (HELLO_HTTPS_CLIENT_DEBUG_LEVEL);
297
300
#endif /* HELLO_HTTPS_CLIENT_DEBUG_LEVEL > 0 */
@@ -358,9 +361,18 @@ void HelloHttpsClient::sslDebug(void *ctx, int level, const char *file,
358
361
int HelloHttpsClient::sslVerify (void *ctx, mbedtls_x509_crt *crt, int depth,
359
362
uint32_t *flags)
360
363
{
361
- HelloHttpsClient *client = static_cast <HelloHttpsClient *>(ctx);
364
+ int ret = 0 ;
365
+
366
+ /*
367
+ * If MBEDTLS_HAVE_TIME_DATE is defined, then the certificate date and time
368
+ * validity checks will probably fail because this application does not set
369
+ * up the clock correctly. We filter out date and time related failures
370
+ * instead
371
+ */
372
+ *flags &= ~MBEDTLS_X509_BADCERT_FUTURE & ~MBEDTLS_X509_BADCERT_EXPIRED;
362
373
363
- int ret = -1 ;
374
+ #if HELLO_HTTPS_CLIENT_DEBUG_LEVEL > 0
375
+ HelloHttpsClient *client = static_cast <HelloHttpsClient *>(ctx);
364
376
365
377
ret = mbedtls_x509_crt_info (client->gp_buf , sizeof (gp_buf), " \r " , crt);
366
378
if (ret < 0 ) {
@@ -370,6 +382,7 @@ int HelloHttpsClient::sslVerify(void *ctx, mbedtls_x509_crt *crt, int depth,
370
382
mbedtls_printf (" Verifying certificate at depth %d:\n %s\n " ,
371
383
depth, client->gp_buf );
372
384
}
385
+ #endif /* HELLO_HTTPS_CLIENT_DEBUG_LEVEL > 0 */
373
386
374
387
return ret;
375
388
}
0 commit comments