Skip to content

Commit

Permalink
tpm2: fix some test panics
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisccoulson committed Sep 10, 2024
1 parent fe8b71d commit 6d89a46
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
21 changes: 21 additions & 0 deletions tpm2/platform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,27 @@ func (s *platformSuite) TestRecoverKeysWithPassphraseIntegrated(c *C) {
c.Check(primaryKeyUnsealed, DeepEquals, primaryKey)
}

func (s *platformSuite) TestRecoverKeysWithPassphraseIntegratedPBKDF2(c *C) {
params := &ProtectKeyParams{
PCRProfile: tpm2test.NewPCRProfileFromCurrentValues(tpm2.HashAlgorithmSHA256, []int{7}),
PCRPolicyCounterHandle: s.NextAvailableHandle(c, 0x0181fff0),
Role: "",
}

passphraseParams := &PassphraseProtectKeyParams{
ProtectKeyParams: *params,
KDFOptions: new(secboot.PBKDF2Options),
}

k, primaryKey, unlockKey, err := NewTPMPassphraseProtectedKey(s.TPM(), passphraseParams, "passphrase")
c.Assert(err, IsNil)

unlockKeyUnsealed, primaryKeyUnsealed, err := k.RecoverKeysWithPassphrase("passphrase")
c.Check(err, IsNil)
c.Check(unlockKeyUnsealed, DeepEquals, unlockKey)
c.Check(primaryKeyUnsealed, DeepEquals, primaryKey)
}

func (s *platformSuite) TestRecoverKeysWithBadPassphraseIntegrated(c *C) {
key := make(secboot.DiskUnlockKey, 32)
rand.Read(key)
Expand Down
4 changes: 2 additions & 2 deletions tpm2/seal.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ type ProtectKeyParams struct {
type PassphraseProtectKeyParams struct {
ProtectKeyParams

KDFOptions *secboot.Argon2Options
KDFOptions secboot.KDFOptions
}

type keyDataConstructor func(skd *SealedKeyData, role string, encryptedPayload []byte, kdfAlg crypto.Hash) (*secboot.KeyData, error)
Expand All @@ -79,7 +79,7 @@ func makeKeyDataNoAuth(skd *SealedKeyData, role string, encryptedPayload []byte,
})
}

func makeKeyDataWithPassphraseConstructor(kdfOptions *secboot.Argon2Options, passphrase string) keyDataConstructor {
func makeKeyDataWithPassphraseConstructor(kdfOptions secboot.KDFOptions, passphrase string) keyDataConstructor {
return func(skd *SealedKeyData, role string, encryptedPayload []byte, kdfAlg crypto.Hash) (*secboot.KeyData, error) {
return secbootNewKeyDataWithPassphrase(&secboot.KeyWithPassphraseParams{
KeyParams: secboot.KeyParams{
Expand Down

0 comments on commit 6d89a46

Please sign in to comment.