|
|
28cd4a |
From 70e9fae7ef535e7cf27a72ddbc818dfefcbdbdbb Mon Sep 17 00:00:00 2001
|
|
|
28cd4a |
From: William Roberts <william.c.roberts@intel.com>
|
|
|
28cd4a |
Date: Wed, 18 Sep 2019 11:29:57 -0700
|
|
|
28cd4a |
Subject: [PATCH] Esys_CreateLoaded: fix resource name calculation
|
|
|
28cd4a |
|
|
|
28cd4a |
The name calculated and cached for the ESYS_TR resource object was based
|
|
|
28cd4a |
on the user supplied TPMT_PUBLIC. However, this template is often
|
|
|
28cd4a |
missing data that the TPM fills in and returns in the TPM2B_PUBLIC
|
|
|
28cd4a |
structure. Because of this, the cached name returned from
|
|
|
28cd4a |
Esys_TR_GetName() and the name read from Esys_ReadPublic() would differ.
|
|
|
28cd4a |
|
|
|
28cd4a |
Add a test to detect this condition and correct it by copying the
|
|
|
28cd4a |
returned TPM2B_PUBLIC to the ESYS_TR resource nodes TPM2B_PUBLIC cache
|
|
|
28cd4a |
and calculate the name off of that.
|
|
|
28cd4a |
|
|
|
28cd4a |
Fixes: #1516
|
|
|
28cd4a |
|
|
|
28cd4a |
Signed-off-by: William Roberts <william.c.roberts@intel.com>
|
|
|
28cd4a |
---
|
|
|
28cd4a |
src/tss2-esys/api/Esys_CreateLoaded.c | 14 ++++-----
|
|
|
28cd4a |
test/integration/esys-createloaded.int.c | 37 ++++++++++++++++++++++++
|
|
|
28cd4a |
2 files changed, 42 insertions(+), 9 deletions(-)
|
|
|
28cd4a |
|
|
|
28cd4a |
diff --git a/src/tss2-esys/api/Esys_CreateLoaded.c b/src/tss2-esys/api/Esys_CreateLoaded.c
|
|
|
28cd4a |
index a92649cade27..44c4400fcff9 100644
|
|
|
28cd4a |
--- a/src/tss2-esys/api/Esys_CreateLoaded.c
|
|
|
28cd4a |
+++ b/src/tss2-esys/api/Esys_CreateLoaded.c
|
|
|
28cd4a |
@@ -317,14 +317,6 @@ Esys_CreateLoaded_Finish(
|
|
|
28cd4a |
goto_error(r, TSS2_ESYS_RC_MEMORY, "Out of memory", error_cleanup);
|
|
|
28cd4a |
}
|
|
|
28cd4a |
|
|
|
28cd4a |
- /* Update the meta data of the ESYS_TR object */
|
|
|
28cd4a |
- objectHandleNode->rsrc.rsrcType = IESYSC_KEY_RSRC;
|
|
|
28cd4a |
- size_t offset = 0;
|
|
|
28cd4a |
- r = Tss2_MU_TPMT_PUBLIC_Unmarshal(&esysContext->in.CreateLoaded.inPublic->buffer[0],
|
|
|
28cd4a |
- sizeof(TPMT_PUBLIC), &offset ,
|
|
|
28cd4a |
- &objectHandleNode->rsrc.misc.rsrc_key_pub.publicArea);
|
|
|
28cd4a |
- goto_if_error(r, "Unmarshal TPMT_PUBULIC", error_cleanup);
|
|
|
28cd4a |
-
|
|
|
28cd4a |
/*Receive the TPM response and handle resubmissions if necessary. */
|
|
|
28cd4a |
r = Tss2_Sys_ExecuteFinish(esysContext->sys, esysContext->timeout);
|
|
|
28cd4a |
if ((r & ~TSS2_RC_LAYER_MASK) == TSS2_BASE_RC_TRY_AGAIN) {
|
|
|
28cd4a |
@@ -386,8 +378,12 @@ Esys_CreateLoaded_Finish(
|
|
|
28cd4a |
error_cleanup);
|
|
|
28cd4a |
|
|
|
28cd4a |
|
|
|
28cd4a |
+ /* Update the meta data of the ESYS_TR object */
|
|
|
28cd4a |
+ objectHandleNode->rsrc.rsrcType = IESYSC_KEY_RSRC;
|
|
|
28cd4a |
+ objectHandleNode->rsrc.misc.rsrc_key_pub = *loutPublic;
|
|
|
28cd4a |
+
|
|
|
28cd4a |
/* Check name and outPublic for consistency */
|
|
|
28cd4a |
- if (!iesys_compare_name(loutPublic, &name))
|
|
|
28cd4a |
+ if (!iesys_compare_name(&objectHandleNode->rsrc.misc.rsrc_key_pub, &name))
|
|
|
28cd4a |
goto_error(r, TSS2_ESYS_RC_MALFORMED_RESPONSE,
|
|
|
28cd4a |
"in Public name not equal name in response", error_cleanup);
|
|
|
28cd4a |
|
|
|
28cd4a |
diff --git a/test/integration/esys-createloaded.int.c b/test/integration/esys-createloaded.int.c
|
|
|
28cd4a |
index ec8d68a0d43d..118f2a3bb1ff 100644
|
|
|
28cd4a |
--- a/test/integration/esys-createloaded.int.c
|
|
|
28cd4a |
+++ b/test/integration/esys-createloaded.int.c
|
|
|
28cd4a |
@@ -8,6 +8,7 @@
|
|
|
28cd4a |
#include <config.h>
|
|
|
28cd4a |
#endif
|
|
|
28cd4a |
|
|
|
28cd4a |
+#include <stdbool.h>
|
|
|
28cd4a |
#include <stdlib.h>
|
|
|
28cd4a |
|
|
|
28cd4a |
#include "tss2_esys.h"
|
|
|
28cd4a |
@@ -19,6 +20,35 @@
|
|
|
28cd4a |
#include "util/log.h"
|
|
|
28cd4a |
#include "util/aux_util.h"
|
|
|
28cd4a |
|
|
|
28cd4a |
+static bool check_name(ESYS_CONTEXT * esys_context, ESYS_TR object_handle)
|
|
|
28cd4a |
+{
|
|
|
28cd4a |
+ bool result = false;
|
|
|
28cd4a |
+
|
|
|
28cd4a |
+ TPM2B_NAME *read_name = NULL;
|
|
|
28cd4a |
+ TPM2B_NAME *get_name = NULL;
|
|
|
28cd4a |
+
|
|
|
28cd4a |
+ TSS2_RC r = Esys_ReadPublic(esys_context, object_handle,
|
|
|
28cd4a |
+ ESYS_TR_NONE, ESYS_TR_NONE, ESYS_TR_NONE,
|
|
|
28cd4a |
+ NULL, &read_name, NULL);
|
|
|
28cd4a |
+ goto_if_error(r, "Error esys readpublic", out);
|
|
|
28cd4a |
+
|
|
|
28cd4a |
+ r = Esys_TR_GetName(esys_context, object_handle, &get_name);
|
|
|
28cd4a |
+ goto_if_error(r, "Error esys getname", out);
|
|
|
28cd4a |
+
|
|
|
28cd4a |
+ if (read_name->size != get_name->size) {
|
|
|
28cd4a |
+ LOG_ERROR("name size mismatch %u != %u",
|
|
|
28cd4a |
+ read_name->size, get_name->size);
|
|
|
28cd4a |
+ goto out;
|
|
|
28cd4a |
+ }
|
|
|
28cd4a |
+
|
|
|
28cd4a |
+ result = memcmp(read_name->name, get_name->name, get_name->size) == 0;
|
|
|
28cd4a |
+
|
|
|
28cd4a |
+out:
|
|
|
28cd4a |
+ free(read_name);
|
|
|
28cd4a |
+ free(get_name);
|
|
|
28cd4a |
+
|
|
|
28cd4a |
+ return result;
|
|
|
28cd4a |
+}
|
|
|
28cd4a |
/** This test is intended to test the ESAPI command CreateLoaded.
|
|
|
28cd4a |
*
|
|
|
28cd4a |
* We start by creating a primary key (Esys_CreatePrimary).
|
|
|
28cd4a |
@@ -29,6 +59,8 @@
|
|
|
28cd4a |
* - Esys_CreatePrimary() (M)
|
|
|
28cd4a |
* - Esys_FlushContext() (M)
|
|
|
28cd4a |
* - Esys_StartAuthSession() (M)
|
|
|
28cd4a |
+ * - Esys_TR_GetName() (M)
|
|
|
28cd4a |
+ * - Esys_TR_ReadPublic() (M)
|
|
|
28cd4a |
*
|
|
|
28cd4a |
* Used compiler defines: TEST_SESSION
|
|
|
28cd4a |
*
|
|
|
28cd4a |
@@ -239,6 +271,11 @@ test_esys_createloaded(ESYS_CONTEXT * esys_context)
|
|
|
28cd4a |
|
|
|
28cd4a |
goto_if_error(r, "Error During CreateLoaded", error);
|
|
|
28cd4a |
|
|
|
28cd4a |
+ bool names_match = check_name(esys_context, objectHandle);
|
|
|
28cd4a |
+ if (!names_match) {
|
|
|
28cd4a |
+ goto error;
|
|
|
28cd4a |
+ }
|
|
|
28cd4a |
+
|
|
|
28cd4a |
r = Esys_FlushContext(esys_context, primaryHandle);
|
|
|
28cd4a |
goto_if_error(r, "Flushing context", error);
|
|
|
28cd4a |
|
|
|
28cd4a |
--
|
|
|
28cd4a |
2.27.0
|
|
|
28cd4a |
|