-
Notifications
You must be signed in to change notification settings - Fork 71
/
status.go
122 lines (114 loc) · 2.82 KB
/
status.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package main
import (
"fmt"
"os"
"strings"
"github.com/foxboron/go-uefi/efi"
"github.com/foxboron/sbctl"
"github.com/foxboron/sbctl/certs"
"github.com/foxboron/sbctl/fs"
"github.com/foxboron/sbctl/logging"
"github.com/foxboron/sbctl/quirks"
"github.com/spf13/cobra"
)
var statusCmd = &cobra.Command{
Use: "status",
Short: "Show current boot status",
RunE: RunStatus,
}
type Status struct {
Installed bool `json:"installed"`
GUID string `json:"guid"`
SetupMode bool `json:"setup_mode"`
SecureBoot bool `json:"secure_boot"`
Vendors []string `json:"vendors"`
FirmwareQuirks []quirks.Quirk `json:"firmware_quirks"`
}
func NewStatus() *Status {
return &Status{
Installed: false,
GUID: "",
SetupMode: false,
SecureBoot: false,
Vendors: []string{},
FirmwareQuirks: []quirks.Quirk{},
}
}
func PrintStatus(s *Status) {
logging.Print("Installed:\t")
if s.Installed {
logging.Ok("sbctl is installed")
if s.GUID != "" {
logging.Print("Owner GUID:\t")
logging.Println(s.GUID)
}
} else {
logging.NotOk("sbctl is not installed")
}
logging.Print("Setup Mode:\t")
if s.SetupMode {
logging.NotOk("Enabled")
} else {
logging.Ok("Disabled")
}
logging.Print("Secure Boot:\t")
if s.SecureBoot {
logging.Ok("Enabled")
} else {
logging.NotOk("Disabled")
}
// TODO: We only have microsoft keys
// this needs to be extended for more keys in the future
logging.Print("Vendor Keys:\t")
if len(s.Vendors) > 0 {
logging.Println(strings.Join(s.Vendors, " "))
} else {
logging.Println("none")
}
if len(s.FirmwareQuirks) > 0 {
logging.Print("Firmware:\t")
logging.Print(logging.Warnf("Your firmware has known quirks"))
for _, quirk := range s.FirmwareQuirks {
logging.Println("\t\t- " + quirk.ID + ": " + quirk.Name + " (" + quirk.Severity + ")\n\t\t " + quirk.Link)
}
}
}
func RunStatus(cmd *cobra.Command, args []string) error {
stat := NewStatus()
if _, err := fs.Fs.Stat("/sys/firmware/efi/efivars"); os.IsNotExist(err) {
return fmt.Errorf("system is not booted with UEFI")
}
if sbctl.CheckSbctlInstallation(sbctl.DatabasePath) {
stat.Installed = true
u, err := sbctl.GetGUID()
if err == nil {
stat.GUID = u.String()
}
}
if efi.GetSetupMode() {
stat.SetupMode = true
}
if efi.GetSecureBoot() {
stat.SecureBoot = true
}
if keys := sbctl.GetEnrolledVendorCerts(); len(keys) > 0 {
stat.Vendors = keys
}
if keys, err := certs.BuiltinSignatureOwners(); err == nil {
stat.Vendors = append(stat.Vendors, keys...)
}
stat.FirmwareQuirks = quirks.CheckFirmwareQuirks()
if cmdOptions.JsonOutput {
if err := JsonOut(stat); err != nil {
return err
}
} else {
PrintStatus(stat)
}
return nil
}
func init() {
CliCommands = append(CliCommands, cliCommand{
Cmd: statusCmd,
})
}