Browse Source

[crypto] Generalise X.509 "valid" field to a "flags" field

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 8 years ago
parent
commit
ff28b22568
5 changed files with 25 additions and 10 deletions
  1. 1
    1
      src/crypto/ocsp.c
  2. 4
    4
      src/crypto/x509.c
  3. 18
    3
      src/include/ipxe/x509.h
  4. 1
    1
      src/net/validator.c
  5. 1
    1
      src/tests/ocsp_test.c

+ 1
- 1
src/crypto/ocsp.c View File

282
 	/* Sanity checks */
282
 	/* Sanity checks */
283
 	assert ( cert != NULL );
283
 	assert ( cert != NULL );
284
 	assert ( issuer != NULL );
284
 	assert ( issuer != NULL );
285
-	assert ( issuer->valid );
285
+	assert ( x509_is_valid ( issuer ) );
286
 
286
 
287
 	/* Allocate and initialise check */
287
 	/* Allocate and initialise check */
288
 	*ocsp = zalloc ( sizeof ( **ocsp ) );
288
 	*ocsp = zalloc ( sizeof ( **ocsp ) );

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

1320
 		root = &root_certificates;
1320
 		root = &root_certificates;
1321
 
1321
 
1322
 	/* Return success if certificate has already been validated */
1322
 	/* Return success if certificate has already been validated */
1323
-	if ( cert->valid )
1323
+	if ( x509_is_valid ( cert ) )
1324
 		return 0;
1324
 		return 0;
1325
 
1325
 
1326
 	/* Fail if certificate is invalid at specified time */
1326
 	/* Fail if certificate is invalid at specified time */
1329
 
1329
 
1330
 	/* Succeed if certificate is a trusted root certificate */
1330
 	/* Succeed if certificate is a trusted root certificate */
1331
 	if ( x509_check_root ( cert, root ) == 0 ) {
1331
 	if ( x509_check_root ( cert, root ) == 0 ) {
1332
-		cert->valid = 1;
1332
+		cert->flags |= X509_FL_VALIDATED;
1333
 		cert->path_remaining = ( cert->extensions.basic.path_len + 1 );
1333
 		cert->path_remaining = ( cert->extensions.basic.path_len + 1 );
1334
 		return 0;
1334
 		return 0;
1335
 	}
1335
 	}
1342
 	}
1342
 	}
1343
 
1343
 
1344
 	/* Fail unless issuer has already been validated */
1344
 	/* Fail unless issuer has already been validated */
1345
-	if ( ! issuer->valid ) {
1345
+	if ( ! x509_is_valid ( issuer ) ) {
1346
 		DBGC ( cert, "X509 %p \"%s\" ", cert, x509_name ( cert ) );
1346
 		DBGC ( cert, "X509 %p \"%s\" ", cert, x509_name ( cert ) );
1347
 		DBGC ( cert, "issuer %p \"%s\" has not yet been validated\n",
1347
 		DBGC ( cert, "issuer %p \"%s\" has not yet been validated\n",
1348
 		       issuer, x509_name ( issuer ) );
1348
 		       issuer, x509_name ( issuer ) );
1376
 		cert->path_remaining = max_path_remaining;
1376
 		cert->path_remaining = max_path_remaining;
1377
 
1377
 
1378
 	/* Mark certificate as valid */
1378
 	/* Mark certificate as valid */
1379
-	cert->valid = 1;
1379
+	cert->flags |= X509_FL_VALIDATED;
1380
 
1380
 
1381
 	DBGC ( cert, "X509 %p \"%s\" successfully validated using ",
1381
 	DBGC ( cert, "X509 %p \"%s\" successfully validated using ",
1382
 	       cert, x509_name ( cert ) );
1382
 	       cert, x509_name ( cert ) );

+ 18
- 3
src/include/ipxe/x509.h View File

189
 	/** Link in certificate store */
189
 	/** Link in certificate store */
190
 	struct x509_link store;
190
 	struct x509_link store;
191
 
191
 
192
-	/** Certificate has been validated */
193
-	int valid;
192
+	/** Flags */
193
+	unsigned int flags;
194
 	/** Maximum number of subsequent certificates in chain */
194
 	/** Maximum number of subsequent certificates in chain */
195
 	unsigned int path_remaining;
195
 	unsigned int path_remaining;
196
 
196
 
216
 	struct x509_extensions extensions;
216
 	struct x509_extensions extensions;
217
 };
217
 };
218
 
218
 
219
+/** X.509 certificate flags */
220
+enum x509_flags {
221
+	/** Certificate has been validated */
222
+	X509_FL_VALIDATED = 0x0001,
223
+};
224
+
219
 /**
225
 /**
220
  * Get reference to X.509 certificate
226
  * Get reference to X.509 certificate
221
  *
227
  *
373
 			     struct x509_root *root );
379
 			     struct x509_root *root );
374
 extern int x509_check_time ( struct x509_certificate *cert, time_t time );
380
 extern int x509_check_time ( struct x509_certificate *cert, time_t time );
375
 
381
 
382
+/**
383
+ * Check if X.509 certificate is valid
384
+ *
385
+ * @v cert		X.509 certificate
386
+ */
387
+static inline int x509_is_valid ( struct x509_certificate *cert ) {
388
+	return ( cert->flags & X509_FL_VALIDATED );
389
+}
390
+
376
 /**
391
 /**
377
  * Invalidate X.509 certificate
392
  * Invalidate X.509 certificate
378
  *
393
  *
379
  * @v cert		X.509 certificate
394
  * @v cert		X.509 certificate
380
  */
395
  */
381
 static inline void x509_invalidate ( struct x509_certificate *cert ) {
396
 static inline void x509_invalidate ( struct x509_certificate *cert ) {
382
-	cert->valid = 0;
397
+	cert->flags &= ~X509_FL_VALIDATED;
383
 	cert->path_remaining = 0;
398
 	cert->path_remaining = 0;
384
 }
399
 }
385
 
400
 

+ 1
- 1
src/net/validator.c View File

478
 		issuer = link->cert;
478
 		issuer = link->cert;
479
 		if ( ! cert )
479
 		if ( ! cert )
480
 			continue;
480
 			continue;
481
-		if ( ! issuer->valid )
481
+		if ( ! x509_is_valid ( issuer ) )
482
 			continue;
482
 			continue;
483
 		/* The issuer is valid, but this certificate is not
483
 		/* The issuer is valid, but this certificate is not
484
 		 * yet valid.  If OCSP is applicable, start it.
484
 		 * yet valid.  If OCSP is applicable, start it.

+ 1
- 1
src/tests/ocsp_test.c View File

110
 	x509_invalidate ( cert );
110
 	x509_invalidate ( cert );
111
 
111
 
112
 	/* Force-validate issuer certificate */
112
 	/* Force-validate issuer certificate */
113
-	issuer->valid = 1;
113
+	issuer->flags |= X509_FL_VALIDATED;
114
 	issuer->path_remaining = ( issuer->extensions.basic.path_len + 1 );
114
 	issuer->path_remaining = ( issuer->extensions.basic.path_len + 1 );
115
 }
115
 }
116
 
116
 

Loading…
Cancel
Save