Skip to content

Commit 4143034

Browse files
committed
Use br_x509_minimal_set_time to inject current
1 parent 57751cd commit 4143034

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

src/ArduinoBearSSL.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,3 @@ void ArduinoBearSSLClass::onGetTime(unsigned long(*callback)(void))
2424
}
2525

2626
ArduinoBearSSLClass ArduinoBearSSL;
27-
28-
extern "C" {
29-
#include <sys/time.h>
30-
31-
int _gettimeofday(struct timeval* tp, void* /*tzvp*/)
32-
{
33-
tp->tv_sec = ArduinoBearSSL.getTime();
34-
tp->tv_usec = 0;
35-
36-
return 0;
37-
}
38-
}

src/BearSSLClient.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "ArduinoBearSSL.h"
12
#include "BearSSLTrustAnchors.h"
23

34
#include "BearSSLClient.h"
@@ -161,6 +162,13 @@ int BearSSLClient::connectSSL(const char* host)
161162
*/
162163
br_ssl_client_reset(&_sc, host, 0);
163164

165+
// get the current time and set it for X.509 validation
166+
uint32_t now = ArduinoBearSSL.getTime();
167+
uint32_t days = now / 86400 + 719528;
168+
uint32_t sec = now % 86400;
169+
170+
br_x509_minimal_set_time(&_xc, days, sec);
171+
164172
/*
165173
* Initialise the simplified I/O wrapper context, to use our
166174
* SSL client context, and the two callbacks for socket I/O.

0 commit comments

Comments
 (0)