Skip to content

Commit c7a6518

Browse files
zaolinChriMarMe
authored andcommitted
Add bg 1.0 verification functions, move subdirs into own namespace
Signed-off-by: Philipp Deppenwiese <zaolin.daisuki@gmail.com>
1 parent 5d5ade8 commit c7a6518

46 files changed

Lines changed: 97 additions & 44 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

pkg/intel/metadata/bg/bootpolicy/bpmh.go renamed to pkg/intel/metadata/bg/bgbootpolicy/bpmh.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
//go:generate manifestcodegen
66

7-
package bootpolicy
7+
package bgbootpolicy
88

99
import "github.com/linuxboot/fiano/pkg/intel/metadata/bg"
1010

pkg/intel/metadata/bg/bootpolicy/bpmh_manifestcodegen.go renamed to pkg/intel/metadata/bg/bgbootpolicy/bpmh_manifestcodegen.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/intel/metadata/bg/bootpolicy/manifest.go renamed to pkg/intel/metadata/bg/bgbootpolicy/manifest.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44

55
//go:generate manifestcodegen
66

7-
package bootpolicy
7+
package bgbootpolicy
88

99
import (
10+
"bytes"
11+
"fmt"
12+
1013
pkgbytes "github.com/linuxboot/fiano/pkg/bytes"
1114

1215
"github.com/linuxboot/fiano/pkg/intel/metadata/bg"
@@ -35,7 +38,28 @@ func (bpm Manifest) StructInfo() StructInfo {
3538

3639
// ValidateIBB returns an error if IBB segments does not match the signature
3740
func (bpm *Manifest) ValidateIBB(firmware uefi.Firmware) error {
38-
// TODO
41+
if bpm.SE[0].Digest.TotalSize() == 0 {
42+
return fmt.Errorf("no IBB hashes")
43+
}
44+
45+
digest := bpm.SE[0].Digest
46+
47+
h, err := digest.HashAlg.Hash()
48+
if err != nil {
49+
return fmt.Errorf("invalid hash function: %v", digest.HashAlg)
50+
}
51+
52+
for _, _range := range bpm.IBBDataRanges(uint64(len(firmware.Buf()))) {
53+
if _, err := h.Write(firmware.Buf()[_range.Offset:_range.End()]); err != nil {
54+
return fmt.Errorf("unable to hash: %w", err)
55+
}
56+
}
57+
hashValue := h.Sum(nil)
58+
59+
if !bytes.Equal(hashValue, digest.HashBuffer) {
60+
return fmt.Errorf("IBB %s hash mismatch: %X != %X", digest.HashAlg, hashValue, digest.HashBuffer)
61+
}
62+
3963
return nil
4064
}
4165

pkg/intel/metadata/bg/bootpolicy/manifest_manifestcodegen.go renamed to pkg/intel/metadata/bg/bgbootpolicy/manifest_manifestcodegen.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/intel/metadata/bg/bootpolicy/manifest_nocodegen.go renamed to pkg/intel/metadata/bg/bgbootpolicy/manifest_nocodegen.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
// "bpm.BPMH.PrettyString undefined" we place these functions to a file
1111
// with a build tag "!manifestcodegen"
1212

13-
package bootpolicy
13+
package bgbootpolicy
1414

1515
import (
1616
"fmt"

pkg/intel/metadata/bg/bootpolicy/manifest_test.go renamed to pkg/intel/metadata/bg/bgbootpolicy/manifest_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
package bootpolicy
5+
package bgbootpolicy
66

77
import (
88
"testing"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
//go:generate manifestcodegen
66

7-
package bootpolicy
7+
package bgbootpolicy
88

99
type PM struct {
1010
StructInfo `id:"__PMDA__" version:"0x10"`

pkg/intel/metadata/bg/bootpolicy/pm_manifestcodegen.go renamed to pkg/intel/metadata/bg/bgbootpolicy/pm_manifestcodegen.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
//go:generate manifestcodegen
66

7-
package bootpolicy
7+
package bgbootpolicy
88

99
import (
1010
"fmt"

pkg/intel/metadata/bg/bootpolicy/se_manifestcodegen.go renamed to pkg/intel/metadata/bg/bgbootpolicy/se_manifestcodegen.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)