iPXE
Data Structures | Functions | Variables
image_crypt_cmd.c File Reference

Image encryption management commands. More...

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

Go to the source code of this file.

Data Structures

struct  imgdecrypt_options
 "imgdecrypt" options More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static int imgdecrypt_exec (int argc, char **argv)
 The "imgdecrypt" command. More...
 

Variables

static struct option_descriptor imgdecrypt_opts []
 "imgdecrypt" option list More...
 
static struct command_descriptor imgdecrypt_cmd
 "imgdecrypt" command descriptor More...
 
struct command image_crypt_commands [] __command
 Image encryption management commands. More...
 

Detailed Description

Image encryption management commands.

Definition in file image_crypt_cmd.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ imgdecrypt_exec()

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

The "imgdecrypt" command.

Parameters
argcArgument count
argvArgument list
Return values
rcReturn status code

Definition at line 73 of file image_crypt_cmd.c.

73  {
74  struct imgdecrypt_options opts;
75  const char *image_name_uri;
76  const char *envelope_name_uri;
77  struct image *image;
78  struct image *envelope;
79  int rc;
80 
81  /* Parse options */
82  if ( ( rc = parse_options ( argc, argv, &imgdecrypt_cmd, &opts ) ) != 0)
83  return rc;
84 
85  /* Parse image name/URI string */
86  image_name_uri = argv[optind];
87 
88  /* Parse envelope name/URI string */
89  envelope_name_uri = argv[ optind + 1 ];
90 
91  /* Acquire the image */
92  if ( ( rc = imgacquire ( image_name_uri, opts.timeout, &image ) ) != 0 )
93  goto err_acquire_image;
94 
95  /* Acquire the envelope image */
96  if ( ( rc = imgacquire ( envelope_name_uri, opts.timeout,
97  &envelope ) ) != 0 )
98  goto err_acquire_envelope;
99 
100  /* Decrypt image */
101  if ( ( rc = imgdecrypt ( image, envelope, opts.name ) ) != 0 ) {
102  printf ( "Could not decrypt: %s\n", strerror ( rc ) );
103  goto err_decrypt;
104  }
105 
106  /* Success */
107  rc = 0;
108 
109  err_decrypt:
110  /* Discard envelope unless --keep was specified */
111  if ( ! opts.keep )
112  unregister_image ( envelope );
113  err_acquire_envelope:
114  err_acquire_image:
115  return rc;
116 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
int optind
Current option index.
Definition: getopt.c:51
"imgdecrypt" options
int parse_options(int argc, char **argv, struct command_descriptor *cmd, void *opts)
Parse command-line options.
Definition: parseopt.c:484
An executable image.
Definition: image.h:24
int imgdecrypt(struct image *image, struct image *envelope, const char *name)
Decrypt image using downloaded envelope.
Definition: imgcrypt.c:47
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
void unregister_image(struct image *image)
Unregister executable image.
Definition: image.c:322
static struct command_descriptor imgdecrypt_cmd
"imgdecrypt" command descriptor
static union @438 opts
"cert<xxx>" option list
int imgacquire(const char *name_uri, unsigned long timeout, struct image **image)
Acquire an image.
Definition: imgmgmt.c:141

References imgacquire(), imgdecrypt(), imgdecrypt_cmd, optind, opts, parse_options(), printf(), rc, strerror(), and unregister_image().

Variable Documentation

◆ imgdecrypt_opts

struct option_descriptor imgdecrypt_opts[]
static
Initial value:
= {
OPTION_DESC ( "keep", 'k', no_argument,
struct imgdecrypt_options, keep, parse_flag ),
OPTION_DESC ( "timeout", 't', required_argument,
}
const char * name
Definition: ath9k_hw.c:1984
"imgdecrypt" options
int parse_timeout(char *text, unsigned long *value)
Parse timeout value (in ms)
Definition: parseopt.c:114
int parse_string(char *text, char **value)
Parse string value.
Definition: parseopt.c:73
int parse_flag(char *text __unused, int *flag)
Parse flag.
Definition: parseopt.c:226
Option does not take an argument.
Definition: getopt.h:16
#define OPTION_DESC(_longopt, _shortopt, _has_arg, _struct, _field, _parse)
Construct option descriptor.
Definition: parseopt.h:67
Option requires an argument.
Definition: getopt.h:18
void timeout(int)

"imgdecrypt" option list

Definition at line 52 of file image_crypt_cmd.c.

◆ imgdecrypt_cmd

struct command_descriptor imgdecrypt_cmd
static
Initial value:
=
"<uri|image> <envelope uri|image>" )
"imgdecrypt" options
static struct option_descriptor imgdecrypt_opts[]
"imgdecrypt" option list
#define COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage)
Construct command descriptor.
Definition: parseopt.h:108

"imgdecrypt" command descriptor

Definition at line 62 of file image_crypt_cmd.c.

Referenced by imgdecrypt_exec().

◆ __command

struct command image_crypt_commands [] __command
Initial value:
= {
{
.name = "imgdecrypt",
.exec = imgdecrypt_exec,
},
}
static int imgdecrypt_exec(int argc, char **argv)
The "imgdecrypt" command.

Image encryption management commands.

Definition at line 119 of file image_crypt_cmd.c.