Skip to content

Commit

Permalink
Make tpm2 quote functions accept PCR selections for multiple banks
Browse files Browse the repository at this point in the history
  • Loading branch information
Hans-Gert Dahmen committed Mar 10, 2022
1 parent 77d0de8 commit 9a7fe02
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
6 changes: 3 additions & 3 deletions tpm2/structures.go
Original file line number Diff line number Diff line change
Expand Up @@ -823,13 +823,13 @@ func (ci CertifyInfo) encode() ([]byte, error) {

// QuoteInfo represents a TPMS_QUOTE_INFO structure.
type QuoteInfo struct {
PCRSelection PCRSelection
PCRSelection []PCRSelection
PCRDigest tpmutil.U16Bytes
}

func decodeQuoteInfo(in *bytes.Buffer) (*QuoteInfo, error) {
var out QuoteInfo
sel, err := decodeOneTPMLPCRSelection(in)
sel, err := decodeTPMLPCRSelection(in)
if err != nil {
return nil, fmt.Errorf("decoding PCRSelection: %v", err)
}
Expand All @@ -842,7 +842,7 @@ func decodeQuoteInfo(in *bytes.Buffer) (*QuoteInfo, error) {
}

func (qi QuoteInfo) encode() ([]byte, error) {
sel, err := encodeTPMLPCRSelection(qi.PCRSelection)
sel, err := encodeTPMLPCRSelection(qi.PCRSelection...)
if err != nil {
return nil, fmt.Errorf("encoding PCRSelection: %v", err)
}
Expand Down
3 changes: 2 additions & 1 deletion tpm2/test/tpm2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"testing"

"github.com/google/go-tpm-tools/simulator"
"github.com/google/go-tpm/tpm2"
. "github.com/google/go-tpm/tpm2"
"github.com/google/go-tpm/tpmutil"
)
Expand Down Expand Up @@ -1670,7 +1671,7 @@ func TestQuote(t *testing.T) {
}
defer FlushContext(rw, keyHandle)

attestation, signature, err := Quote(rw, keyHandle, emptyPassword, emptyPassword, nil, pcrSelection7, AlgNull)
attestation, signature, err := Quote(rw, keyHandle, emptyPassword, emptyPassword, nil, []tpm2.PCRSelection{pcrSelection7}, AlgNull)
if err != nil {
t.Fatalf("Quote failed: %v", err)
}
Expand Down
8 changes: 4 additions & 4 deletions tpm2/tpm2.go
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ func UnsealWithSession(rw io.ReadWriter, sessionHandle, itemHandle tpmutil.Handl
return decodeUnseal(resp)
}

func encodeQuote(signingHandle tpmutil.Handle, signerAuth string, toQuote tpmutil.U16Bytes, sel PCRSelection, sigAlg Algorithm) ([]byte, error) {
func encodeQuote(signingHandle tpmutil.Handle, signerAuth string, toQuote tpmutil.U16Bytes, sel []PCRSelection, sigAlg Algorithm) ([]byte, error) {
ha, err := tpmutil.Pack(signingHandle)
if err != nil {
return nil, err
Expand All @@ -963,7 +963,7 @@ func encodeQuote(signingHandle tpmutil.Handle, signerAuth string, toQuote tpmuti
if err != nil {
return nil, err
}
pcrs, err := encodeTPMLPCRSelection(sel)
pcrs, err := encodeTPMLPCRSelection(sel...)
if err != nil {
return nil, err
}
Expand All @@ -988,7 +988,7 @@ func decodeQuote(in []byte) ([]byte, []byte, error) {
// values, created using a signing TPM key.
//
// Returns attestation data and the decoded signature.
func Quote(rw io.ReadWriter, signingHandle tpmutil.Handle, signerAuth, unused string, toQuote []byte, sel PCRSelection, sigAlg Algorithm) ([]byte, *Signature, error) {
func Quote(rw io.ReadWriter, signingHandle tpmutil.Handle, signerAuth, unused string, toQuote []byte, sel []PCRSelection, sigAlg Algorithm) ([]byte, *Signature, error) {
// TODO: Remove "unused" parameter on next breaking change.
attest, sigRaw, err := QuoteRaw(rw, signingHandle, signerAuth, unused, toQuote, sel, sigAlg)
if err != nil {
Expand All @@ -1003,7 +1003,7 @@ func Quote(rw io.ReadWriter, signingHandle tpmutil.Handle, signerAuth, unused st

// QuoteRaw is very similar to Quote, except that it will return
// the raw signature in a byte array without decoding.
func QuoteRaw(rw io.ReadWriter, signingHandle tpmutil.Handle, signerAuth, unused string, toQuote []byte, sel PCRSelection, sigAlg Algorithm) ([]byte, []byte, error) {
func QuoteRaw(rw io.ReadWriter, signingHandle tpmutil.Handle, signerAuth, unused string, toQuote []byte, sel []PCRSelection, sigAlg Algorithm) ([]byte, []byte, error) {
// TODO: Remove "unused" parameter on next breaking change.
Cmd, err := encodeQuote(signingHandle, signerAuth, toQuote, sel, sigAlg)
if err != nil {
Expand Down

0 comments on commit 9a7fe02

Please sign in to comment.