Browse Source

[crypto] Validate path length constraint in certificate chain

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 13 years ago
parent
commit
b1316ef276
1 changed files with 14 additions and 0 deletions
  1. 14
    0
      src/crypto/x509.c

+ 14
- 0
src/crypto/x509.c View File

89
 	__einfo_error ( EINFO_EACCES_EXPIRED )
89
 	__einfo_error ( EINFO_EACCES_EXPIRED )
90
 #define EINFO_EACCES_EXPIRED \
90
 #define EINFO_EACCES_EXPIRED \
91
 	__einfo_uniqify ( EINFO_EACCES, 0x04, "Expired (or not yet valid)" )
91
 	__einfo_uniqify ( EINFO_EACCES, 0x04, "Expired (or not yet valid)" )
92
+#define EACCES_PATH_LEN \
93
+	__einfo_error ( EINFO_EACCES_PATH_LEN )
94
+#define EINFO_EACCES_PATH_LEN \
95
+	__einfo_uniqify ( EINFO_EACCES, 0x05, "Maximum path length exceeded" )
92
 
96
 
93
 /** "commonName" object identifier */
97
 /** "commonName" object identifier */
94
 static uint8_t oid_common_name[] = { ASN1_OID_COMMON_NAME };
98
 static uint8_t oid_common_name[] = { ASN1_OID_COMMON_NAME };
1187
 	struct x509_certificate *current = &temp[0];
1191
 	struct x509_certificate *current = &temp[0];
1188
 	struct x509_certificate *next = &temp[1];
1192
 	struct x509_certificate *next = &temp[1];
1189
 	struct x509_certificate *swap;
1193
 	struct x509_certificate *swap;
1194
+	unsigned int path_len = 0;
1190
 	int rc;
1195
 	int rc;
1191
 
1196
 
1192
 	/* Use default root certificate store if none specified */
1197
 	/* Use default root certificate store if none specified */
1226
 		if ( ( rc = x509_validate_issuer ( current, next ) ) != 0 )
1231
 		if ( ( rc = x509_validate_issuer ( current, next ) ) != 0 )
1227
 			return rc;
1232
 			return rc;
1228
 
1233
 
1234
+		/* Validate path length constraint */
1235
+		if ( path_len > next->extensions.basic.path_len ) {
1236
+			DBGC ( context, "X509 chain %p path length %d exceeds "
1237
+			       "maximum %d\n", context, path_len,
1238
+			       next->extensions.basic.path_len );
1239
+			return -EACCES_PATH_LEN;
1240
+		}
1241
+		path_len++;
1242
+
1229
 		/* Move to next certificate in chain */
1243
 		/* Move to next certificate in chain */
1230
 		swap = current;
1244
 		swap = current;
1231
 		current = next;
1245
 		current = next;

Loading…
Cancel
Save