-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add HierarchyChangeAuth command (#357)
see definition in Part 3, Commands, section 24.8
- Loading branch information
Showing
2 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,65 @@ | ||
package tpm2test | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
. "github.com/google/go-tpm/tpm2" | ||
"github.com/google/go-tpm/tpm2/transport/simulator" | ||
) | ||
|
||
func TestHierarchyChangeAuth(t *testing.T) { | ||
thetpm, err := simulator.OpenSimulator() | ||
if err != nil { | ||
t.Fatalf("could not connect to TPM simulator: %v", err) | ||
} | ||
defer thetpm.Close() | ||
|
||
authKey := []byte("authkey") | ||
newAuthKey := []byte("newAuthKey") | ||
|
||
t.Run("HierarchyChangeAuthOwner", func(t *testing.T) { | ||
hca := HierarchyChangeAuth{ | ||
AuthHandle: TPMRHOwner, | ||
NewAuth: TPM2BAuth{ | ||
Buffer: authKey, | ||
}, | ||
} | ||
|
||
_, err := hca.Execute(thetpm) | ||
if err != nil { | ||
t.Errorf("failed HierarchyChangeAuth: %v", err) | ||
} | ||
}) | ||
|
||
t.Run("HierarchyChangeAuthOwnerUnauth", func(t *testing.T) { | ||
hca := HierarchyChangeAuth{ | ||
AuthHandle: TPMRHOwner, | ||
NewAuth: TPM2BAuth{ | ||
Buffer: newAuthKey, | ||
}, | ||
} | ||
|
||
_, err := hca.Execute(thetpm) | ||
if !errors.Is(err, TPMRCBadAuth) { | ||
t.Errorf("failed HierarchyChangeAuthWithoutAuth: want TPM_RC_BAD_AUTH, got %v", err) | ||
} | ||
}) | ||
|
||
t.Run("HierarchyChangeAuthOwnerAuth", func(t *testing.T) { | ||
hca := HierarchyChangeAuth{ | ||
AuthHandle: AuthHandle{ | ||
Handle: TPMRHOwner, | ||
Auth: PasswordAuth(authKey), | ||
}, | ||
NewAuth: TPM2BAuth{ | ||
Buffer: newAuthKey, | ||
}, | ||
} | ||
|
||
_, err := hca.Execute(thetpm) | ||
if err != nil { | ||
t.Errorf("failed HierarchyChangeAuthWithAuth: %v", err) | ||
} | ||
}) | ||
} |
This file contains 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