-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
78 lines (67 loc) · 1.94 KB
/
main.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
package main
import (
"encoding/json"
"flag"
"fmt"
"os"
"tpm2-quote-attest/tool"
)
func main() {
var messageFilePath, pcrFilePath, pubKeyFilePath, signatureFilePath, nonceFilePath string
var prettyPrint bool
flag.StringVar(&messageFilePath, "message-file", "", "Path to message file")
flag.StringVar(&pcrFilePath, "pcr-file", "", "Path to pcr file (in pcrs_format=values)")
flag.StringVar(&pubKeyFilePath, "pubKey-file", "", "Path to public key file (in PEM format)")
flag.StringVar(&signatureFilePath, "signature-file", "", "Path to signature file")
flag.StringVar(&nonceFilePath, "nonce-file", "", "Path to nonce file")
flag.BoolVar(&prettyPrint, "pretty", true, "Pretty-print JSON output (optional)")
flag.Parse()
if flag.NFlag() < 5 {
flag.Usage()
os.Exit(1)
}
var err error
// ---------------------------- Read Files --------------------------------
messageFile, err := os.ReadFile(messageFilePath)
if err != nil {
fmt.Println("Error reading message file:", err)
os.Exit(1)
}
pcrFile, err := os.ReadFile(pcrFilePath)
if err != nil {
fmt.Println("Error reading pcr file:", err)
os.Exit(1)
}
pubKeyFile, err := os.ReadFile(pubKeyFilePath)
if err != nil {
fmt.Println("Error reading public key file:", err)
os.Exit(1)
}
signatureFile, err := os.ReadFile(signatureFilePath)
if err != nil {
fmt.Println("Error reading signature file:", err)
os.Exit(1)
}
nonceFile, err := os.ReadFile(nonceFilePath)
if err != nil {
fmt.Println("Error reading nonce file:", err)
os.Exit(1)
}
// ------------------------------------------------------------------------
q, err := tool.Attest(pubKeyFile, messageFile, pcrFile, signatureFile, nonceFile)
if err != nil {
fmt.Println("Attestation error:", err)
os.Exit(1)
}
var result []byte
if prettyPrint {
result, err = json.MarshalIndent(q, "", " ")
} else {
result, err = json.Marshal(q)
}
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Println(string(result))
}