diff options
author | Kiran Kamineni <kiran.k.kamineni@intel.com> | 2018-09-10 16:31:49 -0700 |
---|---|---|
committer | Kiran Kamineni <kiran.k.kamineni@intel.com> | 2018-09-10 16:43:23 -0700 |
commit | e6d5d0d790c57f932dc4c98a903ce826868dd98d (patch) | |
tree | 14dedc0f0f6eacea68af1dfa448b0e2ea28b039e | |
parent | 8420cc7411f57c6df9d25ca48f0dd942b3cbe64a (diff) |
Fix key pair loading in plugin
Key pair reading in TPM plugin assumes a particular order for input buffers.
This patch checks the buffers and removes that assumption
Issue-ID: AAF-478
Change-Id: I4fff17c912a0890138d1f432e5bfab5c9946b1cb
Signed-off-by: Kiran Kamineni <kiran.k.kamineni@intel.com>
-rw-r--r-- | TPM2-Plugin/lib/tpm2_plugin_api.c | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/TPM2-Plugin/lib/tpm2_plugin_api.c b/TPM2-Plugin/lib/tpm2_plugin_api.c index 75e4fc1..c763ef3 100644 --- a/TPM2-Plugin/lib/tpm2_plugin_api.c +++ b/TPM2-Plugin/lib/tpm2_plugin_api.c @@ -414,20 +414,34 @@ int load_key_execute(SSHSM_HW_PLUGIN_ACTIVATE_LOAD_IN_INFO_t *loadkey_in_info, int returnVal = 0; memset(&inPublic,0,sizeof(TPM2B_PUBLIC)); - memset(&inPrivate,0,sizeof(TPM2B_SENSITIVE)); + memset(&inPrivate,0,sizeof(TPM2B_PRIVATE)); setbuf(stdout, NULL); setvbuf (stdout, NULL, _IONBF, BUFSIZ); - //parentHandle = 0x81000011; parentHandle = srk_handle; if (loadkey_in_info->num_buffers != 2) return -1; - memcpy(&inPublic, loadkey_in_info->buffer_info[0]->buffer, - loadkey_in_info->buffer_info[0]->length_of_buffer); - memcpy(&inPrivate, loadkey_in_info->buffer_info[1]->buffer, - loadkey_in_info->buffer_info[1]->length_of_buffer); + + /* + Identify which buffer is public vs which is private + TPM2B_PUBLIC should be 360 bytes + TPM2B_PRIVATE should be 912 bytes + */ + + for (int i=0; i<2; i++) { + if (loadkey_in_info->buffer_info[i]->length_of_buffer == sizeof(TPM2B_PUBLIC)) { + memcpy(&inPublic, loadkey_in_info->buffer_info[i]->buffer, + loadkey_in_info->buffer_info[i]->length_of_buffer); + continue; + } + if (loadkey_in_info->buffer_info[i]->length_of_buffer == sizeof(TPM2B_PRIVATE)) { + memcpy(&inPrivate, loadkey_in_info->buffer_info[i]->buffer, + loadkey_in_info->buffer_info[i]->length_of_buffer); + continue; + } + } returnVal = load_key (sapi_context, parentHandle, |