diff options
author | Kiran Kamineni <kiran.k.kamineni@intel.com> | 2018-09-19 14:18:20 -0700 |
---|---|---|
committer | Kiran Kamineni <kiran.k.kamineni@intel.com> | 2018-09-19 16:44:28 -0700 |
commit | a5f9d0fa5528026209c9fa75c0bb8537a44523c1 (patch) | |
tree | 56651e6ef939f466424566bb498d2bbd45a19356 /TPM2-Plugin/lib | |
parent | cd713d4de6c3d08478d6f6ca27b0f9e1afd439fe (diff) |
Remove global variable sessionData
Remove global variable for storing session info.
Instead this is populated by the calling function
as required.
Issue-ID: AAF-334
Change-Id: I146b52bcee758fd053129fdf4f7a75691575e6e9
Signed-off-by: Kiran Kamineni <kiran.k.kamineni@intel.com>
Diffstat (limited to 'TPM2-Plugin/lib')
-rw-r--r-- | TPM2-Plugin/lib/tpm2_plugin_api.c | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/TPM2-Plugin/lib/tpm2_plugin_api.c b/TPM2-Plugin/lib/tpm2_plugin_api.c index c27ec55..b328413 100644 --- a/TPM2-Plugin/lib/tpm2_plugin_api.c +++ b/TPM2-Plugin/lib/tpm2_plugin_api.c @@ -247,7 +247,7 @@ static TSS2_SYS_CONTEXT *sapi_ctx_init (TSS2_TCTI_CONTEXT *tcti_ctx) #define BUFFER_SIZE(type, field) (sizeof((((type *)NULL)->t.field))) #define TPM2B_TYPE_INIT(type, field) { .t = { .size = BUFFER_SIZE(type, field), }, } -TPMS_AUTH_COMMAND sessionData; + int hex2ByteStructure(const char *inStr, UINT16 *byteLength, BYTE *byteBuffer) { int strLength;//if the inStr likes "1a2b...", no prefix "0x" @@ -279,6 +279,7 @@ int hex2ByteStructure(const char *inStr, UINT16 *byteLength, BYTE *byteBuffer) } int load_key(TSS2_SYS_CONTEXT *sapi_context, + TPMS_AUTH_COMMAND sessionData, TPMI_DH_OBJECT parentHandle, TPM2B_PUBLIC *inPublic, TPM2B_PRIVATE *inPrivate) @@ -301,10 +302,6 @@ int load_key(TSS2_SYS_CONTEXT *sapi_context, sessionsDataOut.rspAuthsCount = 1; sessionsData.cmdAuthsCount = 1; - sessionData.sessionHandle = TPM_RS_PW; - sessionData.nonce.t.size = 0; - - *((UINT8 *)((void *)&sessionData.sessionAttributes)) = 0; if (sessionData.hmac.t.size > 0 && hexPasswd) { sessionData.hmac.t.size = sizeof(sessionData.hmac) - 2; @@ -400,21 +397,19 @@ int read_public(TSS2_SYS_CONTEXT *sapi_context, /* Reads the PRK_PASSWORD Environment variable and populates that information into the -sessionData global environment variable +provided sessionData variable */ -int readPassword() +int readPassword(TPMS_AUTH_COMMAND *sessionData) { char *prk_passwd; - sessionData.hmac.t.size = 0; - prk_passwd = getenv("TPM_PRK_PASSWORD"); if (prk_passwd != NULL) { - sessionData.hmac.t.size = strlen(prk_passwd); - if (sessionData.hmac.t.size > sizeof(sessionData.hmac.t.buffer)) { + sessionData->hmac.t.size = strlen(prk_passwd); + if (sessionData->hmac.t.size > sizeof(sessionData->hmac.t.buffer)) { return -1; } - memcpy(sessionData.hmac.t.buffer, prk_passwd, sessionData.hmac.t.size); + memcpy(sessionData->hmac.t.buffer, prk_passwd, sessionData->hmac.t.size); return 0; } return 0; @@ -430,9 +425,20 @@ int load_key_execute(SSHSM_HW_PLUGIN_ACTIVATE_LOAD_IN_INFO_t *loadkey_in_info, TPMI_DH_OBJECT parentHandle; TPM2B_PUBLIC inPublic; TPM2B_PRIVATE inPrivate; + TPMS_AUTH_COMMAND sessionData; UINT16 size; int returnVal = 0; + /* + Initializing the sessionData structure to the 0 values + sessionAttributes is a union and the following assignment + is based on the method used in other tpm2 tools. + */ + *((UINT8 *)((void *)&sessionData.sessionAttributes)) = 0; + sessionData.sessionHandle = TPM_RS_PW; + sessionData.nonce.t.size = 0; + sessionData.hmac.t.size = 0; + memset(&inPublic,0,sizeof(TPM2B_PUBLIC)); memset(&inPrivate,0,sizeof(TPM2B_PRIVATE)); @@ -464,12 +470,13 @@ int load_key_execute(SSHSM_HW_PLUGIN_ACTIVATE_LOAD_IN_INFO_t *loadkey_in_info, } // Read TPM_PRK_PASSWORD and setup sessionsData appropriately - if (readPassword() != 0) { + if (readPassword(&sessionData) != 0) { // Password read failure return -1; } returnVal = load_key (sapi_context, + sessionData, parentHandle, &inPublic, &inPrivate); |