Skip to content

Fixed loading of parent handles in TPM TSS2 keys#153

Open
thomkopp wants to merge 1 commit intotpm2-software:masterfrom
thomkopp:fix-tpm2-tss-key-loading
Open

Fixed loading of parent handles in TPM TSS2 keys#153
thomkopp wants to merge 1 commit intotpm2-software:masterfrom
thomkopp:fix-tpm2-tss-key-loading

Conversation

@thomkopp
Copy link
Copy Markdown

We need to make sure to be able to load TPM2 TSS2 keys which have been created with earlier versions of the tpm2-openssl provider or with earlier versions of the tpm2-tss-engine.

The parent handle of TPM2_TSS keys created with provider version < 1.2 or engine version < 1.2.0-rc0 have been written using ASN1_INTEGER_set ASN1_INTEGER_set takes a (signed) long (which on 32-bit systems is 32-bit and on 64-bit systems is 64bit) As parent handles are in the range of 0x81000000 - 0x81FFFFFF the MSB on a 32-bit system is always set, and therefore is treated as negative. This won't be the case on 64 bit systems or in case the handle had been written using BN_set_word().

The parent handle of TPM2_TSS keys create with provider verision 1.2 - 1.3 have been written using ASN1_INTEGER_set_uint64. These values can safely be read using BN_get_word, as the values written always were of type TPM2_HANDLE (uint32_t).

Resolves: #152
See also: #74,
tpm2-software/tpm2-tss-engine#222, tpm2-software/tpm2-tools#3113

@thomkopp
Copy link
Copy Markdown
Author

Quick question: Who would be able to review this? I created the MR in November of last year and am still hoping to get some feedback (have the change eventually merged). I'm not a maintainer of this project and therefore definitely don't understand all the details. But I'm trying to make it better by fixing a bug which we encountered in our environment. Thanks in advance.

We need to make sure to be able to load TPM2 TSS2 keys which
have been created with earlier versions of the tpm2-openssl
provider or with earlier versions of the tpm2-tss-engine.

The parent handle of TPM2_TSS keys created with provider version < 1.2 or engine version < 1.2.0-rc0 have been written using ASN1_INTEGER_set
ASN1_INTEGER_set takes a (signed) long (which on 32-bit systems is 32-bit and on 64-bit systems is 64bit)
As parent handles are in the range of 0x81000000 - 0x81FFFFFF the MSB on a 32-bit system is always set, and therefore is treated as negative.
This won't be the case on 64 bit systems or in case the handle had been written using BN_set_word().

The parent handle of TPM2_TSS keys create with provider verision 1.2 - 1.3 have been written using ASN1_INTEGER_set_uint64.
These values can safely be read using BN_get_word, as the values written always were of type TPM2_HANDLE (uint32_t).

Resolves: tpm2-software#152
See also: tpm2-software#74,
tpm2-software/tpm2-tss-engine#222, tpm2-software/tpm2-tools#3113

Signed-off-by: Thomas Kopp <thomas.kopp@securiton.ch>
@thomkopp thomkopp force-pushed the fix-tpm2-tss-key-loading branch from ebd9a89 to 30d57cf Compare March 16, 2026 15:43
@gotthardp
Copy link
Copy Markdown
Contributor

Hello. Thank you for pointing out this problem. I made an alternative fix in #175, which is (almost) identical to what tpm2-tools did. I prefer to stay similar to that code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Loading of TPM2-TSS keys created with version earlier than 1.2.0 always fails

2 participants