Skip to content

Commit 720eae9

Browse files
alexmwuSibcgh
authored andcommitted
Revert "Add HashNonce flag to Attest and VerifyAttestation (google#585)" (google#601)
This reverts commit 215e2ab.
1 parent 6bd162e commit 720eae9

File tree

4 files changed

+21
-109
lines changed

4 files changed

+21
-109
lines changed

client/attest.go

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,6 @@ type AttestOpts struct {
5959
// depending on the technology's size. Leaving this nil is not recommended. If
6060
// nil, then TEEDevice must be nil.
6161
TEENonce []byte
62-
// HashNonce will apply the attestation key's signing scheme hash algorithm
63-
// to the input Nonce field and use the resulting digest in place of the
64-
// original Nonce.
65-
// Nonce must still be unique and application-specific.
66-
HashNonce bool
6762
}
6863

6964
// SevSnpQuoteProvider encapsulates the SEV-SNP attestation device to add its attestation report
@@ -291,16 +286,8 @@ func (k *Key) Attest(opts AttestOpts) (*pb.Attestation, error) {
291286
return nil, fmt.Errorf("failed to encode public area: %w", err)
292287
}
293288
attestation.AkCert = k.CertDERBytes()
294-
extraData := opts.Nonce
295-
if opts.HashNonce {
296-
var err error
297-
extraData, err = internal.HashNonce(k.PublicArea(), extraData)
298-
if err != nil {
299-
return nil, fmt.Errorf("failed to hash the input nonce: %w", err)
300-
}
301-
}
302289
for _, sel := range sels {
303-
quote, err := k.Quote(sel, extraData)
290+
quote, err := k.Quote(sel, opts.Nonce)
304291
if err != nil {
305292
return nil, err
306293
}

internal/quote.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -133,20 +133,3 @@ func validatePCRDigest(quoteInfo *tpm2.QuoteInfo, pcrs *pb.PCRs, hash crypto.Has
133133
}
134134
return nil
135135
}
136-
137-
// HashNonce takes an arbitrary-sized nonce and ensures it can fit in the TPM's
138-
// extraData field by applying the given key's signing hash algorithm to the
139-
// nonce.
140-
func HashNonce(pubArea tpm2.Public, nonce []byte) ([]byte, error) {
141-
sigHash, err := GetSigningHashAlg(pubArea)
142-
if err != nil {
143-
return nil, err
144-
}
145-
chash, err := sigHash.Hash()
146-
if err != nil {
147-
return nil, err
148-
}
149-
hasher := chash.New()
150-
hasher.Write(nonce)
151-
return hasher.Sum(nil), nil
152-
}

server/verify.go

Lines changed: 19 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,6 @@ type VerifyOpts struct {
6666
// "Calling EFI Application from Boot Option". This option is useful when
6767
// the host platform loads EFI Applications unrelated to OS boot.
6868
AllowEFIAppBeforeCallingEvent bool
69-
// HashNonce will apply the attestation key's signing scheme hash algorithm
70-
// to the input Nonce field and use the resulting digest in place of the
71-
// original Nonce.
72-
HashNonce bool
7369
}
7470

7571
// Bootloader refers to the second-stage bootloader that loads and transfers
@@ -118,24 +114,16 @@ func VerifyAttestation(attestation *pb.Attestation, opts VerifyOpts) (*pb.Machin
118114
return nil, fmt.Errorf("bad options: %w", err)
119115
}
120116

121-
machineState, akPub, akPubKey, err := validateAK(attestation, opts)
117+
machineState, akPubKey, err := validateAK(attestation, opts)
122118
if err != nil {
123119
return nil, fmt.Errorf("failed to parse and validate AK: %w", err)
124120
}
125-
extraData := opts.Nonce
126-
if opts.HashNonce {
127-
var err error
128-
extraData, err = internal.HashNonce(akPub, extraData)
129-
if err != nil {
130-
return nil, fmt.Errorf("failed to hash the input nonce: %w", err)
131-
}
132-
}
133121

134122
// Attempt to replay the log against our PCRs in order of hash preference
135123
var lastErr error
136124
for _, quote := range supportedQuotes(attestation.GetQuotes()) {
137125
// Verify the Quote
138-
if err := internal.VerifyQuote(quote, akPubKey, extraData); err != nil {
126+
if err := internal.VerifyQuote(quote, akPubKey, opts.Nonce); err != nil {
139127
lastErr = fmt.Errorf("failed to verify quote: %w", err)
140128
continue
141129
}
@@ -170,48 +158,44 @@ func VerifyAttestation(attestation *pb.Attestation, opts VerifyOpts) (*pb.Machin
170158

171159
// validateAK validates AK cert in the attestation, and returns AK cert (if exists) and public key.
172160
// It also pulls out the GCE Instance Info if it exists.
173-
func validateAK(attestation *pb.Attestation, opts VerifyOpts) (*pb.MachineState, tpm2.Public, crypto.PublicKey, error) {
174-
// If the AK Cert is not in the attestation, use the AK Public Area.
175-
akPubArea, err := tpm2.DecodePublic(attestation.GetAkPub())
176-
if err != nil {
177-
return nil, tpm2.Public{}, nil, fmt.Errorf("failed to decode AK public area: %w", err)
178-
}
179-
akPubKey, err := akPubArea.Key()
180-
if err != nil {
181-
return nil, tpm2.Public{}, nil, fmt.Errorf("failed to get AK public key: %w", err)
182-
}
161+
func validateAK(attestation *pb.Attestation, opts VerifyOpts) (*pb.MachineState, crypto.PublicKey, error) {
183162
if len(attestation.GetAkCert()) == 0 || len(opts.TrustedRootCerts) == 0 {
163+
// If the AK Cert is not in the attestation, use the AK Public Area.
164+
akPubArea, err := tpm2.DecodePublic(attestation.GetAkPub())
165+
if err != nil {
166+
return nil, nil, fmt.Errorf("failed to decode AK public area: %w", err)
167+
}
168+
akPubKey, err := akPubArea.Key()
169+
if err != nil {
170+
return nil, nil, fmt.Errorf("failed to get AK public key: %w", err)
171+
}
184172
if err := validateAKPub(akPubKey, opts); err != nil {
185-
return nil, tpm2.Public{}, nil, fmt.Errorf("failed to validate AK public key: %w", err)
173+
return nil, nil, fmt.Errorf("failed to validate AK public key: %w", err)
186174
}
187-
return &pb.MachineState{}, akPubArea, akPubKey, nil
175+
return &pb.MachineState{}, akPubKey, nil
188176
}
189177

190178
// If AK Cert is presented, ignore the AK Public Area.
191179
akCert, err := x509.ParseCertificate(attestation.GetAkCert())
192-
certPubKey := akCert.PublicKey.(crypto.PublicKey) // This cast cannot fail
193-
if !internal.PubKeysEqual(certPubKey, akPubKey) {
194-
return nil, tpm2.Public{}, nil, errors.New("AK certificate does not match key")
195-
}
196180
if err != nil {
197-
return nil, tpm2.Public{}, nil, fmt.Errorf("failed to parse AK certificate: %w", err)
181+
return nil, nil, fmt.Errorf("failed to parse AK certificate: %w", err)
198182
}
199183
// Use intermediate certs from the attestation if they exist.
200184
certs, err := parseCerts(attestation.IntermediateCerts)
201185
if err != nil {
202-
return nil, tpm2.Public{}, nil, fmt.Errorf("attestation intermediates: %w", err)
186+
return nil, nil, fmt.Errorf("attestation intermediates: %w", err)
203187
}
204188
opts.IntermediateCerts = append(opts.IntermediateCerts, certs...)
205189

206190
if err := VerifyAKCert(akCert, opts.TrustedRootCerts, opts.IntermediateCerts); err != nil {
207-
return nil, tpm2.Public{}, nil, fmt.Errorf("failed to validate AK certificate: %w", err)
191+
return nil, nil, fmt.Errorf("failed to validate AK certificate: %w", err)
208192
}
209193
instanceInfo, err := getInstanceInfoFromExtensions(akCert.Extensions)
210194
if err != nil {
211-
return nil, tpm2.Public{}, nil, fmt.Errorf("error getting instance info: %v", err)
195+
return nil, nil, fmt.Errorf("error getting instance info: %v", err)
212196
}
213197

214-
return &pb.MachineState{Platform: &pb.PlatformState{InstanceInfo: instanceInfo}}, akPubArea, akCert.PublicKey, nil
198+
return &pb.MachineState{Platform: &pb.PlatformState{InstanceInfo: instanceInfo}}, akCert.PublicKey, nil
215199
}
216200

217201
// GetGCEInstanceInfo takes a GCE-issued x509 EK/AK certificate and tries to

server/verify_test.go

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"fmt"
1414
"io"
1515
"os"
16-
"strconv"
1716
"testing"
1817

1918
"github.com/google/go-tpm-tools/client"
@@ -221,47 +220,6 @@ func TestVerifyWithTrustedAK(t *testing.T) {
221220
}
222221
}
223222

224-
func TestVerifyHashNonce(t *testing.T) {
225-
rwc := test.GetTPM(t)
226-
defer client.CheckedClose(t, rwc)
227-
228-
ak, err := client.AttestationKeyRSA(rwc)
229-
if err != nil {
230-
t.Fatalf("failed to generate AK: %v", err)
231-
}
232-
defer ak.Close()
233-
tests := []struct {
234-
attHash bool
235-
verHash bool
236-
wantErr bool
237-
}{
238-
{true, true, false},
239-
{false, false, false},
240-
{true, false, true},
241-
{false, true, true},
242-
}
243-
nonce := []byte("super secret nonce")
244-
245-
for _, test := range tests {
246-
t.Run("attest hash "+strconv.FormatBool(test.attHash)+" verify hash "+strconv.FormatBool(test.verHash), func(t *testing.T) {
247-
attestation, err := ak.Attest(client.AttestOpts{Nonce: nonce, HashNonce: test.attHash})
248-
if err != nil {
249-
t.Fatalf("failed to attest: %v", err)
250-
}
251-
252-
opts := VerifyOpts{
253-
Nonce: nonce,
254-
TrustedAKs: []crypto.PublicKey{ak.PublicKey()},
255-
HashNonce: test.verHash,
256-
}
257-
_, err = VerifyAttestation(attestation, opts)
258-
if test.wantErr != (err != nil) {
259-
t.Errorf("Attest(HashNonce %v), Verify(HashNonce %v): got %v wantErr %v", test.attHash, test.verHash, err, test.wantErr)
260-
}
261-
})
262-
}
263-
}
264-
265223
func TestVerifySHA1Attestation(t *testing.T) {
266224
rwc := test.GetTPM(t)
267225
defer client.CheckedClose(t, rwc)
@@ -481,7 +439,7 @@ func TestValidateAK(t *testing.T) {
481439

482440
for _, tc := range testCases {
483441
t.Run(tc.name, func(t *testing.T) {
484-
_, _, _, err := validateAK(tc.att(), tc.opts)
442+
_, _, err := validateAK(tc.att(), tc.opts)
485443
if gotPass := (err == nil); gotPass != tc.wantPass {
486444
t.Errorf("ValidateAK failed, got pass %v, but want %v", gotPass, tc.wantPass)
487445
}

0 commit comments

Comments
 (0)