Skip to content

Commit 760a6bc

Browse files
Update to latest BearSSL (#8600)
Minor SSL bug fix included.
1 parent 0e0ad1f commit 760a6bc

File tree

5 files changed

+95
-5
lines changed

5 files changed

+95
-5
lines changed

tools/sdk/include/bearssl/bearssl.h

+13
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@
137137
#include "bearssl_x509.h"
138138
#include "bearssl_pem.h"
139139

140+
#ifdef __cplusplus
141+
extern "C" {
142+
#endif
143+
140144
/** \brief Type for a configuration option.
141145
*
142146
* A "configuration option" is a value that is selected when the BearSSL
@@ -167,4 +171,13 @@ typedef struct {
167171
*/
168172
const br_config_option *br_get_config(void);
169173

174+
/* ======================================================================= */
175+
176+
/** \brief Version feature: support for time callback. */
177+
#define BR_FEATURE_X509_TIME_CALLBACK 1
178+
179+
#ifdef __cplusplus
180+
}
181+
#endif
182+
170183
#endif
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
// Do not edit -- Automatically generated by tools/sdk/ssl/bearssl/Makefile
2-
#define BEARSSL_GIT 6105635
2+
#define BEARSSL_GIT 9fe3977

tools/sdk/include/bearssl/bearssl_x509.h

+80-3
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,52 @@ typedef struct {
625625

626626
} br_name_element;
627627

628+
/**
629+
* \brief Callback for validity date checks.
630+
*
631+
* The function receives as parameter an arbitrary user-provided context,
632+
* and the notBefore and notAfter dates specified in an X.509 certificate,
633+
* both expressed as a number of days and a number of seconds:
634+
*
635+
* - Days are counted in a proleptic Gregorian calendar since
636+
* January 1st, 0 AD. Year "0 AD" is the one that preceded "1 AD";
637+
* it is also traditionally known as "1 BC".
638+
*
639+
* - Seconds are counted since midnight, from 0 to 86400 (a count of
640+
* 86400 is possible only if a leap second happened).
641+
*
642+
* Each date and time is understood in the UTC time zone. The "Unix
643+
* Epoch" (January 1st, 1970, 00:00 UTC) corresponds to days=719528 and
644+
* seconds=0; the "Windows Epoch" (January 1st, 1601, 00:00 UTC) is
645+
* days=584754, seconds=0.
646+
*
647+
* This function must return -1 if the current date is strictly before
648+
* the "notBefore" time, or +1 if the current date is strictly after the
649+
* "notAfter" time. If neither condition holds, then the function returns
650+
* 0, which means that the current date falls within the validity range of
651+
* the certificate. If the function returns a value distinct from -1, 0
652+
* and +1, then this is interpreted as an unavailability of the current
653+
* time, which normally ends the validation process with a
654+
* `BR_ERR_X509_TIME_UNKNOWN` error.
655+
*
656+
* During path validation, this callback will be invoked for each
657+
* considered X.509 certificate. Validation fails if any of the calls
658+
* returns a non-zero value.
659+
*
660+
* The context value is an abritrary pointer set by the caller when
661+
* configuring this callback.
662+
*
663+
* \param tctx context pointer.
664+
* \param not_before_days notBefore date (days since Jan 1st, 0 AD).
665+
* \param not_before_seconds notBefore time (seconds, at most 86400).
666+
* \param not_after_days notAfter date (days since Jan 1st, 0 AD).
667+
* \param not_after_seconds notAfter time (seconds, at most 86400).
668+
* \return -1, 0 or +1.
669+
*/
670+
typedef int (*br_x509_time_check)(void *tctx,
671+
uint32_t not_before_days, uint32_t not_before_seconds,
672+
uint32_t not_after_days, uint32_t not_after_seconds);
673+
628674
/**
629675
* \brief The "minimal" X.509 engine structure.
630676
*
@@ -647,8 +693,8 @@ typedef struct {
647693
uint32_t *rp;
648694
const unsigned char *ip;
649695
} cpu;
650-
uint32_t dp_stack[32];
651-
uint32_t rp_stack[32];
696+
uint32_t dp_stack[31];
697+
uint32_t rp_stack[31];
652698
int err;
653699

654700
/* Server name to match with the SAN / CN of the EE certificate. */
@@ -730,6 +776,12 @@ typedef struct {
730776
br_name_element *name_elts;
731777
size_t num_name_elts;
732778

779+
/*
780+
* Callback function (and context) to get the current date.
781+
*/
782+
void *itime_ctx;
783+
br_x509_time_check itime;
784+
733785
/*
734786
* Public key cryptography implementations (signature verification).
735787
*/
@@ -890,7 +942,10 @@ void br_x509_minimal_init_full(br_x509_minimal_context *ctx,
890942
* - Seconds are counted since midnight, from 0 to 86400 (a count of
891943
* 86400 is possible only if a leap second happened).
892944
*
893-
* The validation date and time is understood in the UTC time zone.
945+
* The validation date and time is understood in the UTC time zone. The
946+
* "Unix Epoch" (January 1st, 1970, 00:00 UTC) corresponds to days=719528
947+
* and seconds=0; the "Windows Epoch" (January 1st, 1601, 00:00 UTC) is
948+
* days=584754, seconds=0.
894949
*
895950
* If the validation date and time are not explicitly set, but BearSSL
896951
* was compiled with support for the system clock on the underlying
@@ -908,6 +963,28 @@ br_x509_minimal_set_time(br_x509_minimal_context *ctx,
908963
{
909964
ctx->days = days;
910965
ctx->seconds = seconds;
966+
ctx->itime = 0;
967+
}
968+
969+
/**
970+
* \brief Set the validity range callback function for the X.509
971+
* "minimal" engine.
972+
*
973+
* The provided function will be invoked to check whether the validation
974+
* date is within the validity range for a given X.509 certificate; a
975+
* call will be issued for each considered certificate. The provided
976+
* context pointer (itime_ctx) will be passed as first parameter to the
977+
* callback.
978+
*
979+
* \param tctx context for callback invocation.
980+
* \param cb callback function.
981+
*/
982+
static inline void
983+
br_x509_minimal_set_time_callback(br_x509_minimal_context *ctx,
984+
void *itime_ctx, br_x509_time_check itime)
985+
{
986+
ctx->itime_ctx = itime_ctx;
987+
ctx->itime = itime;
911988
}
912989

913990
/**

tools/sdk/lib/libbearssl.a

4.54 KB
Binary file not shown.

0 commit comments

Comments
 (0)