Re: [Tpm2] help regarding how to create NV under platform hierarchy

"Roberts, William C" <[email protected]> Tue, 11 Jul 2023 14:26:50 +0000
Newsgroups dev.linux.lists.tpm2
Message-ID <SN6PR11MB343780BFD56FE3EDFE29E872B831A@SN6PR11MB3437.namprd11.prod.outlook.com>
Let me provide some context on the behavior of the TPM before I answer your questions.

Generally speaking, the platform hierarchy is unavailable except for early boot firmware. Typically, the way
folks store and retrieve data, like a symmetric key, is to use tpm2_create to create a sealing key and then
use tpm2_unseal to unseal it. This is how your disk encryption keys are stored.

The other thing to understand is how the TPM organizes objects. The TPM has four hierarchies, they are
owner, platform, endorsement and null.
owner - TPM owner, this is where most user data is stored
platform - OS and below usage typically
endorsement - privacy admin
null - ephemeral usages

Each one of these hierarchies has a seed which is used to generate primary objects, tpm2_createprimary. Given the same
seed and the same inputs to tpm2_createprimary, and you get the same key. The primary keys are stable, until the seed is changed.
Below a primary object can be other objects in an arbitrarily deep key hierarchy shaped like a tree. tpm2_create, will create objects under an existing object in this hierarchy and any of these objects can be loading into the TPM using tpm2_load. This is the typical and preferred model to using keys. There is typically a persistent primary key in the owner hierarchy at address 0x81010001 which is referred to as the Storage Root Key or SRK. This SRK is a scratch space for folks to store keys as there is no need for any passwords like the owner hierarchy password. Consider that a user making a key in the TPM may not have access to hierarchy passwords.
You can move keys into NV space an either the owner or platform hierarchies using tpm2_evictcontrol. This requires that hierarchies authorization and NV space is scarce, so it's frowned upon. It's better to use tpm2_load and load the key when you want to use it, this is also called a transient object. The metadata that is loaded is safe to store on disk with appropriate permissions defined for the threat model.


  1.  Question: is there way to access randomly set platform hierarchy authentication through TPM software stack ?
Answer: Yes, the code allows it, but you need that hierarchy auth, so in practice it's not feasable
  2.  Question: does NV index defined through platform hierarchy is persistent unless we undefine it manually ?
Answer: Yes
  3.  Question: I tried to use tpm2_clearcontrol to disable tpm2_clear but it also requires
platform authentication . can we disable clear from owner hierarchy ?
Answer: No, but lockout authorization can be used here as well, same for tpm2_clear
  4.
Question: I came across other solution to store keys using seal and unseal from below links
    <snip>
     *
Question: can you let me know what sealing and unsealing the key means here?
Answer: Sealing means creating an object with arbitrary data that can be unsealed later. It's created with tpm2_create with the -i option. You can retrieve the data with tpm2_unseal.
     *
Question: where will the sealed data reside in TPM ?
Answer: Under the parent object in the aforementioned key hierachy. The parent key,/object aka a storage key, is used to protect the child object/key data following the object protectiosn disucuseed in part 1 of the TPM library architecture specification. See link below. See section 22.
     *
Question: can we get a sealed data object so that after TPM clear or reset it can be loaded into TPM again and used for unsealing ?
Answer: If the parent object(s) are destroyed the seal object is unloadable. Ie if the primary seed for the hierarchy changes, it cannot be loaded. Remember, primary keys are stable, so deleting a primary key won't make the object unloadable.

Typically, folks use the SRK for the parent and define everything in that hierarchy if you're not firmware vendor. This is usually not a problem. I guess we would need to understand exactly what you're trying to do to advise another solution. If it's not consumable for the general public mailing list, we could do a direct talk off list.

Bill

Part 1 of the TPM Spec:
https://trustedcomputinggroup.org/wp-content/uploads/TCG_TPM2_r1p59_Part1_Architecture_pub.pdf



________________________________
From: SAI VAMSEE KRISHNA Lankisetti <[email protected]>
Sent: Tuesday, July 11, 2023 8:39 AM
To: Roberts, William C <[email protected]>; [email protected] <[email protected]>
Cc: Ravindra Sure <[email protected]>
Subject: Re: [Tpm2] help regarding how to create NV under platform hierarchy

Hi ,
   I am trying to use TPM to store symmetric keys and retrieve them from TPM whenever needed. First, I created a symmetric in TPM and tried to use it, but I came to know that private key which is the symmetric key doesn't come out of TPM. Then I thought NV index will be good to store the keys with some authentication. But NV Index defined in owner hierarchy is not persistent with TPM clear and reset. I have read in below link that NV index can't be cleared using tpm2_clear when defined in platform hierarchy . But unable to create it .
