Repository navigation
fix loading of parent handles in TPM TSS2 keys #175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| #!/usr/bin/env bash | ||
| # SPDX-License-Identifier: BSD-3-Clause | ||
| set -eufx | ||
|
|
||
| # create primary using the same ECC template that tpm2-openssl uses internally | ||
| tpm2_createprimary \ | ||
| -G ecc256:aes128cfb \ | ||
| -g sha256 \ | ||
| -a 'fixedtpm|fixedparent|sensitivedataorigin|userwithauth|noda|restricted|decrypt' \ | ||
| -c primary.ctx | ||
|
|
||
| # generate a private key and store its public portions to PEM | ||
| tpm2_create -C primary.ctx -u key.pub -r key.priv -f pem -o pub.pem | ||
|
|
||
| # encode private key to PEM | ||
| tpm2_encodeobject -C primary.ctx -u key.pub -r key.priv -o priv.pem | ||
|
|
||
| # print public key modulus | ||
| openssl rsa -pubin -in pub.pem -modulus -noout | ||
|
|
||
| # validate the private key | ||
| openssl rsa -provider tpm2 -provider base -in priv.pem -passin pass: -check -noout | ||
|
|
||
| # print private key modulus | ||
| openssl rsa -provider tpm2 -provider base -in priv.pem -passin pass: -modulus -noout | ||
|
|
||
| rm primary.ctx key.pub key.priv pub.pem priv.pem |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| #!/usr/bin/env bash | ||
| # SPDX-License-Identifier: BSD-3-Clause | ||
| set -eufx | ||
|
|
||
| # create primary key | ||
| tpm2_createprimary -c primary.ctx | ||
|
|
||
| # make the primary persistent | ||
| HANDLE=$(tpm2_evictcontrol -c primary.ctx | cut -d ' ' -f 2 | head -n 1) | ||
|
|
||
| # generate a private key and store its public portions to PEM | ||
| tpm2_create -C primary.ctx -u key.pub -r key.priv -f pem -o pub.pem | ||
|
|
||
| # encode private key to PEM using the persistent parent handle | ||
| tpm2_encodeobject -C ${HANDLE} -u key.pub -r key.priv -o priv.pem | ||
|
|
||
| # print public key modulus | ||
| openssl rsa -pubin -in pub.pem -modulus -noout | ||
|
|
||
| # validate the private key | ||
| openssl rsa -provider tpm2 -provider base -in priv.pem -passin pass: -check -noout | ||
|
|
||
| # print private key modulus | ||
| openssl rsa -provider tpm2 -provider base -in priv.pem -passin pass: -modulus -noout | ||
|
|
||
| # release the persistent primary | ||
| tpm2_evictcontrol -c ${HANDLE} | ||
|
|
||
| rm primary.ctx key.pub key.priv pub.pem priv.pem |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By changing parent from type uint64_t to TPM2_HANDLE (which according to tpm2-tss is an uint32_t see: https://github.com/tpm2-software/tpm2-tss/blob/a54a27df0732cde2c47b1d4d0e7bef489dc8a7d5/include/tss2/tss2_tpm2_types.h#L1050 and https://github.com/tpm2-software/tpm2-tss/blob/a54a27df0732cde2c47b1d4d0e7bef489dc8a7d5/include/tss2/tss2_common.h#L24) this line will always be true.
Have a look at line 153:
BN_get_word returns an BN_ULONG, which is 32-bits on 32-bit systems and 64-bits on 64-bit systems.
BN_get_word set's all bits in case of an error.
parent is of type TPM2_HANDLE which is of type uint32_t.
On a 64 bit system, we're performing an implicit conversion from uint64 to uint32. This shouldn't be a problem in case of a valid parent-handle as they're in the range 0x81000000 - 0x81FFFFFF. I think we should handle the case where BN_get_word() returns something bigger than a 32bit value on 64bits systems and on 32bit systems we should treat the return value UINT32_MAX as error.