forked from google/go-tpm-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more CosTlv ops related to CEL, able to parse a COS CEL to a Mach…
…ineState Add digest verification when replaying/parsing the CEL
- Loading branch information
Showing
12 changed files
with
513 additions
and
84 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
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
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
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,62 @@ | ||
package cel | ||
|
||
import ( | ||
"bytes" | ||
"crypto" | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"github.com/google/go-tpm-tools/client" | ||
"github.com/google/go-tpm-tools/internal/test" | ||
pb "github.com/google/go-tpm-tools/proto/attest" | ||
) | ||
|
||
func TestCosEventlog(t *testing.T) { | ||
tpm := test.GetTPM(t) | ||
defer client.CheckedClose(t, tpm) | ||
|
||
hashAlgoList := []crypto.Hash{crypto.SHA256, crypto.SHA1, crypto.SHA512} | ||
cel := &CEL{} | ||
|
||
testEvents := []struct { | ||
cosNestedEventType CosType | ||
pcr int | ||
eventPayload []byte | ||
}{ | ||
{ImageRefType, test.DebugPCR, []byte("docker.io/bazel/experimental/test:latest")}, | ||
{ImageDigestType, test.DebugPCR, []byte("sha256:781d8dfdd92118436bd914442c8339e653b83f6bf3c1a7a98efcfb7c4fed7483")}, | ||
{RestartPolicyType, test.DebugPCR, []byte(pb.RestartPolicy_NEVER.String())}, | ||
} | ||
|
||
for _, testEvent := range testEvents { | ||
cos := CosTlv{testEvent.cosNestedEventType, testEvent.eventPayload} | ||
if err := cel.AppendEvent(tpm, testEvent.pcr, hashAlgoList, cos); err != nil { | ||
t.Fatal(err.Error()) | ||
} | ||
} | ||
|
||
var buf bytes.Buffer | ||
if err := cel.EncodeCEL(&buf); err != nil { | ||
t.Fatal(err) | ||
} | ||
decodedcel, err := DecodeToCEL(&buf) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if len(decodedcel.Records) != 3 { | ||
t.Errorf("should have three records") | ||
} | ||
|
||
for i, testEvent := range testEvents { | ||
extractedCos, err := decodedcel.Records[i].Content.ParseToCosTlv() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
want := CosTlv{testEvent.cosNestedEventType, testEvent.eventPayload} | ||
if !cmp.Equal(extractedCos, want) { | ||
t.Errorf("decoded COS TLV got %+v, want %+v", extractedCos, want) | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.