Skip to content
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

Move TPM Seal/Unseal test to tpmmgr_test #3005

Merged
merged 3 commits into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions pkg/pillar/cmd/tpmmgr/tpmmgr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"fmt"
"io/ioutil"
"os"
"reflect"
"testing"
"time"

Expand Down Expand Up @@ -201,3 +202,24 @@ func TestVerifyEdgeNodeCerts(t *testing.T) {
return
}
}

func TestSealUnseal(t *testing.T) {
_, err := os.Stat(etpm.TpmDevicePath)
if err != nil {
t.Skip("TPM is not available, skipping the test.")
}

dataToSeal := []byte("secret")
if err := etpm.SealDiskKey(dataToSeal, etpm.DiskKeySealingPCRs); err != nil {
t.Errorf("Seal operation failed with err: %v", err)
return
}
unsealedData, err := etpm.UnsealDiskKey(etpm.DiskKeySealingPCRs)
if err != nil {
t.Errorf("Unseal operation failed with err: %v", err)
return
}
if !reflect.DeepEqual(dataToSeal, unsealedData) {
t.Errorf("Seal/Unseal operation failed, want %v, but got %v", dataToSeal, unsealedData)
}
}
17 changes: 0 additions & 17 deletions pkg/pillar/evetpm/tpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"io/ioutil"
"math/big"
"os"
"reflect"
"unsafe"

"github.com/google/go-tpm/tpm2"
Expand Down Expand Up @@ -704,22 +703,6 @@ func PolicyPCRSession(rw io.ReadWriteCloser, pcrSel tpm2.PCRSelection) (tpmutil.
return session, policy, nil
}

// TestSealUnseal tests TPM2.0 Seal and Unseal commands
func TestSealUnseal() error {
dataToSeal := []byte("secret")
if err := SealDiskKey(dataToSeal, DiskKeySealingPCRs); err != nil {
return err
}
unsealedData, err := UnsealDiskKey(DiskKeySealingPCRs)
if err != nil {
return err
}
if !reflect.DeepEqual(dataToSeal, unsealedData) {
return fmt.Errorf("want %v, but got %v", dataToSeal, unsealedData)
}
return nil
}

// CompareLegacyandSealedKey compares legacy and sealed keys
// to record if we are using a new key for sealed vault
func CompareLegacyandSealedKey() SealedKeyType {
Expand Down