aboutsummaryrefslogtreecommitdiffstats
path: root/src/crypto/cms.c
diff options
context:
space:
mode:
authorMichael Brown <mcb30@ipxe.org>2012-05-08 11:12:09 +0100
committerMichael Brown <mcb30@ipxe.org>2012-05-08 12:49:01 +0100
commit1a5f025ad85c484697718eeba13680dc4ffebd24 (patch)
treec938e52c806ff0b3a55f9826868f8b4c4d8d78f6 /src/crypto/cms.c
parent99c798d87a94838be62976cb1632e7d0a9550df3 (diff)
downloadipxe-1a5f025ad85c484697718eeba13680dc4ffebd24.tar.gz
[crypto] Add x509_auto_append()
CMS includes an unordered certificate set, from which certificates must be extracted in order by matching up issuers with subjects. We will use the same functionality as part of the automatic download of cross-signing certificates. Generalise cms_find_subject() to x509_find_subject(), and create x509_auto_append(). Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/crypto/cms.c')
-rw-r--r--src/crypto/cms.c54
1 files changed, 13 insertions, 41 deletions
diff --git a/src/crypto/cms.c b/src/crypto/cms.c
index 9198d03e4..18e59bfba 100644
--- a/src/crypto/cms.c
+++ b/src/crypto/cms.c
@@ -176,31 +176,6 @@ cms_find_issuer_serial ( struct cms_signature *sig,
}
/**
- * Identify CMS signature certificate by subject
- *
- * @v sig CMS signature
- * @v subject Subject
- * @ret cert X.509 certificate, or NULL if not found
- */
-static struct x509_certificate *
-cms_find_subject ( struct cms_signature *sig,
- const struct asn1_cursor *subject ) {
- struct x509_link *link;
- struct x509_certificate *cert;
-
- /* Scan through certificate list */
- list_for_each_entry ( link, &sig->certificates->links, list ) {
-
- /* Check subject */
- cert = link->cert;
- if ( asn1_compare ( subject, &cert->subject.raw ) == 0 )
- return cert;
- }
-
- return NULL;
-}
-
-/**
* Parse CMS signature signer identifier
*
* @v sig CMS signature
@@ -215,7 +190,6 @@ static int cms_parse_signer_identifier ( struct cms_signature *sig,
struct asn1_cursor serial;
struct asn1_cursor issuer;
struct x509_certificate *cert;
- struct x509_certificate *previous;
int rc;
/* Enter issuerAndSerialNumber */
@@ -253,22 +227,20 @@ static int cms_parse_signer_identifier ( struct cms_signature *sig,
return -ENOENT;
}
- /* Create certificate chain */
- do {
- /* Add certificate to chain */
- if ( ( rc = x509_append ( info->chain, cert ) ) != 0 ) {
- DBGC ( sig, "CMS %p/%p could not append certificate: "
- "%s\n", sig, info, strerror ( rc ) );
- return rc;
- }
- DBGC ( sig, "CMS %p/%p added certificate %s\n",
- sig, info, cert->subject.name );
-
- /* Locate next certificate in chain, if any */
- previous = cert;
- cert = cms_find_subject ( sig, &cert->issuer.raw );
+ /* Append certificate to chain */
+ if ( ( rc = x509_append ( info->chain, cert ) ) != 0 ) {
+ DBGC ( sig, "CMS %p/%p could not append certificate: %s\n",
+ sig, info, strerror ( rc ) );
+ return rc;
+ }
- } while ( ( cert != NULL ) && ( cert != previous ) );
+ /* Append remaining certificates to chain */
+ if ( ( rc = x509_auto_append ( info->chain,
+ sig->certificates ) ) != 0 ) {
+ DBGC ( sig, "CMS %p/%p could not append certificates: %s\n",
+ sig, info, strerror ( rc ) );
+ return rc;
+ }
return 0;
}