Skip to content

Commit

Permalink
cli: Add token file generation for secure unlock version update
Browse files Browse the repository at this point in the history
  • Loading branch information
kelvin-cao committed Jul 14, 2023
1 parent 5ed09c6 commit 5e6a576
Showing 1 changed file with 32 additions and 6 deletions.
38 changes: 32 additions & 6 deletions cli/mfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1439,7 +1439,11 @@ static int no_openssl(int argc, char **argv)

#endif

#define CMD_DESC_DEBUG_TOKEN "generate debug unlock token file for the device"

#define TOKEN_RESROUCE_UNLOCK 0
#define TOKEN_VERSION_UPDATE 1

#define CMD_DESC_DEBUG_TOKEN "generate device token file for signature"
static int debug_unlock_token(int argc, char **argv)
{
int ret;
Expand All @@ -1453,16 +1457,32 @@ static int debug_unlock_token(int argc, char **argv)

const char *desc = CMD_DESC_DEBUG_TOKEN "\n\n"
"Use the generated token file on your security "
"management system to generate the signature file "
"required for command 'mfg debug-unlock'";
"management system to generate the signature file ";

const struct argconfig_choice type[] = {
{"RESROUCE_UNLOCK", TOKEN_RESROUCE_UNLOCK,
"Generate token for signature file requred for command 'mfg debug-unlock' (default)"},
{"UNLOCK_VERSION_UPDATE", TOKEN_VERSION_UPDATE,
"Generate token for signature file requred for command 'mfg debug-lock-update'"},
{}
};

struct {
struct switchtec_dev *dev;
int out_fd;
const char *out_filename;
} cfg = {};
int unlock;
int update;
int type;
} cfg = {
.type = TOKEN_RESROUCE_UNLOCK,
};

const struct argconfig_options opts[] = {
DEVICE_OPTION_MFG_PCI,
{"type", 't', "TYPE", CFG_CHOICES, &cfg.type,
required_argument,
"output token file type", .choices=type},
{"token_file", .cfg_type=CFG_FD_WR, .value_addr=&cfg.out_fd,
.argument_type=optional_positional,
.force_default="debug.tkn",
Expand All @@ -1477,9 +1497,15 @@ static int debug_unlock_token(int argc, char **argv)
return ret;
}

token.id = htole32(1);
token.serial = htole32(sn_info.chip_serial);
token.version = htole32(sn_info.ver_sec_unlock);

if (cfg.type == TOKEN_RESROUCE_UNLOCK) {
token.id = htole32(1);
token.version = htole32(sn_info.ver_sec_unlock);
} else {
token.id = htole32(2);
token.version = htole32(sn_info.ver_sec_unlock) + 1;
}

ret = write(cfg.out_fd, &token, sizeof(token));
if(ret <= 0) {
Expand Down

0 comments on commit 5e6a576

Please sign in to comment.