mirror of
https://github.com/ipxe/ipxe
synced 2026-01-25 07:31:04 +03:00
[crypto] Add x509_truncate() to truncate a certificate chain
Downloading a cross-signed certificate chain to partially replace (rather than simply extend) an existing chain will require the ability to discard all certificates after a specified link in the chain. Extract the relevant logic from x509_free_chain() and expose it separately as x509_truncate(). Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -984,6 +984,7 @@ static void x509_validate_chain_fail_okx ( struct x509_test_chain *chn,
|
||||
*
|
||||
*/
|
||||
static void x509_test_exec ( void ) {
|
||||
struct x509_link *link;
|
||||
|
||||
/* Parse all certificates */
|
||||
x509_certificate_ok ( &root_crt );
|
||||
@@ -1089,6 +1090,18 @@ static void x509_test_exec ( void ) {
|
||||
x509_validate_chain_fail_ok ( &useless_chain, test_ca_expired,
|
||||
&empty_store, &test_root );
|
||||
|
||||
/* Check chain truncation */
|
||||
link = list_last_entry ( &server_chain.chain->links,
|
||||
struct x509_link, list );
|
||||
ok ( link->cert == root_crt.cert );
|
||||
link = list_prev_entry ( link, &server_chain.chain->links, list );
|
||||
ok ( link->cert == intermediate_crt.cert );
|
||||
x509_validate_chain_ok ( &server_chain, test_time,
|
||||
&empty_store, &test_root );
|
||||
x509_truncate ( server_chain.chain, link );
|
||||
x509_validate_chain_fail_ok ( &server_chain, test_time,
|
||||
&empty_store, &test_root );
|
||||
|
||||
/* Sanity check */
|
||||
assert ( list_empty ( &empty_store.links ) );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user