-
Notifications
You must be signed in to change notification settings - Fork 164
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
Streamline unit-tests that use a TPM #4239
Conversation
shjala
commented
Sep 11, 2024
- Create all the required keys for the TPM tests in the prep-and-test.sh before running the tests. This changes adds the creation of AIK key and also changes other keys creation method to creates all keys under Owner hierarchy rather than EK, just like we do in EVE.
- Add helper functions for simulate TPM.
- Streamline all the unit-tests that uses TPM, by removing the duplicated code and making all to use the sim tpm helper functions.
697520c
to
0e9453f
Compare
In general, it would be nice to run the test in a container so that it can be used on any system. However, the preparation script currently works only on Ubuntu-based systems. But it's out of scope of the PR. |
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.
Looks good. I realized too late that it was basically about just moving functions to shared files =D
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.
Another question of curiosity. In the commit message, you say:
This changes adds the creation of AIK key and
also changes other keys creation method to creates all keys under Owner
hirearchy rather than EK, just like we do in EVE.
Can you please point me to where it is done in EVE?
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.
Here :
eve/pkg/pillar/cmd/tpmmgr/tpmmgr.go
Lines 717 to 734 in 9a29580
func createOtherKeys(override bool) error { | |
if err := etpm.CreateKey(log, etpm.TpmDevicePath, etpm.TpmEKHdl, tpm2.HandleEndorsement, etpm.DefaultEkTemplate, override); err != nil { | |
return fmt.Errorf("error in creating Endorsement key: %w ", err) | |
} | |
if err := etpm.CreateKey(log, etpm.TpmDevicePath, etpm.TpmSRKHdl, tpm2.HandleOwner, etpm.DefaultSrkTemplate, override); err != nil { | |
return fmt.Errorf("error in creating SRK key: %w ", err) | |
} | |
if err := etpm.CreateKey(log, etpm.TpmDevicePath, etpm.TpmAIKHdl, tpm2.HandleOwner, etpm.DefaultAikTemplate, override); err != nil { | |
return fmt.Errorf("error in creating Attestation key: %w ", err) | |
} | |
if err := etpm.CreateKey(log, etpm.TpmDevicePath, etpm.TpmQuoteKeyHdl, tpm2.HandleOwner, etpm.DefaultQuoteKeyTemplate, override); err != nil { | |
return fmt.Errorf("error in creating Quote key: %w ", err) | |
} | |
if err := etpm.CreateKey(log, etpm.TpmDevicePath, etpm.TpmEcdhKeyHdl, tpm2.HandleOwner, etpm.DefaultEcdhKeyTemplate, override); err != nil { | |
return fmt.Errorf("error in creating ECDH key: %w ", err) | |
} | |
return nil | |
} |
btw, the ownerHandle
in CreateKey
is unused so don't and we don't create the EK under tpm2.HandleEndorsement
, and tpm2.HandleOwner
is hardcoded in the function. I want to clean that up for ages :D
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.
Thanks!
It may make sense to add a comment to the prep script that it refers to this code (and vice versa), especially if you have a plan to change it.
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.
sure.
Create all the required keys for the TPM tests in the prep-and-test.sh before running the tests. This changes adds the creation of AIK key and also changes other keys creation method to creates all keys under Owner hirearchy rather than EK, just like we do in EVE. Signed-off-by: Shahriyar Jalayeri <shahriyar@zededa.com>
These functions can be used in all other tests that rely on a sim TPM. Signed-off-by: Shahriyar Jalayeri <shahriyar@zededa.com>
Streamline all the unit-tests that uses TPM, by removing the duplicated code and making all to use the sim tpm helper functions. Signed-off-by: Shahriyar Jalayeri <shahriyar@zededa.com>
0e9453f
to
ad620da
Compare
The very last thing) |
We create the keys in test script based on the tpmmgr code. Add a comment and reminder, in case something changed. Signed-off-by: Shahriyar Jalayeri <shahriyar@zededa.com>
abbf712
to
5d5d5db
Compare
SPDX check glitching. |
Yep... I also don't understand how it happened. |