-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstmgr.go
171 lines (140 loc) · 3.43 KB
/
stmgr.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
package main
import (
"log"
"os"
"system-transparency.org/stboot/stlog"
"system-transparency.org/stmgr/eval"
"system-transparency.org/stmgr/uki"
)
const (
_ = iota
commandCallPosition
subcommandCallPosition
flagsCallPosition
)
func main() {
log.SetFlags(0)
if err := run(os.Args); err != nil {
stlog.Error("%s", err)
os.Exit(1)
}
}
// We move the main program logic away into run()
// so that our code is easier to write tests for.
func run(args []string) error {
const usage = `Usage: stmgr <COMMAND> <SUBCOMMAND> [flags...]
COMMANDS:
trustpolicy:
Manage trust policy files for stboot.
hostconfig:
Manage host configuration files for stboot.
ospkg:
Set of commands related to OS packages. This includes
creating, signing and analyzing them.
keygen:
Commands to generate different keys and certificates for
system-transparency.
uki:
Create an Unified Kernel Image (UKI) for booting stboot and provisioning tools.
Output formats:
* ISO
Use 'stmgr <COMMAND> -help' for more info.
`
// Display helptext if not enough arguments are given
if len(args) < flagsCallPosition {
log.Print(usage)
return nil
}
// Check which command is requested or display usage
switch args[commandCallPosition] {
case "trustpolicy":
return trustpolicyArg(args)
case "hostconfig":
return hostconfigArg(args)
case "ospkg":
return ospkgArg(args)
case "uki":
return ukiArg(args)
case "keygen":
return keygenArg(args)
default:
// Display usage on unknown command
log.Print(usage)
return nil
}
}
func trustpolicyArg(args []string) error {
switch args[subcommandCallPosition] {
case "check":
return eval.TrustPolicyCheck(args[flagsCallPosition:])
default:
log.Print(`SUBCOMMANDS:
check:
Create valid trust policy by checking the provided JSON.
Use 'stmgr trustpolicy <SUBCOMMAND> -help' for more info.
`)
}
return nil
}
func hostconfigArg(args []string) error {
switch args[subcommandCallPosition] {
case "check":
return eval.HostConfigCheck(args[flagsCallPosition:])
default:
log.Print(`SUBCOMMANDS:
check:
Create valid host configuration by checking the provided JSON.
Use 'stmgr hostconfig <SUBCOMMAND> -help' for more info.
`)
}
return nil
}
// Check for ospkg subcommands.
func ospkgArg(args []string) error {
switch args[subcommandCallPosition] {
case "create":
return eval.OspkgCreate(args[flagsCallPosition:])
case "sign":
return eval.OspkgSign(args[flagsCallPosition:])
default:
// Display usage on unknown subcommand
log.Print(`SUBCOMMANDS:
create:
Create an OS package from the provided operating
system files.
sign:
Sign the provided OS package with your private key.
Use 'stmgr ospkg <SUBCOMMAND> -help' for more info.
`)
return nil
}
}
func ukiArg(args []string) error {
switch args[subcommandCallPosition] {
case "create":
return uki.Create(args[flagsCallPosition:])
default:
log.Print(`SUBCOMMANDS:
create:
create an unified kernel image with an optional host configuration.
Use 'stmgr uki <SUBCOMMAND> -help' for more info.
`)
}
return nil
}
// Check for keygen subcommands.
func keygenArg(args []string) error {
switch args[subcommandCallPosition] {
case "certificate":
return eval.KeygenCertificate(args[flagsCallPosition:])
default:
// Display usage on unknown subcommand
log.Print(`SUBCOMMANDS:
certificate:
Generate certificates for signing OS packages
using ED25519 keys.
Use 'stmgr keygen <SUBCOMMAND> -help' for more info.
`)
return nil
}
}