mirror of
https://github.com/ipxe/ipxe
synced 2026-02-12 21:29:39 +03:00
[x509] Record root of trust used when validating a certificate
Record the root of trust used at the point that a certificate is validated, redefine validation as checking a certificate against a specific root of trust, and pass an explicit root of trust when creating a TLS connection. This allows a custom TLS connection to be used with a custom root of trust, without causing any validated certificates to be treated as valid for normal purposes. Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -73,6 +73,8 @@ struct validator {
|
||||
/** Process */
|
||||
struct process process;
|
||||
|
||||
/** Root of trust (or NULL to use default) */
|
||||
struct x509_root *root;
|
||||
/** X.509 certificate chain */
|
||||
struct x509_chain *chain;
|
||||
/** OCSP check */
|
||||
@@ -554,7 +556,7 @@ static void validator_step ( struct validator *validator ) {
|
||||
*/
|
||||
now = time ( NULL );
|
||||
if ( ( rc = x509_validate_chain ( validator->chain, now, NULL,
|
||||
NULL ) ) == 0 ) {
|
||||
validator->root ) ) == 0 ) {
|
||||
DBGC ( validator, "VALIDATOR %p \"%s\" validated\n",
|
||||
validator, validator_name ( validator ) );
|
||||
validator_finished ( validator, 0 );
|
||||
@@ -569,7 +571,7 @@ static void validator_step ( struct validator *validator ) {
|
||||
issuer = link->cert;
|
||||
if ( ! cert )
|
||||
continue;
|
||||
if ( ! x509_is_valid ( issuer ) )
|
||||
if ( ! x509_is_valid ( issuer, validator->root ) )
|
||||
continue;
|
||||
/* The issuer is valid, but this certificate is not
|
||||
* yet valid. If OCSP is applicable, start it.
|
||||
@@ -621,9 +623,11 @@ static struct process_descriptor validator_process_desc =
|
||||
*
|
||||
* @v job Job control interface
|
||||
* @v chain X.509 certificate chain
|
||||
* @v root Root of trust, or NULL to use default
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
int create_validator ( struct interface *job, struct x509_chain *chain ) {
|
||||
int create_validator ( struct interface *job, struct x509_chain *chain,
|
||||
struct x509_root *root ) {
|
||||
struct validator *validator;
|
||||
int rc;
|
||||
|
||||
@@ -646,6 +650,7 @@ int create_validator ( struct interface *job, struct x509_chain *chain ) {
|
||||
&validator->refcnt );
|
||||
process_init ( &validator->process, &validator_process_desc,
|
||||
&validator->refcnt );
|
||||
validator->root = root;
|
||||
validator->chain = x509_chain_get ( chain );
|
||||
xferbuf_malloc_init ( &validator->buffer );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user