https://github.com/Infineon/optiga-tpm-cheatsheet#nv-storage

I have few questions

  1.  is there way to access randomly set platform hierarchy authentication through TPM software stack ?
  2.  does NV index defined through platform hierarchy is persistent unless we undefine it manually ?
  3.  I tried to use tpm2_clearcontrol to disable tpm2_clear but it also requires
platform authentication . can we disable clear from owner hierarchy ?
  4.  I came across other solution to store keys using seal and unseal from below links
https://github.com/tpm2-software/tpm2-tools/issues/3246

https://github.com/tpm2-software/tpm2-tools/issues/3180#issuecomment-1354996963

  *
can you let me know what sealing and unsealing the key means here?
  *
where will the sealed data reside in TPM ?
  *
can we get a sealed data object so that after TPM clear or reset it can be loaded into TPM again and used for unsealing ?


Thanks,
Vamsee Krishna.

________________________________
From: Roberts, William C <[email protected]>
Sent: 10 July 2023 20:17
To: [email protected] <[email protected]>; SAI VAMSEE KRISHNA Lankisetti <[email protected]>
Cc: Ravindra Sure <[email protected]>
Subject: [EXTERNAL] Re: [Tpm2] help regarding how to create NV under platform hierarchy

You're trying to define the NV index in the platform hierarchy which is usually locked out with a password. This is what the -Cp option is doing. Any particular reason for that? If you leave off -Cp option or do -Co it will use the owner hierarchy
ZjQcmQRYFpfptBannerStart
This Message Is From an External Sender
This message came from outside your organization.
<https://us-phishalarm-ewt.proofpoint.com/EWT/v1/PjiDSg!1e-trX6zRvm6lYv7uAElbjDV-N1WPgO-Z4rd5Cvb-R7oRVgpFx77CzoyPG6-k0ArvQdtiFKelJJQC_MYkaTD0hOPIiXdeeNnWjy7rvV08EgKHEOlpNl6WqVbTe9uPO-7HENoanchZZr0XCkxSNdK6wWs$>
Report Suspicious

ZjQcmQRYFpfptBannerEnd
You're trying to define the NV index in the platform hierarchy which is usually locked out with a password. This is what the -Cp option is doing. Any particular reason for that? If you leave off -Cp option or do -Co it will use the owner hierarchy which is usually what normal users use to create NV indices but you still need the owner password if it is set.

You can query if the owner password is set by:
tpm2_getcap properties-variable
TPM2_PT_PERMANENT:
  ownerAuthSet:              0
  endorsementAuthSet:        0
  lockoutAuthSet:            0
  reserved1:                 0
  disableClear:              0
  inLockout:                 0
  tpmGeneratedEPS:           1
  reserved2:                 0

<snip>
Note the ownerAuthSet bit under TPM2_PT_PERMANENT. You can pass the password for the owner hiearchy if it's set by using the -P (capital P) option.
________________________________
From: Tpm2 <[email protected]> on behalf of SAI VAMSEE KRISHNA Lankisetti via Tpm2 <[email protected]>
Sent: Monday, July 10, 2023 1:48 AM
To: [email protected] <[email protected]>
Cc: Ravindra Sure <[email protected]>
Subject: [Tpm2] help regarding how to create NV under platform hierarchy

Hi Folks,
I am new to tpm2.


I am trying to create NV index under platform hierarchy using tpm2-tools but getting below error.

tpm2_nvdefine 0x01000000 -C p -s 32 -a "ppwrite|ppread|platformcreate" WARNING:esys:src/tss2-esys/api/Esys_NV_DefineSpace.c:337:Esys_NV_DefineSpace_Finish() Received TPM Error ERROR:esys:src/tss2-esys/api/Esys_NV_DefineSpace.c:122:Esys_NV_DefineSpace() Esys Finish ErrorCode (0x000009a2) ERROR: Failed to define NV area at index 0x1000000 ERROR: Esys_NV_DefineSpace(0x9A2) - tpm:session(1):authorization failure without DA implications ERROR: Failed to create NV index 0x1000000.


need help regarding above error and how to create nv index in platform hierarchy
if I create nv index in owner hierarchy tmp2_clear will remove the NV index which i don't want to happen so I am trying to create in platform hierarchy.

are there any ways to store a symmetric key in TPM for external use other than nv index?

Thanks,
Vamsee Krishna.