@@ -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
0 commit comments