iPXE
image_trust_cmd.c File Reference

Image trust management commands. More...

#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <getopt.h>
#include <ipxe/image.h>
#include <ipxe/command.h>
#include <ipxe/parseopt.h>
#include <usr/imgmgmt.h>
#include <usr/imgtrust.h>

Go to the source code of this file.

Data Structures

struct  imgtrust_options
 "imgtrust" options More...
struct  imgverify_options
 "imgverify" options More...

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
static int imgtrust_exec (int argc, char **argv)
 The "imgtrust" command.
static int imgverify_exec (int argc, char **argv)
 The "imgverify" command.
 COMMAND (imgtrust, imgtrust_exec)
 Image trust management commands.
 COMMAND (imgverify, imgverify_exec)

Variables

static struct option_descriptor imgtrust_opts []
 "imgtrust" option list
static struct command_descriptor imgtrust_cmd
 "imgtrust" command descriptor
static struct option_descriptor imgverify_opts []
 "imgverify" option list
static struct command_descriptor imgverify_cmd
 "imgverify" command descriptor

Detailed Description

Image trust management commands.

Definition in file image_trust_cmd.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ imgtrust_exec()

int imgtrust_exec ( int argc,
char ** argv )
static

The "imgtrust" command.

Parameters
argcArgument count
argvArgument list
Return values
rcReturn status code

Definition at line 70 of file image_trust_cmd.c.

70 {
72 int rc;
73
74 /* Parse options */
75 if ( ( rc = parse_options ( argc, argv, &imgtrust_cmd, &opts ) ) != 0 )
76 return rc;
77
78 /* Set trust requirement */
79 if ( ( rc = image_set_trust ( ( ! opts.allow ),
80 opts.permanent ) ) != 0 ) {
81 printf ( "Could not set image trust requirement: %s\n",
82 strerror ( rc ) );
83 return rc;
84 }
85
86 return 0;
87}
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
static union @024010030001061367220137227263210031030210157031 opts
"cert<xxx>" option list
int image_set_trust(int require_trusted, int permanent)
Change image trust requirement.
Definition image.c:584
static struct command_descriptor imgtrust_cmd
"imgtrust" command descriptor
int parse_options(int argc, char **argv, struct command_descriptor *cmd, void *opts)
Parse command-line options.
Definition parseopt.c:485
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
"imgtrust" options
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition vsprintf.c:465

References image_set_trust(), imgtrust_cmd, opts, parse_options(), printf(), rc, and strerror().

Referenced by COMMAND().

◆ imgverify_exec()

int imgverify_exec ( int argc,
char ** argv )
static

The "imgverify" command.

Parameters
argcArgument count
argvArgument list
Return values
rcReturn status code

Definition at line 121 of file image_trust_cmd.c.

121 {
122 struct imgverify_options opts;
123 const char *image_name_uri;
124 const char *signature_name_uri;
125 struct image *image;
126 struct image *signature;
127 int rc;
128
129 /* Parse options */
130 if ( ( rc = parse_options ( argc, argv, &imgverify_cmd, &opts ) ) != 0 )
131 return rc;
132
133 /* Parse image name/URI string */
134 image_name_uri = argv[optind];
135
136 /* Parse signature name/URI string */
137 signature_name_uri = argv[ optind + 1 ];
138
139 /* Acquire the image */
140 if ( ( rc = imgacquire ( image_name_uri, opts.timeout, &image ) ) != 0 )
141 goto err_acquire_image;
142
143 /* Acquire the signature image */
144 if ( ( rc = imgacquire ( signature_name_uri, opts.timeout,
145 &signature ) ) != 0 )
146 goto err_acquire_signature;
147
148 /* Verify image */
149 if ( ( rc = imgverify ( image, signature, opts.signer ) ) != 0 ) {
150 printf ( "Could not verify: %s\n", strerror ( rc ) );
151 goto err_verify;
152 }
153
154 /* Success */
155 rc = 0;
156
157 err_verify:
158 /* Discard signature unless --keep was specified */
159 if ( ! opts.keep )
161 err_acquire_signature:
162 err_acquire_image:
163 return rc;
164}
u8 signature
CPU signature.
Definition CIB_PRM.h:7
int optind
Current option index.
Definition getopt.c:52
void unregister_image(struct image *image)
Unregister executable image.
Definition image.c:358
static struct command_descriptor imgverify_cmd
"imgverify" command descriptor
int imgacquire(const char *name_uri, unsigned long timeout, struct image **image)
Acquire an image.
Definition imgmgmt.c:143
int imgverify(struct image *image, struct image *signature, const char *name)
Verify image using downloaded signature.
Definition imgtrust.c:52
An executable image.
Definition image.h:24
"imgverify" options

