-
Notifications
You must be signed in to change notification settings - Fork 71
/
create-keys.go
56 lines (49 loc) · 1.42 KB
/
create-keys.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"fmt"
"github.com/foxboron/sbctl"
"github.com/foxboron/sbctl/logging"
"github.com/spf13/cobra"
)
var (
exportPath string = sbctl.KeysPath
databasePath string = sbctl.DatabasePath
)
var createKeysCmd = &cobra.Command{
Use: "create-keys",
Short: "Create a set of secure boot signing keys",
RunE: func(cmd *cobra.Command, args []string) error {
if err := sbctl.CreateDirectory(exportPath); err != nil {
return err
}
uuid, err := sbctl.CreateGUID(databasePath)
if err != nil {
return err
}
logging.Print("Created Owner UUID %s\n", uuid)
if !sbctl.CheckIfKeysInitialized(exportPath) {
logging.Print("Creating secure boot keys...")
err := sbctl.InitializeSecureBootKeys(exportPath)
if err != nil {
logging.NotOk("")
return fmt.Errorf("couldn't initialize secure boot: %w", err)
}
logging.Ok("")
logging.Println("Secure boot keys created!")
} else {
logging.Ok("Secure boot keys have already been created!")
}
return nil
},
}
func createKeysCmdFlags(cmd *cobra.Command) {
f := cmd.Flags()
f.StringVarP(&exportPath, "export", "e", sbctl.KeysPath, "export file path. defaults to "+sbctl.KeysPath)
f.StringVarP(&databasePath, "database-path", "d", sbctl.DatabasePath, "location to create GUID file. defaults to "+sbctl.DatabasePath)
}
func init() {
createKeysCmdFlags(createKeysCmd)
CliCommands = append(CliCommands, cliCommand{
Cmd: createKeysCmd,
})
}