Skip to content

Commit 4b54315

Browse files
JuergenReppSITAndreasFuchsTPM
authored andcommitted
pcr commands: session support added.
Session support is added for the following commands: tpm2_pcrextend, tpm2_event, and tpm2_pcrread. Examples for usage: tpm2_startauthsession -Q --session audit_session.ctx --audit tpm2_pcrread sha256:0 -o pcr0 -S audit_session.ctx tpm2_startauthsession -Q --session hmac_session.ctx --hmac tpm2_startauthsession -Q --session audit_session.ctx --audit tpm2_pcrextend -S audit_session.ctx -P session:hmac_session.ctx \ 16:sha256=b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c tpm2_startauthsession -Q --session hmac_session.ctx --hmac tpm2_startauthsession -Q --session audit_session.ctx --audit echo event |tpm2_pcrevent -S audit_session.ctx -Psession:hmac_session.ctx 10 Signed-off-by: Juergen Repp <[email protected]>
1 parent 10c21a0 commit 4b54315

File tree

14 files changed

+217
-34
lines changed

14 files changed

+217
-34
lines changed

lib/pcr.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,9 @@ bool pcr_check_pcr_selection(TPMS_CAPABILITY_DATA *cap_data,
605605

606606
tool_rc pcr_read_pcr_values(ESYS_CONTEXT *esys_context,
607607
TPML_PCR_SELECTION *pcr_select, tpm2_pcrs *pcrs, TPM2B_DIGEST *cp_hash,
608-
TPMI_ALG_HASH parameter_hash_algorithm) {
608+
TPMI_ALG_HASH parameter_hash_algorithm,
609+
ESYS_TR session_handle_1, ESYS_TR session_handle_2,
610+
ESYS_TR session_handle_3) {
609611

610612
TPML_PCR_SELECTION pcr_selection_tmp;
611613
TPML_PCR_SELECTION *pcr_selection_out;
@@ -618,8 +620,8 @@ tool_rc pcr_read_pcr_values(ESYS_CONTEXT *esys_context,
618620
pcrs->count = 0;
619621
do {
620622
TPML_DIGEST *v;
621-
tool_rc rc = tpm2_pcr_read(esys_context, ESYS_TR_NONE, ESYS_TR_NONE,
622-
ESYS_TR_NONE, &pcr_selection_tmp, &pcr_update_counter,
623+
tool_rc rc = tpm2_pcr_read(esys_context, session_handle_1, session_handle_2,
624+
session_handle_3, &pcr_selection_tmp, &pcr_update_counter,
623625
&pcr_selection_out, &v, cp_hash, parameter_hash_algorithm);
624626

625627
if (rc != tool_rc_success || (cp_hash && cp_hash->size)) {

lib/pcr.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ bool pcr_check_pcr_selection(TPMS_CAPABILITY_DATA *cap_data,
114114

115115
tool_rc pcr_read_pcr_values(ESYS_CONTEXT *esys_context,
116116
TPML_PCR_SELECTION *pcr_selections, tpm2_pcrs *pcrs,
117-
TPM2B_DIGEST *cp_hash, TPMI_ALG_HASH parameter_hash_algorithm);
117+
TPM2B_DIGEST *cp_hash, TPMI_ALG_HASH parameter_hash_algorithm,
118+
ESYS_TR session_handle_1, ESYS_TR session_handle_2,
119+
ESYS_TR session_handle_3);
118120

119121
#endif /* SRC_PCR_H_ */

lib/tpm2.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5115,10 +5115,21 @@ tool_rc tpm2_loadexternal(ESYS_CONTEXT *ectx, const TPM2B_SENSITIVE *private,
51155115
}
51165116

51175117
tool_rc tpm2_pcr_extend(ESYS_CONTEXT *ectx, TPMI_DH_PCR pcr_index,
5118-
TPML_DIGEST_VALUES *digests) {
5118+
tpm2_session *session,
5119+
TPML_DIGEST_VALUES *digests,
5120+
ESYS_TR session_handle_2,
5121+
ESYS_TR session_handle_3) {
51195122

5120-
TSS2_RC rval = Esys_PCR_Extend(ectx, pcr_index, ESYS_TR_PASSWORD,
5121-
ESYS_TR_NONE, ESYS_TR_NONE, digests);
5123+
ESYS_TR shandle1 = ESYS_TR_NONE;
5124+
tool_rc rc = tpm2_auth_util_get_shandle(ectx, pcr_index, session,
5125+
&shandle1);
5126+
if (rc != tool_rc_success) {
5127+
return rc;
5128+
}
5129+
5130+
5131+
TSS2_RC rval = Esys_PCR_Extend(ectx, pcr_index, shandle1,
5132+
session_handle_2, session_handle_3, digests);
51225133
if (rval != TSS2_RC_SUCCESS) {
51235134
LOG_PERR(Esys_PCR_Extend, rval);
51245135
return tool_rc_from_tpm(rval);
@@ -5129,7 +5140,8 @@ tool_rc tpm2_pcr_extend(ESYS_CONTEXT *ectx, TPMI_DH_PCR pcr_index,
51295140

51305141
tool_rc tpm2_pcr_event(ESYS_CONTEXT *ectx, ESYS_TR pcr, tpm2_session *session,
51315142
const TPM2B_EVENT *event_data, TPML_DIGEST_VALUES **digests,
5132-
TPM2B_DIGEST *cp_hash, TPMI_ALG_HASH parameter_hash_algorithm) {
5143+
TPM2B_DIGEST *cp_hash, TPMI_ALG_HASH parameter_hash_algorithm,
5144+
ESYS_TR session_handle_2, ESYS_TR session_handle_3) {
51335145

51345146
TSS2_RC rval = TSS2_RC_SUCCESS;
51355147
tool_rc rc = tool_rc_success;
@@ -5176,8 +5188,8 @@ tool_rc tpm2_pcr_event(ESYS_CONTEXT *ectx, ESYS_TR pcr, tpm2_session *session,
51765188
return rc;
51775189
}
51785190

5179-
rval = Esys_PCR_Event(ectx, pcr, shandle1, ESYS_TR_NONE,
5180-
ESYS_TR_NONE, event_data, digests);
5191+
rval = Esys_PCR_Event(ectx, pcr, shandle1, session_handle_2,
5192+
session_handle_3, event_data, digests);
51815193
if (rval != TSS2_RC_SUCCESS) {
51825194
LOG_PERR(Esys_PCR_Event, rval);
51835195
return tool_rc_from_tpm(rval);

lib/tpm2.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,11 +430,14 @@ tool_rc tpm2_loadexternal(ESYS_CONTEXT *ectx, const TPM2B_SENSITIVE *private,
430430
TPMI_ALG_HASH parameter_hash_algorithm);
431431

432432
tool_rc tpm2_pcr_extend(ESYS_CONTEXT *ectx, TPMI_DH_PCR pcr_index,
433-
TPML_DIGEST_VALUES *digests);
433+
tpm2_session *session,
434+
TPML_DIGEST_VALUES *digests,
435+
ESYS_TR session_handle_2, ESYS_TR session_handle_3);
434436

435437
tool_rc tpm2_pcr_event(ESYS_CONTEXT *ectx, ESYS_TR pcr, tpm2_session *session,
436438
const TPM2B_EVENT *event_data, TPML_DIGEST_VALUES **digests,
437-
TPM2B_DIGEST *cp_hash, TPMI_ALG_HASH parameter_hash_algorithm);
439+
TPM2B_DIGEST *cp_hash, TPMI_ALG_HASH parameter_hash_algorithm,
440+
ESYS_TR session_handle_2, ESYS_TR session_handle_3);
438441

439442
tool_rc tpm2_getrandom(ESYS_CONTEXT *ectx, UINT16 count,
440443
TPM2B_DIGEST **random, TPM2B_DIGEST *cp_hash, TPM2B_DIGEST *rp_hash,

lib/tpm2_policy.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,8 @@ tool_rc tpm2_policy_build_pcr(ESYS_CONTEXT *ectx, tpm2_session *policy_session,
212212
} else {
213213
// Read PCRs
214214
tool_rc rc = pcr_read_pcr_values(ectx, pcr_selections, &pcrs,
215-
NULL, TPM2_ALG_ERROR);
215+
NULL, TPM2_ALG_ERROR, ESYS_TR_NONE,
216+
ESYS_TR_NONE, ESYS_TR_NONE);
216217
if (rc != tool_rc_success) {
217218
return rc;
218219
}

man/tpm2_pcrevent.1.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,23 @@ These options control extending the pcr:
3636

3737
Specifies the authorization value for PCR.
3838

39+
* **-S**, **\--session**=_FILE_:
40+
41+
Specifies the auxiliary sessions for the command.
42+
3943
* **\--cphash**=_FILE_
4044

4145
File path to record the hash of the command parameters. This is commonly
4246
termed as cpHash. NOTE: When this option is selected, The tool will not
4347
actually execute the command, it simply returns a cpHash.
4448

45-
[common options](common/options.md)
49+
## References
50+
51+
[common options](common/options.md) collection of common options that provide
52+
information many users may expect.
4653

47-
[common tcti options](common/tcti.md)
54+
[common tcti options](common/tcti.md) collection of options used to configure
55+
the various known TCTI modules.
4856

4957
[authorization formatting](common/authorizations.md)
5058

man/tpm2_pcrextend.1.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,13 @@ supported. This is to keep the parser simple.
3636

3737
# OPTIONS
3838

39-
This tool accepts no tool specific options.
39+
* **-P**, **\--auth**=_AUTH_:
40+
41+
The authorization value of the used PCR register.
42+
43+
* **-S**, **\--session**=_FILE_:
44+
45+
Specifies the auxiliary sessions for the command.
4046

4147
[common options](common/options.md)
4248

man/tpm2_pcrread.1.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ sha256 :
4848
termed as cpHash. NOTE: When this option is selected, The tool will not
4949
actually execute the command, it simply returns a cpHash.
5050

51+
* **-S**, **\--session**=_FILE_:
52+
53+
Specifies the auxiliary sessions for the command.
54+
5155
[PCR output file format specifiers](common/pcrs_format.md)
5256
Default is 'values'.
5357

test/integration/tests/pcrevent.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ yaml_out_file=pcr_list.yaml
1010

1111
cleanup() {
1212
rm -f $hash_in_file $hash_out_file $yaml_out_file
13-
13+
rm -f audit_session.ctx hmac_session.ctx eventfile
1414
shut_down
1515
}
1616
trap cleanup EXIT
@@ -83,4 +83,9 @@ if [ $? -eq 0 ]; then
8383
exit 1;
8484
fi
8585

86+
echo event > eventfile
87+
tpm2 startauthsession -Q --session hmac_session.ctx --hmac
88+
tpm2 startauthsession -Q --session audit_session.ctx --audit
89+
tpm2 pcrevent -S audit_session.ctx -P session:hmac_session.ctx 10 eventfile
90+
8691
exit 0

test/integration/tests/pcrextend.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
source helpers.sh
44

5+
cleanup() {
6+
rm -f audit_session.ctx hmac_session.ctx
7+
shut_down
8+
}
9+
trap cleanup EXIT
10+
511
start_up
612

713
declare -A alg_hashes=(
@@ -46,4 +52,9 @@ else
4652
true
4753
fi
4854

55+
tpm2 startauthsession -Q --session hmac_session.ctx --hmac
56+
tpm2 startauthsession -Q --session audit_session.ctx --audit
57+
tpm2 pcrextend -S audit_session.ctx -P session:hmac_session.ctx \
58+
16:sha256=b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c
59+
4960
exit 0

0 commit comments

Comments
 (0)