8000 mimxrt/mbedtls: Enable certificate validity time validation. · micropython/micropython@52e3da0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 52e3da0

Browse files
iabdalkaderdpgeorge
authored andcommitted
mimxrt/mbedtls: Enable certificate validity time validation.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
1 parent 361ca7d commit 52e3da0

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

ports/mimxrt/mbedtls/mbedtls_config.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@
2626
#ifndef MICROPY_INCLUDED_MBEDTLS_CONFIG_H
2727
#define MICROPY_INCLUDED_MBEDTLS_CONFIG_H
2828

29+
// Enable mbedtls modules.
30+
#define MBEDTLS_HAVE_TIME
31+
#define MBEDTLS_HAVE_TIME_DATE
32+
33+
// Time hook.
34+
#include <time.h>
35+
extern time_t mimxrt_rtctime_seconds(time_t *timer);
36+
#define MBEDTLS_PLATFORM_TIME_MACRO mimxrt_rtctime_seconds
37+
2938
// Set MicroPython-specific options.
3039
#define MICROPY_MBEDTLS_CONFIG_BARE_METAL (1)
3140

ports/mimxrt/mbedtls/mbedtls_port.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,16 @@
2424
* THE SOFTWARE.
2525
*/
2626

27+
#include "py/runtime.h"
28+
2729
#ifdef MICROPY_SSL_MBEDTLS
2830

2931
#include "mbedtls_config.h"
32+
#if defined(MBEDTLS_HAVE_TIME) || defined(MBEDTLS_HAVE_TIME_DATE)
33+
#include "fsl_snvs_lp.h"
34+
#include "shared/timeutils/timeutils.h"
35+
#endif
36+
3037
void trng_random_data(unsigned char *output, size_t len);
3138

3239
int mbedtls_hardware_poll(void *data, unsigned char *output, size_t len, size_t *olen) {
@@ -38,4 +45,33 @@ int mbedtls_hardware_poll(void *data, unsigned char *output, size_t len, size_t
3845
return 0;
3946
}
4047

48+
#if defined(MBEDTLS_HAVE_TIME)
49+
time_t mimxrt_rtctime_seconds(time_t *timer) {
50+
// Get date and date in CPython order.
51+
snvs_lp_srtc_datetime_t date;
52+
SNVS_LP_SRTC_GetDatetime(SNVS, &date);
53+
return timeutils_seconds_since_epoch(date.year, date.month, date.day, date.hour, date.minute, date.second);
54+
}
55+
#endif
56+
57+
#if defined(MBEDTLS_HAVE_TIME_DATE)
58+
struct tm *gmtime(const time_t *timep) {
59+
static struct tm tm;
60+
timeutils_struct_time_t tm_buf = {0};
61+
timeutils_seconds_since_epoch_to_struct_time(*timep, &tm_buf);
62+
63+
tm.tm_sec = tm_buf.tm_sec;
64+
tm.tm_min = tm_buf.tm_min;
65+
tm.tm_hour = tm_buf.tm_hour;
66+
tm.tm_mday = tm_buf.tm_mday;
67+
tm.tm_mon = tm_buf.tm_mon - 1;
68+
tm.tm_year = tm_buf.tm_year - 1900;
69+
tm.tm_wday = tm_buf.tm_wday;
70+
tm.tm_yday = tm_buf.tm_yday;
71+
tm.tm_isdst = -1;
72+
73+
return &tm;
74+
}
75+
#endif
76+
4177
#endif

0 commit comments

Comments
 (0)
0