Bläddra i källkod

[crypto] Allow an error margin on X.509 certificate validity periods

iPXE has no concept of the local time zone, mainly because there is no
viable way to obtain time zone information in the absence of local
state.  This causes potential problems with newly-issued certificates
and certificates that are about to expire.

Avoid such problems by allowing an error margin of around 12 hours on
certificate validity periods, similar to the error margin already
allowed for OCSP response timestamps.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 12 år sedan
förälder
incheckning
4010890a39
4 ändrade filer med 12 tillägg och 12 borttagningar
  1. 2
    2
      src/crypto/ocsp.c
  2. 2
    2
      src/crypto/x509.c
  3. 0
    8
      src/include/ipxe/ocsp.h
  4. 8
    0
      src/include/ipxe/x509.h

+ 2
- 2
src/crypto/ocsp.c Visa fil

@@ -794,12 +794,12 @@ int ocsp_validate ( struct ocsp_check *ocsp, time_t time ) {
794 794
 	/* Check OCSP response is valid at the specified time
795 795
 	 * (allowing for some margin of error).
796 796
 	 */
797
-	if ( response->this_update > ( time + OCSP_ERROR_MARGIN_TIME ) ) {
797
+	if ( response->this_update > ( time + X509_ERROR_MARGIN_TIME ) ) {
798 798
 		DBGC ( ocsp, "OCSP %p \"%s\" response is not yet valid (at "
799 799
 		       "time %lld)\n", ocsp, ocsp->cert->subject.name, time );
800 800
 		return -EACCES_STALE;
801 801
 	}
802
-	if ( response->next_update < ( time - OCSP_ERROR_MARGIN_TIME ) ) {
802
+	if ( response->next_update < ( time - X509_ERROR_MARGIN_TIME ) ) {
803 803
 		DBGC ( ocsp, "OCSP %p \"%s\" response is stale (at time "
804 804
 		       "%lld)\n", ocsp, ocsp->cert->subject.name, time );
805 805
 		return -EACCES_STALE;

+ 2
- 2
src/crypto/x509.c Visa fil

@@ -1264,12 +1264,12 @@ int x509_check_time ( struct x509_certificate *cert, time_t time ) {
1264 1264
 	struct x509_validity *validity = &cert->validity;
1265 1265
 
1266 1266
 	/* Check validity period */
1267
-	if ( time < validity->not_before.time ) {
1267
+	if ( validity->not_before.time > ( time + X509_ERROR_MARGIN_TIME ) ) {
1268 1268
 		DBGC ( cert, "X509 %p \"%s\" is not yet valid (at time %lld)\n",
1269 1269
 		       cert, cert->subject.name, time );
1270 1270
 		return -EACCES_EXPIRED;
1271 1271
 	}
1272
-	if ( time > validity->not_after.time ) {
1272
+	if ( validity->not_after.time < ( time - X509_ERROR_MARGIN_TIME ) ) {
1273 1273
 		DBGC ( cert, "X509 %p \"%s\" has expired (at time %lld)\n",
1274 1274
 		       cert, cert->subject.name, time );
1275 1275
 		return -EACCES_EXPIRED;

+ 0
- 8
src/include/ipxe/ocsp.h Visa fil

@@ -28,14 +28,6 @@ FILE_LICENCE ( GPL2_OR_LATER );
28 28
 #define OCSP_STATUS_SIG_REQUIRED	0x05
29 29
 #define OCSP_STATUS_UNAUTHORIZED	0x06
30 30
 
31
-/** Margin of error allowed in OCSP response times
32
- *
33
- * We allow a generous margin of error: 12 hours to allow for the
34
- * local time zone being non-GMT, plus 30 minutes to allow for general
35
- * clock drift.
36
- */
37
-#define OCSP_ERROR_MARGIN_TIME ( ( 12 * 60 + 30 ) * 60 )
38
-
39 31
 /** An OCSP request */
40 32
 struct ocsp_request {
41 33
 	/** Request builder */

+ 8
- 0
src/include/ipxe/x509.h Visa fil

@@ -42,6 +42,14 @@ struct x509_validity {
42 42
 	struct x509_time not_after;
43 43
 };
44 44
 
45
+/** Margin of error allowed in X.509 response times
46
+ *
47
+ * We allow a generous margin of error: 12 hours to allow for the
48
+ * local time zone being non-GMT, plus 30 minutes to allow for general
49
+ * clock drift.
50
+ */
51
+#define X509_ERROR_MARGIN_TIME ( ( 12 * 60 + 30 ) * 60 )
52
+
45 53
 /** An X.509 certificate public key */
46 54
 struct x509_public_key {
47 55
 	/** Raw public key information */

Laddar…
Avbryt
Spara