-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.go
More file actions
58 lines (50 loc) · 1.47 KB
/
main.go
File metadata and controls
58 lines (50 loc) · 1.47 KB
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
package main
import (
"errors"
"os"
goversion "github.com/caarlos0/go-version"
"github.com/caarlos0/log"
"github.com/loicsikidi/tpm-trust/cmd/audit"
"github.com/loicsikidi/tpm-trust/cmd/certificates"
"github.com/loicsikidi/tpm-trust/cmd/info"
versionCmd "github.com/loicsikidi/tpm-trust/cmd/version"
"github.com/loicsikidi/tpm-trust/internal"
"github.com/spf13/cobra"
)
const website = "https://github.com/loicsikidi/tpm-trust"
var (
version = ""
builtBy = ""
)
func main() {
rootCmd := &cobra.Command{
Use: "tpm-trust",
Short: "verify TPM authenticity using hardware certificates",
Long: `tpm-trust verifies the authenticity of a TPM by validating its Endorsement Key (EK)
certificate against a trusted bundle of TPM manufacturer root certificates.`,
SilenceErrors: true,
}
rootCmd.AddCommand(audit.NewCommand())
rootCmd.AddCommand(certificates.NewCommand())
rootCmd.AddCommand(info.NewCommand())
rootCmd.AddCommand(versionCmd.NewCommand(buildVersion(version, builtBy)))
if err := rootCmd.Execute(); err != nil {
if !errors.Is(err, internal.ErrSilence) {
log.WithError(err).Error("command failed")
}
os.Exit(1)
}
}
func buildVersion(version, builtBy string) goversion.Info {
return goversion.GetVersionInfo(
goversion.WithAppDetails("tpm-trust", "a tool that will tell you if your TPM is genuine.", website),
func(i *goversion.Info) {
if version != "" {
i.GitVersion = version
}
if builtBy != "" {
i.BuiltBy = builtBy
}
},
)
}