Skip to content
This repository has been archived by the owner on Sep 6, 2023. It is now read-only.

Commit

Permalink
Generate bootkit artifacts for snakeoil as well
Browse files Browse the repository at this point in the history
Also, simply do nothing if not on amd64, since we don't have
arm64 artifacts.

Signed-off-by: Serge Hallyn <[email protected]>
  • Loading branch information
hallyn committed Aug 24, 2023
1 parent 5cc5a70 commit f9f56e5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 17 deletions.
32 changes: 18 additions & 14 deletions cmd/trust/keyset.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,6 @@ func initkeyset(keysetName string, Org []string) error {
return fmt.Errorf("Failed to add the pcr7data to keyset %q: (%w)", keysetName, err)
}

// Now create the bootkit artifacts
if err = trust.SetupBootkit(keysetName); err != nil {
return fmt.Errorf("Failed creating bootkit artifacts for keyset %q: (%w)", keysetName, err)
}

return nil
}

Expand Down Expand Up @@ -336,17 +331,26 @@ func doAddKeyset(ctx *cli.Context) error {
return fmt.Errorf("%s keyset already exists", keysetName)
}

// git clone if keyset is snakeoil
if keysetName == "snakeoil" {
switch keysetName {
case keysetName:
// git clone if keyset is snakeoil
_, err = git.PlainClone(keysetPath, false, &git.CloneOptions{URL: "https://github.com/project-machine/keys.git"})
if err != nil {
os.Remove(keysetPath)
return err
}
return nil

default:
// Otherwise, generate a new keyset
err = initkeyset(keysetName, Org)
}
// Otherwise, generate a new keyset
return initkeyset(keysetName, Org)
if err != nil {
os.Remove(keysetPath)
return errors.Wrapf(err, "Failed creating keyset %q", keysetName)
}

// Now create the bootkit artifacts
if err = trust.SetupBootkit(keysetName); err != nil {
return fmt.Errorf("Failed creating bootkit artifacts for keyset %q: (%w)", keysetName, err)
}

return nil
}

func doListKeysets(ctx *cli.Context) error {
Expand Down
18 changes: 15 additions & 3 deletions pkg/trust/artifacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import (
"fmt"
"os"
"path/filepath"
"runtime"
"strconv"
"strings"

"github.com/apex/log"
efi "github.com/canonical/go-efilib"
ispec "github.com/opencontainers/image-spec/specs-go/v1"
rspec "github.com/opencontainers/runtime-spec/specs-go"
Expand Down Expand Up @@ -162,6 +164,16 @@ func UpdateShim(inShim, newShim, keysetPath string) error {
}

func SetupBootkit(keysetName string) error {
// TODO - we have to fix this by
// a. having bootkit generate arm64
// b. changing the bootkit layer naming to reflect arch
// c. using the bootkit api here instead of doing it ourselves
// for now, we just do nothing on arm64
if runtime.GOARCH != "amd64" {
log.Warnf("Running on %q, so not building bootkit artifacts (only amd64 supported).", runtime.GOARCH)
return nil
}

tmpdir, err := os.MkdirTemp("", "trust-bootkit")
if err != nil {
return errors.Wrapf(err, "Failed creating temporary directory")
Expand Down Expand Up @@ -244,17 +256,17 @@ func SetupBootkit(keysetName string) error {
if err != nil {
return errors.Wrapf(err, "failed reading uefi-pk guid")
}
pkGuid := string(pkGuidBytes)
pkGuid := strings.TrimSpace(string(pkGuidBytes))
kekGuidBytes, err := os.ReadFile(filepath.Join(keysetPath, "uefi-kek", "guid"))
if err != nil {
return errors.Wrapf(err, "failed reading uefi-kek guid")
}
kekGuid := string(kekGuidBytes)
kekGuid := strings.TrimSpace(string(kekGuidBytes))
dbGuidBytes, err := os.ReadFile(filepath.Join(keysetPath, "uefi-db", "guid"))
if err != nil {
return errors.Wrapf(err, "failed reading uefi-db guid")
}
dbGuid := string(dbGuidBytes)
dbGuid := strings.TrimSpace(string(dbGuidBytes))

outFile := filepath.Join(destDir, "ovmf-vars.fd")
cmd = []string{
Expand Down

0 comments on commit f9f56e5

Please sign in to comment.