2
* Copyright (C) 2012 Michael Brown <mbrown@fensystems.co.uk>.
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License as
6
* published by the Free Software Foundation; either version 2 of the
7
* License, or any later version.
9
* This program is distributed in the hope that it will be useful, but
10
* WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20
FILE_LICENCE ( GPL2_OR_LATER );
25
#include <ipxe/image.h>
26
#include <ipxe/command.h>
27
#include <ipxe/parseopt.h>
28
#include <usr/imgmgmt.h>
29
#include <usr/imgtrust.h>
33
* Image trust management commands
37
/** "imgtrust" options */
38
struct imgtrust_options {
39
/** Allow trusted images */
41
/** Make trust requirement permanent */
45
/** "imgtrust" option list */
46
static struct option_descriptor imgtrust_opts[] = {
47
OPTION_DESC ( "allow", 'a', no_argument,
48
struct imgtrust_options, allow, parse_flag ),
49
OPTION_DESC ( "permanent", 'p', no_argument,
50
struct imgtrust_options, permanent, parse_flag ),
53
/** "imgtrust" command descriptor */
54
static struct command_descriptor imgtrust_cmd =
55
COMMAND_DESC ( struct imgtrust_options, imgtrust_opts, 0, 0,
56
"[--allow] [--permanent]" );
59
* The "imgtrust" command
61
* @v argc Argument count
62
* @v argv Argument list
63
* @ret rc Return status code
65
static int imgtrust_exec ( int argc, char **argv ) {
66
struct imgtrust_options opts;
70
if ( ( rc = parse_options ( argc, argv, &imgtrust_cmd, &opts ) ) != 0 )
73
/* Set trust requirement */
74
if ( ( rc = image_set_trust ( ( ! opts.allow ),
75
opts.permanent ) ) != 0 ) {
76
printf ( "Could not set image trust requirement: %s\n",
84
/** "imgverify" options */
85
struct imgverify_options {
86
/** Required signer common name */
88
/** Keep signature after verification */
92
/** "imgverify" option list */
93
static struct option_descriptor imgverify_opts[] = {
94
OPTION_DESC ( "signer", 's', required_argument,
95
struct imgverify_options, signer, parse_string ),
96
OPTION_DESC ( "keep", 'k', no_argument,
97
struct imgverify_options, keep, parse_flag ),
100
/** "imgverify" command descriptor */
101
static struct command_descriptor imgverify_cmd =
102
COMMAND_DESC ( struct imgverify_options, imgverify_opts, 2, 2,
103
"[--signer <signer>] [--keep] <uri|image> "
104
"<signature uri|image>" );
107
* The "imgverify" command
109
* @v argc Argument count
110
* @v argv Argument list
111
* @ret rc Return status code
113
static int imgverify_exec ( int argc, char **argv ) {
114
struct imgverify_options opts;
115
const char *image_name_uri;
116
const char *signature_name_uri;
118
struct image *signature;
122
if ( ( rc = parse_options ( argc, argv, &imgverify_cmd, &opts ) ) != 0 )
125
/* Parse image name/URI string */
126
image_name_uri = argv[optind];
128
/* Parse signature name/URI string */
129
signature_name_uri = argv[ optind + 1 ];
131
/* Acquire the image */
132
if ( ( rc = imgacquire ( image_name_uri, &image ) ) != 0 )
133
goto err_acquire_image;
135
/* Acquire the signature image */
136
if ( ( rc = imgacquire ( signature_name_uri, &signature ) ) != 0 )
137
goto err_acquire_signature;
140
if ( ( rc = imgverify ( image, signature, opts.signer ) ) != 0 ) {
141
printf ( "Could not verify: %s\n", strerror ( rc ) );
149
/* Discard signature unless --keep was specified */
151
unregister_image ( signature );
152
err_acquire_signature:
157
/** Image trust management commands */
158
struct command image_trust_commands[] __command = {
161
.exec = imgtrust_exec,
165
.exec = imgverify_exec,
169
/* Drag in objects typically required for signature verification */
170
REQUIRE_OBJECT ( rsa );
171
REQUIRE_OBJECT ( md5 );
172
REQUIRE_OBJECT ( sha1 );
173
REQUIRE_OBJECT ( sha256 );