Browse Source

[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 years ago
parent
commit
4010890a39
4 changed files with 12 additions and 12 deletions
  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 View File

794
 	/* Check OCSP response is valid at the specified time
794
 	/* Check OCSP response is valid at the specified time
795
 	 * (allowing for some margin of error).
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
 		DBGC ( ocsp, "OCSP %p \"%s\" response is not yet valid (at "
798
 		DBGC ( ocsp, "OCSP %p \"%s\" response is not yet valid (at "
799
 		       "time %lld)\n", ocsp, ocsp->cert->subject.name, time );
799
 		       "time %lld)\n", ocsp, ocsp->cert->subject.name, time );
800
 		return -EACCES_STALE;
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
 		DBGC ( ocsp, "OCSP %p \"%s\" response is stale (at time "
803
 		DBGC ( ocsp, "OCSP %p \"%s\" response is stale (at time "
804
 		       "%lld)\n", ocsp, ocsp->cert->subject.name, time );
804
 		       "%lld)\n", ocsp, ocsp->cert->subject.name, time );
805
 		return -EACCES_STALE;
805
 		return -EACCES_STALE;

+ 2
- 2
src/crypto/x509.c View File

1264
 	struct x509_validity *validity = &cert->validity;
1264
 	struct x509_validity *validity = &cert->validity;
1265
 
1265
 
1266
 	/* Check validity period */
1266
 	/* Check validity period */
1267
-	if ( time < validity->not_before.time ) {
1267
+	if ( validity->not_before.time > ( time + X509_ERROR_MARGIN_TIME ) ) {
1268
 		DBGC ( cert, "X509 %p \"%s\" is not yet valid (at time %lld)\n",
1268
 		DBGC ( cert, "X509 %p \"%s\" is not yet valid (at time %lld)\n",
1269
 		       cert, cert->subject.name, time );
1269
 		       cert, cert->subject.name, time );
1270
 		return -EACCES_EXPIRED;
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
 		DBGC ( cert, "X509 %p \"%s\" has expired (at time %lld)\n",
1273
 		DBGC ( cert, "X509 %p \"%s\" has expired (at time %lld)\n",
1274
 		       cert, cert->subject.name, time );
1274
 		       cert, cert->subject.name, time );
1275
 		return -EACCES_EXPIRED;
1275
 		return -EACCES_EXPIRED;

+ 0
- 8
src/include/ipxe/ocsp.h View File

28
 #define OCSP_STATUS_SIG_REQUIRED	0x05
28
 #define OCSP_STATUS_SIG_REQUIRED	0x05
29
 #define OCSP_STATUS_UNAUTHORIZED	0x06
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
 /** An OCSP request */
31
 /** An OCSP request */
40
 struct ocsp_request {
32
 struct ocsp_request {
41
 	/** Request builder */
33
 	/** Request builder */

+ 8
- 0
src/include/ipxe/x509.h View File

42
 	struct x509_time not_after;
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
 /** An X.509 certificate public key */
53
 /** An X.509 certificate public key */
46
 struct x509_public_key {
54
 struct x509_public_key {
47
 	/** Raw public key information */
55
 	/** Raw public key information */

Loading…
Cancel
Save