References imgacquire(), imgverify(), imgverify_cmd, optind, opts, parse_options(), printf(), rc, signature, strerror(), and unregister_image().

Referenced by COMMAND().

◆ COMMAND() [1/2]

COMMAND ( imgtrust ,
imgtrust_exec  )

Image trust management commands.

References imgtrust_exec().

◆ COMMAND() [2/2]

COMMAND ( imgverify ,
imgverify_exec  )

References imgverify(), and imgverify_exec().

Variable Documentation

◆ imgtrust_opts

struct option_descriptor imgtrust_opts[]
static
Initial value:
= {
OPTION_DESC ( "allow", 'a', no_argument,
struct imgtrust_options, allow, parse_flag ),
OPTION_DESC ( "permanent", 'p', no_argument,
struct imgtrust_options, permanent, parse_flag ),
}
@ no_argument
Option does not take an argument.
Definition getopt.h:17
int parse_flag(char *text __unused, int *flag)
Parse flag.
Definition parseopt.c:227
#define OPTION_DESC(_longopt, _shortopt, _has_arg, _struct, _field, _parse)
Construct option descriptor.
Definition parseopt.h:68

"imgtrust" option list

Definition at line 52 of file image_trust_cmd.c.

52 {
53 OPTION_DESC ( "allow", 'a', no_argument,
54 struct imgtrust_options, allow, parse_flag ),
55 OPTION_DESC ( "permanent", 'p', no_argument,
56 struct imgtrust_options, permanent, parse_flag ),
57};

◆ imgtrust_cmd

struct command_descriptor imgtrust_cmd
static
Initial value:
=
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
static struct option_descriptor imgtrust_opts[]
"imgtrust" option list
#define COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage)
Construct command descriptor.
Definition parseopt.h:109

"imgtrust" command descriptor

Definition at line 60 of file image_trust_cmd.c.

Referenced by imgtrust_exec().

◆ imgverify_opts

struct option_descriptor imgverify_opts[]
static
Initial value:
= {
OPTION_DESC ( "signer", 's', required_argument,
struct imgverify_options, signer, parse_string ),
OPTION_DESC ( "keep", 'k', no_argument,
struct imgverify_options, keep, parse_flag ),
OPTION_DESC ( "timeout", 't', required_argument,
}
void timeout(int)
@ required_argument
Option requires an argument.
Definition getopt.h:19
int parse_string(char *text, char **value)
Parse string value.
Definition parseopt.c:74
int parse_timeout(char *text, unsigned long *value)
Parse timeout value (in ms)
Definition parseopt.c:115

"imgverify" option list

Definition at line 100 of file image_trust_cmd.c.

100 {
101 OPTION_DESC ( "signer", 's', required_argument,
102 struct imgverify_options, signer, parse_string ),
103 OPTION_DESC ( "keep", 'k', no_argument,
104 struct imgverify_options, keep, parse_flag ),
105 OPTION_DESC ( "timeout", 't', required_argument,
107};

◆ imgverify_cmd

struct command_descriptor imgverify_cmd
static
Initial value:
=
"<uri|image> <signature uri|image>" )
static struct option_descriptor imgverify_opts[]
"imgverify" option list

"imgverify" command descriptor

Definition at line 110 of file image_trust_cmd.c.

Referenced by imgverify_exec().