iPXE
Functions
imgtrust.c File Reference

Image trust management. More...

#include <stdlib.h>
#include <errno.h>
#include <time.h>
#include <syslog.h>
#include <ipxe/uaccess.h>
#include <ipxe/image.h>
#include <ipxe/cms.h>
#include <ipxe/validator.h>
#include <ipxe/monojob.h>
#include <usr/imgtrust.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
int imgverify (struct image *image, struct image *signature, const char *name)
 Verify image using downloaded signature. More...
 

Detailed Description

Image trust management.

Definition in file imgtrust.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ imgverify()

int imgverify ( struct image image,
struct image signature,
const char *  name 
)

Verify image using downloaded signature.

Parameters
imageImage to verify
signatureImage containing signature
nameRequired common name, or NULL to allow any name
Return values
rcReturn status code

Definition at line 51 of file imgtrust.c.

52  {
53  struct cms_message *cms;
54  struct cms_participant *part;
55  time_t now;
56  int rc;
57 
58  /* Parse signature */
59  if ( ( rc = cms_message ( signature, &cms ) ) != 0 )
60  goto err_parse;
61 
62  /* Complete all certificate chains */
63  list_for_each_entry ( part, &cms->participants, list ) {
64  if ( ( rc = create_validator ( &monojob, part->chain,
65  NULL ) ) != 0 )
66  goto err_create_validator;
67  if ( ( rc = monojob_wait ( NULL, 0 ) ) != 0 )
68  goto err_validator_wait;
69  }
70 
71  /* Use signature to verify image */
72  now = time ( NULL );
73  if ( ( rc = cms_verify ( cms, image, name, now, NULL, NULL ) ) != 0 )
74  goto err_verify;
75 
76  /* Drop reference to message */
77  cms_put ( cms );
78  cms = NULL;
79 
80  /* Record signature verification */
81  syslog ( LOG_NOTICE, "Image \"%s\" signature OK\n", image->name );
82 
83  return 0;
84 
85  err_verify:
86  err_validator_wait:
87  err_create_validator:
88  cms_put ( cms );
89  err_parse:
90  syslog ( LOG_ERR, "Image \"%s\" signature bad: %s\n",
91  image->name, strerror ( rc ) );
92  return rc;
93 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
const char * name
Definition: ath9k_hw.c:1984
int monojob_wait(const char *string, unsigned long timeout)
Wait for single foreground job to complete.
Definition: monojob.c:81
int cms_verify(struct cms_message *cms, struct image *image, const char *name, time_t time, struct x509_chain *store, struct x509_root *root)
Verify CMS signature.
Definition: cms.c:854
An executable image.
Definition: image.h:24
#define LOG_ERR
Error: error conditions.
Definition: syslog.h:35
A CMS message.
Definition: cms.h:55
CMS participant information.
Definition: cms.h:39
int create_validator(struct interface *job, struct x509_chain *chain, struct x509_root *root)
Instantiate a certificate validator.
Definition: validator.c:759
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:431
struct interface monojob
Definition: monojob.c:56
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static void cms_put(struct cms_message *cms)
Drop reference to CMS message.
Definition: cms.h:94
struct list_head participants
List of participant information blocks.
Definition: cms.h:66
struct list_head list
List of participant information blocks.
Definition: cms.h:41
#define syslog(priority, fmt,...)
Write message to system log.
Definition: syslog.h:93
struct x509_chain * chain
Certificate chain.
Definition: cms.h:43
int64_t time_t
Seconds since the Epoch.
Definition: time.h:18
u8 signature
CPU signature.
Definition: CIB_PRM.h:35
char * name
Name.
Definition: image.h:34
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
#define LOG_NOTICE
Notice: normal but significant conditions.
Definition: syslog.h:41

References cms_participant::chain, cms_put(), cms_verify(), create_validator(), cms_participant::list, list_for_each_entry, LOG_ERR, LOG_NOTICE, monojob, monojob_wait(), image::name, name, NULL, cms_message::participants, rc, signature, strerror(), and syslog.

Referenced by imgverify_exec().