mirror of
https://github.com/ipxe/ipxe
synced 2026-02-10 21:28:44 +03:00
[crypto] Pass image as parameter to CMS functions
The cms_signature() and cms_verify() functions currently accept raw data pointers. This will not be possible for cms_decrypt(), which will need the ability to extract fragments of ASN.1 data from a potentially large image. Change cms_signature() and cms_verify() to accept an image as an input parameter, and move the responsibility for setting the image trust flag within cms_verify() since that now becomes a more natural fit. Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -50,31 +50,15 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||
*/
|
||||
int imgverify ( struct image *image, struct image *signature,
|
||||
const char *name ) {
|
||||
struct asn1_cursor *data;
|
||||
struct cms_signature *sig;
|
||||
struct cms_signer_info *info;
|
||||
time_t now;
|
||||
int next;
|
||||
int rc;
|
||||
|
||||
/* Mark image as untrusted */
|
||||
image_untrust ( image );
|
||||
|
||||
/* Get raw signature data */
|
||||
next = image_asn1 ( signature, 0, &data );
|
||||
if ( next < 0 ) {
|
||||
rc = next;
|
||||
goto err_asn1;
|
||||
}
|
||||
|
||||
/* Parse signature */
|
||||
if ( ( rc = cms_signature ( data->data, data->len, &sig ) ) != 0 )
|
||||
if ( ( rc = cms_signature ( signature, &sig ) ) != 0 )
|
||||
goto err_parse;
|
||||
|
||||
/* Free raw signature data */
|
||||
free ( data );
|
||||
data = NULL;
|
||||
|
||||
/* Complete all certificate chains */
|
||||
list_for_each_entry ( info, &sig->info, list ) {
|
||||
if ( ( rc = create_validator ( &monojob, info->chain,
|
||||
@@ -86,16 +70,14 @@ int imgverify ( struct image *image, struct image *signature,
|
||||
|
||||
/* Use signature to verify image */
|
||||
now = time ( NULL );
|
||||
if ( ( rc = cms_verify ( sig, image->data, image->len,
|
||||
name, now, NULL, NULL ) ) != 0 )
|
||||
if ( ( rc = cms_verify ( sig, image, name, now, NULL, NULL ) ) != 0 )
|
||||
goto err_verify;
|
||||
|
||||
/* Drop reference to signature */
|
||||
cms_put ( sig );
|
||||
sig = NULL;
|
||||
|
||||
/* Mark image as trusted */
|
||||
image_trust ( image );
|
||||
/* Record signature verification */
|
||||
syslog ( LOG_NOTICE, "Image \"%s\" signature OK\n", image->name );
|
||||
|
||||
return 0;
|
||||
@@ -105,8 +87,6 @@ int imgverify ( struct image *image, struct image *signature,
|
||||
err_create_validator:
|
||||
cms_put ( sig );
|
||||
err_parse:
|
||||
free ( data );
|
||||
err_asn1:
|
||||
syslog ( LOG_ERR, "Image \"%s\" signature bad: %s\n",
|
||||
image->name, strerror ( rc ) );
|
||||
return rc;
|
||||
|
||||
Reference in New Issue
Block a user