Skip to content

Commit

Permalink
feat: tpm2.EvictControl
Browse files Browse the repository at this point in the history
  • Loading branch information
jclab-joseph committed Jul 20, 2023
1 parent f17b035 commit 610962e
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tpm2/structures.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,10 @@ type TPMIYesNo = bool
// See definition in Part 2: Structures, section 9.3.
type TPMIDHObject = TPMHandle

// TPMIDHPersistent represents a TPMI_DH_PERSISTENT.
// See definition in Part 2: Structures, section 9.5.
type TPMIDHPersistent = TPMHandle

// TPMIDHEntity represents a TPMI_DH_ENTITY.
// See definition in Part 2: Structures, section 9.6.
type TPMIDHEntity = TPMHandle
Expand Down
38 changes: 38 additions & 0 deletions tpm2/test/evict_control_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package tpm2test

import (
"testing"

. "github.com/google/go-tpm/tpm2"
"github.com/google/go-tpm/tpm2/transport/simulator"
)

func TestEvictControl(t *testing.T) {
thetpm, err := simulator.OpenSimulator()
if err != nil {
t.Fatalf("could not connect to TPM simulator: %v", err)
}
defer thetpm.Close()

srkCreate := CreatePrimary{
PrimaryHandle: TPMRHOwner,
InPublic: New2B(ECCSRKTemplate),
}

srkCreateRsp, err := srkCreate.Execute(thetpm)
if err != nil {
t.Fatalf("could not generate SRK: %v", err)
}

_, err := EvictControl{
Auth: TPMRHOwner,
ObjectHandle: &NamedHandle{
Handle: srkCreateRsp.ObjectHandle,
Name: srkCreateRsp.Name,
},
PersistentHandle: 0x81000000,
}.Execute(thetpm)
if err != nil {
t.Fatalf("could not persist: %v", err)
}
}
24 changes: 24 additions & 0 deletions tpm2/tpm2.go
Original file line number Diff line number Diff line change
Expand Up @@ -1469,6 +1469,30 @@ func (cmd FlushContext) Execute(t transport.TPM, s ...Session) (*FlushContextRes
// FlushContextResponse is the response from TPM2_FlushContext.
type FlushContextResponse struct{}

// EvictControl is the input to TPM2_EvictControl.
// See definition in Part 3, Commands, section 28.5
type EvictControl struct {
// TPM_RH_OWNER or TPM_RH_PLATFORM+{PP}
Auth handle `gotpm:"handle,auth"`
ObjectHandle handle `gotpm:"handle"`
PersistentHandle TPMIDHPersistent
}

// EvictControlResponse is the response from TPM2_EvictControl.
type EvictControlResponse struct{}

// Command implements the Command interface.
func (EvictControl) Command() TPMCC { return TPMCCEvictControl }

// Execute executes the command and returns the response.
func (cmd EvictControl) Execute(t transport.TPM, s ...Session) (*EvictControlResponse, error) {
var rsp EvictControlResponse
if err := execute[EvictControlResponse](t, cmd, &rsp, s...); err != nil {
return nil, err
}
return &rsp, nil
}

// GetCapability is the input to TPM2_GetCapability.
// See definition in Part 3, Commands, section 30.2
type GetCapability struct {
Expand Down

0 comments on commit 610962e

Please sign in to comment.