Skip to content
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
17 changes: 14 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ help:
# make build Build companion tools
# make check Run all tests
# make check-efi-preinstall Run tests of package efi/preinstall
# make check-efi Run tests of package efi
# make list-packages List Go packages


.PHONY: build check check-tpm2-simulator FORCE
FORCE:

# Build command line programs
build:
go build -o test_efi_fde_compat cmd/test_efi_fde_compat/main.go
go build -o run_argon2 cmd/run_argon2/main.go

.PHONY: check check-tpm2-simulator FORCE
FORCE:

# Disable optimization and inlining (to facilitate step-by-step debugging)
GCFLAGS = -gcflags "-N -l"

Expand All @@ -33,5 +34,15 @@ check-efi-preinstall: check-efi-preinstall.bin check-tpm2-simulator
# go tool cover -func=coverage.out
# or: go tool cover -html=coverage.out

check-efi.bin: FORCE
go test -cover -c -o $@ $(GCFLAGS) ./efi -v -ldflags '-X github.com/snapcore/secboot/internal/testenv.testBinary=enabled' -race -p 1

check-efi: check-efi.bin check-tpm2-simulator
@# cd to efi/. as testdata is expected in .
cd efi && ../$< -test.coverprofile=coverage.out -check.v

fmt:
go fmt ./...

list-packages:
go list ./...
8 changes: 8 additions & 0 deletions cmd/test_efi_fde_compat/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/jessevdk/go-flags"
secboot_efi "github.com/snapcore/secboot/efi"
"github.com/snapcore/secboot/efi/preinstall"
efi "github.com/snapcore/secboot/internal/efi"
"github.com/snapcore/snapd/snap/snapdir"
"github.com/snapcore/snapd/snap/squashfs"
)
Expand Down Expand Up @@ -36,6 +37,8 @@ type options struct {

Action preinstall.Action `long:"action" description:"What action to run"`

EventLog string `long:"event-log" description:"Alternate TCG event log" value-name:"EVENT-LOG"`

Positional struct {
BootImages []string `positional-arg-name:"ordered paths to the EFI boot components for the current boot"`
} `positional-args:"true"`
Expand Down Expand Up @@ -80,6 +83,11 @@ func run() error {
checkFlags |= preinstall.PermitNoHardwareRootOfTrust
}

if opts.EventLog != "" {
efi.SetEventLogPath(opts.EventLog)
}
fmt.Println("Using TCG event log:", efi.EventLogPath())

var bootImages []secboot_efi.Image
for _, img := range opts.Positional.BootImages {
var snapPath string
Expand Down
9 changes: 6 additions & 3 deletions efi/efi.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@

package efi

import "github.com/canonical/go-tpm2"
import (
"fmt"
"github.com/canonical/go-tpm2"
)

const (
kernelConfigPCR tpm2.Handle = 12
Expand All @@ -34,7 +37,7 @@ func makePcrFlags(pcrs ...tpm2.Handle) pcrFlags {
var out pcrFlags
for _, pcr := range pcrs {
if pcr >= 32 {
panic("invalid PCR")
panic(fmt.Sprintf("invalid PCR: %v", pcr))
}
out |= 1 << pcr
}
Expand All @@ -54,7 +57,7 @@ func (f pcrFlags) PCRs() (out tpm2.HandleList) {
func (f pcrFlags) Contains(pcrs ...tpm2.Handle) bool {
for _, pcr := range pcrs {
if pcr >= 32 {
panic("invalid PCR")
panic(fmt.Sprintf("invalid PCR: %v", pcr))
}
if f&(1<<pcr) == 0 {
return false
Expand Down
2 changes: 1 addition & 1 deletion efi/pcr_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func WithPlatformFirmwareProfile() PCRProfileEnablePCRsOption {

// WithDriversAndAppsProfile adds the UEFI Drivers and UEFI Applications profile
// (measured to PCR2). This is copied directly from the current host environment
// configiguration.
// configuration.
func WithDriversAndAppsProfile() PCRProfileEnablePCRsOption {
return newPcrProfileSetPcrOption(internal_efi.DriversAndAppsPCR)
}
Expand Down
6 changes: 3 additions & 3 deletions efi/pcr_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import (

efi "github.com/canonical/go-efilib"
"github.com/canonical/go-tpm2"
"github.com/canonical/go-tpm2/policyutil"
tpm2_testutil "github.com/canonical/go-tpm2/testutil"
"github.com/canonical/go-tpm2/util"
"github.com/canonical/tcglog-parser"
. "gopkg.in/check.v1"

Expand Down Expand Up @@ -121,7 +121,7 @@ func (s *pcrProfileMockedSuite) TestAddPCRProfileSimple(c *C) {
profile := secboot_tpm2.NewPCRProtectionProfile()

var digests tpm2.DigestList
for i := 0; i <= 2; i++ {
for i := 0; i <= 1; i++ {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's this change about?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original loop creates 3 items in the list, but only the first 2 are used in the test.
This modification is to remove useless code and processing.

h := crypto.SHA256.New()
io.WriteString(h, strconv.Itoa(i))
digests = append(digests, h.Sum(nil))
Expand Down Expand Up @@ -633,7 +633,7 @@ func (s *pcrProfileSuite) testAddPCRProfile(c *C, data *testAddPCRProfileData, o
var expectedPcrs tpm2.PCRSelectionList
var expectedDigests tpm2.DigestList
for i, v := range data.expected {
pcrs, digest, err := util.ComputePCRDigestFromAllValues(tpm2.HashAlgorithmSHA256, v)
pcrs, digest, err := policyutil.ComputePCRDigestFromAllValues(tpm2.HashAlgorithmSHA256, v)
c.Assert(err, IsNil)
if i == 0 {
expectedPcrs = pcrs
Expand Down
2 changes: 1 addition & 1 deletion efi/preinstall/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,7 @@ func wrapPCRError(pcr tpm2.Handle, err error) error {
case 7:
return &SecureBootPolicyPCRError{err}
default:
panic("invalid PCR")
panic(fmt.Sprintf("invalid PCR: %v", pcr))
}
}

Expand Down
8 changes: 8 additions & 0 deletions internal/efi/default_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ var (
eventLogPath = "/sys/kernel/security/tpm0/binary_bios_measurements" // Path of the TCG event log for the default TPM, in binary form
)

func SetEventLogPath(path string) {
eventLogPath = path
}

func EventLogPath() string {
return eventLogPath
}

// decodeKernelUeventParams decodes the uevent attribute for the device associated
// with the supplied sysfs path, and returns a map of variables.
//
Expand Down
Loading