Skip to content

Commit

Permalink
Don't serialise empty sub structs in manifest (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCutter authored Feb 13, 2024
1 parent 20e7573 commit b71051a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
4 changes: 2 additions & 2 deletions release/firmware/ftlog/log_entries.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 9 additions & 2 deletions release/firmware/update/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -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{
Expand Down
32 changes: 24 additions & 8 deletions release/firmware/update/fetch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")},
},
},
}, {
Expand Down

0 comments on commit b71051a

Please sign in to comment.