@@ -625,6 +625,52 @@ typedef struct {
625
625
626
626
} br_name_element ;
627
627
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
+
628
674
/**
629
675
* \brief The "minimal" X.509 engine structure.
630
676
*
@@ -647,8 +693,8 @@ typedef struct {
647
693
uint32_t * rp ;
648
694
const unsigned char * ip ;
649
695
} 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 ];
652
698
int err ;
653
699
654
700
/* Server name to match with the SAN / CN of the EE certificate. */
@@ -730,6 +776,12 @@ typedef struct {
730
776
br_name_element * name_elts ;
731
777
size_t num_name_elts ;
732
778
779
+ /*
780
+ * Callback function (and context) to get the current date.
781
+ */
782
+ void * itime_ctx ;
783
+ br_x509_time_check itime ;
784
+
733
785
/*
734
786
* Public key cryptography implementations (signature verification).
735
787
*/
@@ -890,7 +942,10 @@ void br_x509_minimal_init_full(br_x509_minimal_context *ctx,
890
942
* - Seconds are counted since midnight, from 0 to 86400 (a count of
891
943
* 86400 is possible only if a leap second happened).
892
944
*
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.
894
949
*
895
950
* If the validation date and time are not explicitly set, but BearSSL
896
951
* 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,
908
963
{
909
964
ctx -> days = days ;
910
965
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 ;
911
988
}
912
989
913
990
/**
0 commit comments