Showing with 224 additions and 310 deletions.
  1. +4 −4 Makefile.am
  2. +4 −13 man/tpm2_startup.8.in
  3. +2 −2 test/system/test_tpm2_startup.sh
  4. +40 −42 tools/tpm2_send_command.c
  5. +137 −158 tools/tpm2_sign.c
  6. +37 −91 tools/tpm2_startup.c
8 changes: 4 additions & 4 deletions Makefile.am
Expand Up @@ -63,6 +63,9 @@ bin_PROGRAMS = \
tools/tpm2_getpubek \
tools/tpm2_getrandom \
tools/tpm2_hmac \
tools/tpm2_send_command \
tools/tpm2_sign \
tools/tpm2_startup \
tools/tpm2_takeownership \
tools/tpm2_unseal \
tools/tpm2_verifysignature
Expand All @@ -85,10 +88,7 @@ bin_PROGRAMS = \
# tools/tpm2_rc_decode \
# tools/tpm2_readpublic \
# tools/tpm2_rsadecrypt \
# tools/tpm2_rsaencrypt \
# tools/tpm2_send_command \
# tools/tpm2_sign \
# tools/tpm2_startup
# tools/tpm2_rsaencrypt

tcti_src = ""
if HAVE_TCTI_DEV
Expand Down
17 changes: 4 additions & 13 deletions man/tpm2_startup.8.in
Expand Up @@ -32,24 +32,15 @@
tpm2_startup \- Send a TPM2_Startup command with either TPM_SU_CLEAR or
TPM_SU_STATE.
.SH SYNOPSIS
.B tpm2_startup [ \fBCOMMON OPTIONS\fR ] [ \fBTCTI OPTIONS\fR ] [ \fB\-\-clear\fR|\fB\-\-state\fR ]
.B tpm2_startup [ \fBCOMMON OPTIONS\fR ] [ \fBTCTI OPTIONS\fR ] [ \fB\-\-clear\fR ]
.PP
Send a TPM2_Startup command, with the startupType set to TPM_SU_CLEAR using
the specified TCTI.
Send a TPM2_Startup command.
.SH DESCRIPTION
.B tpm2_send_command
is a command line tool used to send a TPM command to the TPM. The command is
read from stdin as a binary stream and transmitted to the TPM using the TCTI
specified by the caller. The response received from the TPM is written to
stdout. Likely the caller will want to redirect this to a file or into a
program to decode and display the response in a human readable form.
Send a startup command to the tpm.
.SH OPTIONS
.TP
\fB\-c,\ \-\-clear\fR
Startup type sent will be TPM_SU_CLEAR.
.TP
\fB\-s,\ \-\-state\fR
Startup type sent will be TPM2_SU_STATE.
Startup type sent will be TPM_SU_CLEAR instead of TPM2_SU_STATE.
@COMMON_OPTIONS_INCLUDE@
@TCTI_OPTIONS_INCLUDE@
.SH ENVIRONMENT
Expand Down
4 changes: 2 additions & 2 deletions test/system/test_tpm2_startup.sh
Expand Up @@ -37,9 +37,9 @@ if [ $? -ne 0 ]; then
exit 1
fi

tpm2_startup --state
tpm2_startup
if [ $? -ne 0 ]; then
echo "tpm2_startup --state failed."
echo "tpm2_startup default failed."
exit 1
fi

Expand Down
82 changes: 40 additions & 42 deletions tools/tpm2_send_command.c
Expand Up @@ -49,6 +49,8 @@ struct tpm2_send_command_ctx {
FILE *output;
};

tpm2_send_command_ctx ctx;

static bool read_command_from_file(FILE *f, tpm2_command_header **c,
UINT32 *size) {

Expand Down Expand Up @@ -119,35 +121,42 @@ static void close_file(FILE *f) {
}
}

static bool init(tpm2_send_command_ctx *ctx, int argc, char *argv[]) {

static const char *optstring = "i:o:";
static const struct option long_options[] = { { "--input",
required_argument, NULL, 'i' }, { "--output", required_argument,
NULL, 'o' }, { NULL, no_argument, NULL, '\0' }, };

int opt;
while ((opt = getopt_long(argc, argv, optstring, long_options, NULL)) != -1) {
switch (opt) {
case 'i':
ctx->input = open_file(optarg, "rb");
break;
case 'o':
ctx->output = open_file(optarg, "wb");
break;
case ':':
LOG_ERR("Argument %c needs a value!", optopt);
return false;
case '?':
LOG_ERR("Unknown Argument: %c", optopt);
return false;
default:
LOG_ERR("?? getopt returned character code 0%o ??", opt);
return false;
}
static bool on_option(char key, char *value) {

switch (key) {
case 'i':
ctx.input = open_file(value, "rb");
if (!ctx.input) {
return false;
}
break;
case 'o':
ctx.output = open_file(value, "wb");
if (!ctx.output) {
return false;
}
break;
/* no break */
}

return ctx->input && ctx->output;
return true;
}

bool tpm2_tool_onstart(tpm2_options **opts) {

static const struct option topts[] = {
{ "--input", required_argument, NULL, 'i' },
{ "--output", required_argument, NULL, 'o' },
{ NULL }
};

*opts = tpm2_options_new("i:o:", ARRAY_LEN(topts), topts,
on_option, NULL);

ctx.input = stdin;
ctx.output = stdout;

return *opts != NULL;
}

/*
Expand All @@ -157,26 +166,15 @@ static bool init(tpm2_send_command_ctx *ctx, int argc, char *argv[]) {
* in network byte order (big-endian). We output the response in the same
* form.
*/
int execute_tool(int argc, char *argv[], char *envp[], common_opts_t *opts,
TSS2_SYS_CONTEXT *sapi_context) {
(void) envp;
(void) opts;

int ret = 1;
int tpm2_tool_onrun(TSS2_SYS_CONTEXT *sapi_context, tpm2_option_flags flags) {

tpm2_send_command_ctx ctx = {
.input = stdin,
.output = stdout
};
UNUSED(flags);

bool result = init(&ctx, argc, argv);
if (!result) {
goto out_files;
}
int ret = 1;

UINT32 size;
tpm2_command_header *command;
result = read_command_from_file(ctx.input, &command, &size);
bool result = read_command_from_file(ctx.input, &command, &size);
if (!result) {
LOG_ERR("failed to read TPM2 command buffer from file");
goto out_files;
Expand Down