Blame Wire-up-support-for-ak-auth-password-in-tpm2_quote-t.patch

af88e80
From 993da58a612238bf2dd53a015dfdb2a6c0eb00b9 Mon Sep 17 00:00:00 2001
af88e80
From: jetwhiz <Charles.Munson@ll.mit.edu>
af88e80
Date: Mon, 22 Apr 2019 09:48:56 -0400
af88e80
Subject: [PATCH 1/6] Wire up support for ak auth password in tpm2_quote tool
af88e80
af88e80
Add regression test
af88e80
af88e80
Signed-off-by: jetwhiz <Charles.Munson@ll.mit.edu>
af88e80
---
af88e80
 test/system/test_tpm2_quote.sh |  9 ++++++++-
af88e80
 tools/tpm2_quote.c             | 11 ++++++++---
af88e80
 2 files changed, 16 insertions(+), 4 deletions(-)
af88e80
af88e80
diff --git a/test/system/test_tpm2_quote.sh b/test/system/test_tpm2_quote.sh
af88e80
index d845ea1bdb1..231bed326ec 100755
af88e80
--- a/test/system/test_tpm2_quote.sh
af88e80
+++ b/test/system/test_tpm2_quote.sh
af88e80
@@ -50,6 +50,7 @@ file_quote_key_ctx=ctx_load_out_"$alg_primary_obj"_"$alg_primary_key"-"$alg_crea
af88e80
 Handle_ak_quote=0x81010016
af88e80
 Handle_ek_quote=0x81010017
af88e80
 Handle_ak_quote2=0x81010018
af88e80
+Handle_ak_quote3=0x81010019
af88e80
 
af88e80
 maxdigest=$(tpm2_getcap -c properties-fixed | grep TPM_PT_MAX_DIGEST | sed -r -e 's/.*(0x[0-9a-f]+)/\1/g')
af88e80
 if ! [[ "$maxdigest" =~ ^(0x)*[0-9]+$ ]] ; then
af88e80
@@ -73,6 +74,7 @@ cleanup() {
af88e80
     tpm2_evictcontrol -Q -Ao -H $Handle_ek_quote 2>/dev/null || true
af88e80
     tpm2_evictcontrol -Q -Ao -H $Handle_ak_quote 2>/dev/null || true
af88e80
     tpm2_evictcontrol -Q -Ao -H $Handle_ak_quote2 2>/dev/null || true
af88e80
+    tpm2_evictcontrol -Q -Ao -H $Handle_ak_quote3 2>/dev/null || true
af88e80
 }
af88e80
 trap cleanup EXIT
af88e80
 
af88e80
@@ -104,4 +106,9 @@ tpm2_getpubak -Q -E  $Handle_ek_quote -k  $Handle_ak_quote2 -f ak.pub2 -n ak.nam
af88e80
 
af88e80
 tpm2_quote -Q -k $Handle_ak_quote -g $alg_quote -l 16,17,18 -q $nonce
af88e80
 
af88e80
-exit 0
af88e80
+#####AK with password
af88e80
+tpm2_getpubak -Q -E  $Handle_ek_quote -k  $Handle_ak_quote3 -f ak.pub2 -n ak.name_2 -P abc123
af88e80
+
af88e80
+tpm2_quote -Q -k $Handle_ak_quote3 -g $alg_quote -l 16,17,18 -q $nonce -P abc123
af88e80
+
af88e80
+exit 0
af88e80
\ No newline at end of file
af88e80
diff --git a/tools/tpm2_quote.c b/tools/tpm2_quote.c
af88e80
index 3538947db31..05b6d641656 100644
af88e80
--- a/tools/tpm2_quote.c
af88e80
+++ b/tools/tpm2_quote.c
af88e80
@@ -50,7 +50,7 @@ typedef struct {
af88e80
     UINT32 id[24];
af88e80
 } PCR_LIST;
af88e80
 
af88e80
-static TPMS_AUTH_COMMAND sessionData;
af88e80
+static TPMS_AUTH_COMMAND sessionData = TPMS_AUTH_COMMAND_INIT(TPM2_RS_PW);
af88e80
 static char *outFilePath;
af88e80
 static char *signature_path;
af88e80
 static char *message_path;
af88e80
@@ -60,7 +60,7 @@ static TPM2B_DATA qualifyingData = TPM2B_EMPTY_INIT;
af88e80
 static TPML_PCR_SELECTION  pcrSelections;
af88e80
 static bool is_auth_session;
af88e80
 static TPMI_SH_AUTH_SESSION auth_session_handle;
af88e80
-static int k_flag, c_flag, l_flag, g_flag, L_flag, o_flag, G_flag;
af88e80
+static int k_flag, c_flag, l_flag, g_flag, L_flag, o_flag, G_flag, P_flag;
af88e80
 static char *contextFilePath;
af88e80
 static TPM2_HANDLE akHandle;
af88e80
 
af88e80
@@ -94,7 +94,7 @@ static int quote(TSS2_SYS_CONTEXT *sapi_context, TPM2_HANDLE akHandle, TPML_PCR_
af88e80
 {
af88e80
     UINT32 rval;
af88e80
     TPMT_SIG_SCHEME inScheme;
af88e80
-    TSS2L_SYS_AUTH_COMMAND sessionsData = { 1, {{.sessionHandle=TPM2_RS_PW}}};
af88e80
+    TSS2L_SYS_AUTH_COMMAND sessionsData = { 1, { sessionData }};
af88e80
     TSS2L_SYS_AUTH_RESPONSE sessionsDataOut;
af88e80
     TPM2B_ATTEST quoted = TPM2B_TYPE_INIT(TPM2B_ATTEST, attestationData);
af88e80
     TPMT_SIGNATURE signature;
af88e80
@@ -152,6 +152,7 @@ static bool on_option(char key, char *value) {
af88e80
             LOG_ERR("Invalid AK password, got\"%s\"", value);
af88e80
             return false;
af88e80
         }
af88e80
+        P_flag = 1;
af88e80
     } break;
af88e80
     case 'l':
af88e80
         if(!pcr_parse_list(value, strlen(value), &pcrSelections.pcrSelections[0]))
af88e80
@@ -265,5 +266,9 @@ int tpm2_tool_onrun(TSS2_SYS_CONTEXT *sapi_context, tpm2_option_flags flags) {
af88e80
         }
af88e80
     }
af88e80
 
af88e80
+    if (P_flag == 0) {
af88e80
+        sessionData.hmac.size = 0;
af88e80
+    }
af88e80
+
af88e80
     return quote(sapi_context, akHandle, &pcrSelections);
af88e80
 }
af88e80
-- 
af88e80
2.21.0
af88e80