forked from google/go-tpm-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_test.go
47 lines (39 loc) · 1010 Bytes
/
example_test.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
package server
import (
"crypto"
"fmt"
"log"
"github.com/google/go-tpm-tools/client"
"github.com/google/go-tpm-tools/simulator"
)
func ExampleVerifyAttestation() {
// On client machine, generate the TPM quote.
// TODO: use real TPM.
simulator, err := simulator.Get()
if err != nil {
log.Fatalf("failed to initialize simulator: %v", err)
}
defer simulator.Close()
ak, err := client.AttestationKeyRSA(simulator)
if err != nil {
log.Fatalf("failed to generate AK: %v", err)
}
defer ak.Close()
nonce := []byte("super secret nonce")
attestation, err := ak.Attest(client.AttestOpts{Nonce: nonce})
if err != nil {
log.Fatalf("failed to attest: %v", err)
}
// TODO: send Attestation proto to verifier
// verify the attesation proto
opts := VerifyOpts{
Nonce: nonce,
TrustedAKs: []crypto.PublicKey{ak.PublicKey()},
AllowSHA1: true,
}
state, err := VerifyAttestation(attestation, opts)
if err != nil {
log.Fatalf("failed to verify: %v", err)
}
fmt.Println(state)
}