Skip to content

Commit 1664939

Browse files
committed
rp2/mbedtls: Enable certificate validity time validation.
1 parent 91d30da commit 1664939

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

ports/rp2/mbedtls/mbedtls_config.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@
9696

9797
#define MBEDTLS_BASE64_C
9898
#define MBEDTLS_PEM_PARSE_C
99+
#define MBEDTLS_HAVE_TIME
100+
#define MBEDTLS_HAVE_TIME_DATE
101+
99102
// Memory allocation hooks
100103
#include <stdlib.h>
101104
#include <stdio.h>
@@ -105,6 +108,10 @@ void m_tracked_free(void *ptr);
105108
#define MBEDTLS_PLATFORM_STD_FREE m_tracked_free
106109
#define MBEDTLS_PLATFORM_SNPRINTF_MACRO snprintf
107110

111+
// Time hook
112+
time_t rp2_rtctime_seconds(time_t *timer);
113+
#define MBEDTLS_PLATFORM_TIME_MACRO rp2_rtctime_seconds
114+
108115
#include "mbedtls/check_config.h"
109116

110117
#endif /* MICROPY_INCLUDED_MBEDTLS_CONFIG_H */

ports/rp2/mbedtls/mbedtls_port.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929

3030
#include "mbedtls_config.h"
3131

32+
#include "hardware/rtc.h"
33+
#include "shared/timeutils/timeutils.h"
34+
3235
extern uint8_t rosc_random_u8(size_t cycles);
3336

3437
int mbedtls_hardware_poll(void *data, unsigned char *output, size_t len, size_t *olen) {
@@ -39,4 +42,10 @@ int mbedtls_hardware_poll(void *data, unsigned char *output, size_t len, size_t
3942
return 0;
4043
}
4144

45+
time_t rp2_rtctime_seconds(time_t *timer) {
46+
datetime_t t;
47+
rtc_get_datetime(&t);
48+
return timeutils_seconds_since_epoch(t.year, t.month, t.day, t.hour, t.min, t.sec);
49+
}
50+
4251
#endif

0 commit comments

Comments
 (0)