diff --git a/release/firmware/ftlog/log_entries.go b/release/firmware/ftlog/log_entries.go index ed11add..4108f40 100644 --- a/release/firmware/ftlog/log_entries.go +++ b/release/firmware/ftlog/log_entries.go @@ -66,12 +66,12 @@ type FirmwareRelease struct { // BuildEnvs contains all environment variables set for this build. Each value in the string // array will be a single key/value assignment, such as "DEBUG=1". - BuildEnvs []string `json:"build_envs"` + BuildEnvs []string `json:"build_envs,omitempty"` // HAB holds a signature and related data for firmware which must be authenticated // by the device's mask ROM at boot. // Currently, this is only meaningful for Bootloader and Recovery firmware images. - HAB HAB `json:"hab"` + HAB *HAB `json:"hab,omitempty"` } // HAB holds information relating to SecureBoot. diff --git a/release/firmware/update/fetch.go b/release/firmware/update/fetch.go index cef314a..a3fb753 100644 --- a/release/firmware/update/fetch.go +++ b/release/firmware/update/fetch.go @@ -79,6 +79,9 @@ func BinaryPath(fr ftlog.FirmwareRelease) (string, error) { // HABSignaturePath returns the relative path within a bucket for the HAB signature referenced by the manifest. func HABSignaturePath(fr ftlog.FirmwareRelease) (string, error) { + if fr.HAB == nil { + return "", errors.New("no HAB information in manifest") + } if len(fr.HAB.SignatureDigestSha256) == 0 { return "", errors.New("HAB signature digest unset") } @@ -267,8 +270,12 @@ func (f *Fetcher) Scan(ctx context.Context) error { continue } isHABComponent := manifest.Component == ftlog.ComponentBoot || manifest.Component == ftlog.ComponentRecovery - if isHABComponent && f.habTarget != "" && f.habTarget != manifest.HAB.Target { - klog.V(1).Infof("Skipping leaf %d as manifest hab target %q != required target %q", i, manifest.HAB.Target, f.habTarget) + if isHABComponent && f.habTarget != "" && (manifest.HAB == nil || f.habTarget != manifest.HAB.Target) { + mt := "nil" + if manifest.HAB != nil { + mt = manifest.HAB.Target + } + klog.V(1).Infof("Skipping leaf %d as manifest hab target %q != required target %q", i, mt, f.habTarget) continue } bundle := &firmware.Bundle{ diff --git a/release/firmware/update/fetch_test.go b/release/firmware/update/fetch_test.go index 3bd368f..2776405 100644 --- a/release/firmware/update/fetch_test.go +++ b/release/firmware/update/fetch_test.go @@ -137,22 +137,38 @@ func TestFetcher(t *testing.T) { { {Component: ftlog.ComponentOS, GitTagName: *semver.New("1.0.1")}, {Component: ftlog.ComponentApplet, GitTagName: *semver.New("1.1.1")}, - {HAB: ftlog.HAB{Target: "orange"}, Component: ftlog.ComponentBoot, GitTagName: *semver.New("1.3.1")}, - {HAB: ftlog.HAB{Target: "orange"}, Component: ftlog.ComponentRecovery, GitTagName: *semver.New("1.1.1")}, + {HAB: &ftlog.HAB{Target: "orange"}, Component: ftlog.ComponentBoot, GitTagName: *semver.New("1.3.1")}, + {HAB: &ftlog.HAB{Target: "orange"}, Component: ftlog.ComponentRecovery, GitTagName: *semver.New("1.1.1")}, }, { - {HAB: ftlog.HAB{Target: "orange"}, Component: ftlog.ComponentBoot, GitTagName: *semver.New("1.4.1")}, - {HAB: ftlog.HAB{Target: "banana"}, Component: ftlog.ComponentRecovery, GitTagName: *semver.New("1.8.1")}, // this should be ignored + {HAB: &ftlog.HAB{Target: "orange"}, Component: ftlog.ComponentBoot, GitTagName: *semver.New("1.4.1")}, + {HAB: &ftlog.HAB{Target: "banana"}, Component: ftlog.ComponentRecovery, GitTagName: *semver.New("1.8.1")}, // this should be ignored }, }, want: [][]ftlog.FirmwareRelease{ { - {HAB: ftlog.HAB{Target: "orange"}, Component: ftlog.ComponentBoot, GitTagName: *semver.New("1.3.1")}, - {HAB: ftlog.HAB{Target: "orange"}, Component: ftlog.ComponentRecovery, GitTagName: *semver.New("1.1.1")}, + {HAB: &ftlog.HAB{Target: "orange"}, Component: ftlog.ComponentBoot, GitTagName: *semver.New("1.3.1")}, + {HAB: &ftlog.HAB{Target: "orange"}, Component: ftlog.ComponentRecovery, GitTagName: *semver.New("1.1.1")}, }, { - {HAB: ftlog.HAB{Target: "orange"}, Component: ftlog.ComponentBoot, GitTagName: *semver.New("1.4.1")}, - {HAB: ftlog.HAB{Target: "orange"}, Component: ftlog.ComponentRecovery, GitTagName: *semver.New("1.1.1")}, + {HAB: &ftlog.HAB{Target: "orange"}, Component: ftlog.ComponentBoot, GitTagName: *semver.New("1.4.1")}, + {HAB: &ftlog.HAB{Target: "orange"}, Component: ftlog.ComponentRecovery, GitTagName: *semver.New("1.1.1")}, + }, + }, + }, { + desc: "Missing HAB section", + habTarget: "orange", // only match HAB signed firmware targetting "orange" devices + releases: [][]ftlog.FirmwareRelease{ + { + {Component: ftlog.ComponentOS, GitTagName: *semver.New("1.0.1")}, + {Component: ftlog.ComponentApplet, GitTagName: *semver.New("1.1.1")}, + {HAB: &ftlog.HAB{Target: "orange"}, Component: ftlog.ComponentBoot, GitTagName: *semver.New("1.1.1")}, + {HAB: nil, Component: ftlog.ComponentBoot, GitTagName: *semver.New("1.3.1")}, + }, + }, + want: [][]ftlog.FirmwareRelease{ + { + {HAB: &ftlog.HAB{Target: "orange"}, Component: ftlog.ComponentBoot, GitTagName: *semver.New("1.1.1")}, }, }, }, {