Skip to content
Open
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
17 changes: 11 additions & 6 deletions cel/canonical_eventlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ type Record struct {
// Generic Measurement Register index number, register type
// is determined by IndexType
Index uint8
IndexType uint8
IndexType MRType
Digests map[crypto.Hash][]byte
Content TLV
}
Expand Down Expand Up @@ -205,7 +205,7 @@ func (c *eventLog) AppendEvent(event Content, bankAlgos []crypto.Hash, mrIndex i
Index: uint8(mrIndex),
Digests: digestMap,
Content: eventTlv,
IndexType: uint8(c.Type),
IndexType: c.Type,
}

c.Recs = append(c.Recs, celrPCR)
Expand Down Expand Up @@ -246,8 +246,13 @@ func createIndexField(indexType uint8, indexNum uint8) TLV {

// unmarshalIndex takes in a TLV with its type equals to the PCR or CCMR type value, and
// return its index number.
func unmarshalIndex(tlv TLV) (indexType uint8, pcrNum uint8, err error) {
if tlv.Type != uint8(PCRType) && tlv.Type != uint8(CCMRType) {
func unmarshalIndex(tlv TLV) (indexType MRType, pcrNum uint8, err error) {
switch tlv.Type {
case uint8(PCRType):
indexType = PCRType
case uint8(CCMRType):
indexType = CCMRType
default:
return 0, 0, fmt.Errorf("type of the TLV [%d] indicates it is not a PCR [%d] or a CCMR [%d] field ",
tlv.Type, uint8(PCRType), uint8(CCMRType))
}
Expand All @@ -257,7 +262,7 @@ func unmarshalIndex(tlv TLV) (indexType uint8, pcrNum uint8, err error) {
len(tlv.Value), regIndexValueLength)
}

return tlv.Type, tlv.Value[0], nil
return indexType, tlv.Value[0], nil
}

func createDigestField(digestMap map[crypto.Hash][]byte) (TLV, error) {
Expand Down Expand Up @@ -318,7 +323,7 @@ func (r *Record) EncodeCELR(buf *bytes.Buffer) error {
return err
}

indexField, err := createIndexField(r.IndexType, r.Index).MarshalBinary()
indexField, err := createIndexField(uint8(r.IndexType), r.Index).MarshalBinary()
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions cel/canonical_eventlog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ func TestCELEncodingDecoding(t *testing.T) {
if decodedcel.Records()[1].RecNum != 1 {
t.Errorf("recnum mismatch")
}
if decodedcel.Records()[0].IndexType != uint8(tc) {
if decodedcel.Records()[0].IndexType != tc {
t.Errorf("index type mismatch")
}
if decodedcel.Records()[0].Index != uint8(16) {
t.Errorf("pcr value mismatch")
}
if decodedcel.Records()[1].IndexType != uint8(tc) {
if decodedcel.Records()[1].IndexType != tc {
t.Errorf("index type mismatch")
}
if decodedcel.Records()[1].Index != uint8(23) {
Expand Down Expand Up @@ -90,7 +90,7 @@ func TestCELAppendDifferentMRTypes(t *testing.T) {
appendFakeMREventOrFatal(t, &el, rot, 8, measuredHashes, event)

for _, rec := range el.Records() {
if rec.IndexType != uint8(tc) {
if rec.IndexType != tc {
t.Errorf("AppendEvent(): got Index Type %v, want type %v", rec.IndexType, tc)
}
}
Expand Down
5 changes: 4 additions & 1 deletion extract/extract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/google/go-eventlog/register"
"github.com/google/go-eventlog/tcg"
"github.com/google/go-eventlog/testdata"
"google.golang.org/protobuf/encoding/protojson"
)

func TestExtractFirmwareLogStateRTMR(t *testing.T) {
Expand Down Expand Up @@ -147,10 +148,12 @@ func TestExtractFirmwareLogStateRTMR(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
evts := getCCELEvents(t)
tc.mutate(evts)
_, err := FirmwareLogState(evts, crypto.SHA384, RTMRRegisterConfig, Opts{Loader: GRUB})
fs, err := FirmwareLogState(evts, crypto.SHA384, RTMRRegisterConfig, Opts{Loader: GRUB})
if (err != nil) != tc.expectErr {
t.Errorf("ExtractFirmwareLogState(%v) = got %v, wantErr: %v", tc.name, err, tc.expectErr)
}
bts, _ := protojson.MarshalOptions{UseProtoNames: true}.Marshal(fs)
t.Log(string(bts))
})
}
}
Expand Down
Loading