Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements #177

Merged
merged 2 commits into from
Mar 5, 2024
Merged
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
1 change: 1 addition & 0 deletions attestationreport/attestationreport.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@ func Verify(arRaw, nonce, casPem []byte, policies []byte, polEng PolicyEngineSel
if code != NotSet {
result.ErrorCode = code
result.Success = false
return result
}

// Verify and unpack metadata from attestation report
Expand Down
4 changes: 2 additions & 2 deletions attestationreport/tpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ func recalculatePcrs(measurement Measurement, referenceValues []ReferenceValue)
EventData: event.EventData,
}
detailedResults = append(detailedResults, measResult)
log.Tracef("Failed to find measurement %v in reference values",
hex.EncodeToString(event.Sha256))
log.Tracef("Failed to find PCR%v measurement %v: %v in reference values",
measuredPcr.Pcr, event.EventName, hex.EncodeToString(event.Sha256))
ok = false
pcrResult.Success = false
continue
Expand Down
59 changes: 51 additions & 8 deletions ima/ima.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,19 @@
template.header = header
copy(template.Name[:], name)

var len uint32
var length uint32
if strings.Compare(string(template.Name[:]), "ima") == 0 {
template.DataLen = SHA1_DIGEST_LEN + MAX_TCG_EVENT_LEN + 1
len = SHA1_DIGEST_LEN
length = SHA1_DIGEST_LEN
} else {
err = binary.Read(buf, binary.LittleEndian, &template.DataLen)
if err != nil {
return nil, fmt.Errorf("error reading binary data: %w", err)
}
len = template.DataLen
length = template.DataLen
}

template.Data = make([]byte, len)
template.Data = make([]byte, length)
err = binary.Read(buf, binary.LittleEndian, template.Data)
if err != nil {
return nil, fmt.Errorf("error reading binary data: %w", err)
Expand All @@ -122,16 +122,59 @@
// template must be calculated manually
digest := sha256.Sum256(template.Data)

// Parse the template data to retrieve additional information
_, eventName, err := parseTemplateData(&template)
if err != nil {
log.Tracef("Failed to parse addtional template data: %v", err)

Check failure on line 128 in ima/ima.go

View workflow job for this annotation

GitHub Actions / ci

"addtional" is a misspelling of "additional"
}

event := ar.PcrEvent{
Sha256: digest[:],
// TODO EventName: parseEventName(template.Data)
EventName: "",
Sha256: digest[:],
EventName: eventName,
}

log.Tracef("Parsed PCR%v IMA %v event", header.Pcr, string(template.Name[:]))
log.Tracef("Parsed IMA PCR%v %v event %v", header.Pcr,
string(template.Name[:template.header.NameLen]), eventName)

events = append(events, event)
}

return events, nil
}

func parseTemplateData(tmpl *imaTemplate) ([]byte, string, error) {

if !bytes.Equal(tmpl.Name[:tmpl.header.NameLen], []byte("ima-ng")) &&
!bytes.Equal(tmpl.Name[:tmpl.header.NameLen], []byte("ima-sig")) {
return nil, "", fmt.Errorf("template %v parsing additional information not supported", tmpl.Name[:tmpl.header.NameLen])
}

var tmplDigestLen uint32
buf := bytes.NewBuffer(tmpl.Data)
err := binary.Read(buf, binary.LittleEndian, &tmplDigestLen)
if err != nil {
return nil, "", fmt.Errorf("failed to read digest length from template: %w", err)
}

tmplDigest := make([]byte, tmplDigestLen)
err = binary.Read(buf, binary.LittleEndian, tmplDigest)
if err != nil {
return nil, "", fmt.Errorf("failed to read digest from template: %w", err)
}

var tmplPathLen uint32
err = binary.Read(buf, binary.LittleEndian, &tmplPathLen)
if err != nil {
return nil, "", fmt.Errorf("failed to read digest length from template: %w", err)
}

tmplPath := make([]byte, tmplPathLen)
err = binary.Read(buf, binary.LittleEndian, tmplPath)
if err != nil {
return nil, "", fmt.Errorf("failed to read path from template: %w", err)
}
// Strip the path from the parsed \0 byte
tmplPath = tmplPath[:len(tmplPath)-1]

return tmplDigest, string(tmplPath), nil
}
Loading