wrappedTPM20.ekTemplate() never returns an error. (#327)

This commit is contained in:
zhsh 2023-05-30 03:16:09 +10:00 committed by GitHub
parent a4b579bcf0
commit b474b712d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -37,9 +37,9 @@ type wrappedTPM20 struct {
tpmEkTemplate *tpm2.Public tpmEkTemplate *tpm2.Public
} }
func (t *wrappedTPM20) ekTemplate() (tpm2.Public, error) { func (t *wrappedTPM20) ekTemplate() tpm2.Public {
if t.tpmEkTemplate != nil { if t.tpmEkTemplate != nil {
return *t.tpmEkTemplate, nil return *t.tpmEkTemplate
} }
nonce, err := tpm2.NVReadEx(t.rwc, nvramEkNonceIndex, tpm2.HandleOwner, "", 0) nonce, err := tpm2.NVReadEx(t.rwc, nvramEkNonceIndex, tpm2.HandleOwner, "", 0)
@ -51,7 +51,7 @@ func (t *wrappedTPM20) ekTemplate() (tpm2.Public, error) {
t.tpmEkTemplate = &template t.tpmEkTemplate = &template
} }
return *t.tpmEkTemplate, nil return *t.tpmEkTemplate
} }
func (t *wrappedTPM20) tpmVersion() TPMVersion { func (t *wrappedTPM20) tpmVersion() TPMVersion {
@ -97,11 +97,7 @@ func (t *wrappedTPM20) getPrimaryKeyHandle(pHnd tpmutil.Handle) (tpmutil.Handle,
case commonSrkEquivalentHandle: case commonSrkEquivalentHandle:
keyHnd, _, err = tpm2.CreatePrimary(t.rwc, tpm2.HandleOwner, tpm2.PCRSelection{}, "", "", defaultSRKTemplate) keyHnd, _, err = tpm2.CreatePrimary(t.rwc, tpm2.HandleOwner, tpm2.PCRSelection{}, "", "", defaultSRKTemplate)
case commonEkEquivalentHandle: case commonEkEquivalentHandle:
var tmpl tpm2.Public keyHnd, _, err = tpm2.CreatePrimary(t.rwc, tpm2.HandleEndorsement, tpm2.PCRSelection{}, "", "", t.ekTemplate())
if tmpl, err = t.ekTemplate(); err != nil {
return 0, false, fmt.Errorf("ek template: %v", err)
}
keyHnd, _, err = tpm2.CreatePrimary(t.rwc, tpm2.HandleEndorsement, tpm2.PCRSelection{}, "", "", tmpl)
} }
if err != nil { if err != nil {
return 0, false, fmt.Errorf("ReadPublic failed (%v), and then CreatePrimary failed: %v", rerr, err) return 0, false, fmt.Errorf("ReadPublic failed (%v), and then CreatePrimary failed: %v", rerr, err)
@ -124,12 +120,7 @@ func (t *wrappedTPM20) eks() ([]EK, error) {
} }
// Attempt to create an EK. // Attempt to create an EK.
tmpl, err := t.ekTemplate() ekHnd, _, err := tpm2.CreatePrimary(t.rwc, tpm2.HandleEndorsement, tpm2.PCRSelection{}, "", "", t.ekTemplate())
if err != nil {
return nil, fmt.Errorf("ek template: %v", err)
}
ekHnd, _, err := tpm2.CreatePrimary(t.rwc, tpm2.HandleEndorsement, tpm2.PCRSelection{}, "", "", tmpl)
if err != nil { if err != nil {
return nil, fmt.Errorf("EK CreatePrimary failed: %v", err) return nil, fmt.Errorf("EK CreatePrimary failed: %v", err)
} }