| 1 |
package server |
| 2 |
|
| 3 |
import ( |
| 4 |
"crypto" |
| 5 |
"fmt" |
| 6 |
"log" |
| 7 |
|
| 8 |
"github.com/google/go-tpm-tools/client" |
| 9 |
"github.com/google/go-tpm-tools/simulator" |
| 10 |
) |
| 11 |
|
| 12 |
func ExampleVerifyAttestation() { |
| 13 |
// On client machine, generate the TPM quote. |
| 14 |
// TODO: use real TPM. |
| 15 |
simulator, err := simulator.Get() |
| 16 |
if err != nil { |
| 17 |
log.Fatalf("failed to initialize simulator: %v", err) |
| 18 |
} |
| 19 |
defer simulator.Close() |
| 20 |
|
| 21 |
ak, err := client.AttestationKeyRSA(simulator) |
| 22 |
if err != nil { |
| 23 |
log.Fatalf("failed to generate AK: %v", err) |
| 24 |
} |
| 25 |
defer ak.Close() |
| 26 |
|
| 27 |
nonce := []byte("super secret nonce") |
| 28 |
attestation, err := ak.Attest(client.AttestOpts{Nonce: nonce}) |
| 29 |
if err != nil { |
| 30 |
log.Fatalf("failed to attest: %v", err) |
| 31 |
} |
| 32 |
|
| 33 |
// TODO: send Attestation proto to verifier |
| 34 |
|
| 35 |
// verify the attesation proto |
| 36 |
opts := VerifyOpts{ |
| 37 |
Nonce: nonce, |
| 38 |
TrustedAKs: []crypto.PublicKey{ak.PublicKey()}, |
| 39 |
AllowSHA1: true, |
| 40 |
} |
| 41 |
state, err := VerifyAttestation(attestation, opts) |
| 42 |
if err != nil { |
| 43 |
log.Fatalf("failed to verify: %v", err) |
| 44 |
} |
| 45 |
|
| 46 |
fmt.Println(state) |
| 47 |
} |