Explorar o código

Export database-independent device attestation verification

Device attestation verification is currently available only through the ACME
challenge handler. Let library callers reuse the same format, trust-root,
signature, nonce, and identifier checks without constructing an ACME database.
Keep persistence and challenge status updates in the handler.

Expose binding metadata for the existing Apple missing-nonce and TPM
missing-identifier compatibility cases. Callers remain responsible for token
lifecycle, identifier authorization, and matching the verified fingerprint
to the key being enrolled. Preserve existing ACME acceptance behavior.

External-package tests cover successful step and Apple statements and reject
wrong bindings, account keys, signatures, roots, and disabled formats. The
wrong-identifier test fails when its validation check is removed.

go build ./acme, go vet ./acme, and gofmt pass. Tests for acme, acme/api,
and acme/wire pass. Four acme/db/nosql Badger cleanup tests fail on Windows;
the same failures reproduce on unchanged upstream master at 74662198.

Co-Authored-By: Codex <noreply@openai.com>
Ted Malone hai 2 meses
pai
achega
efba34bd71
Modificáronse 4 ficheiros con 434 adicións e 152 borrados
  1. 212 0
      acme/attestation.go
  2. 149 0
      acme/attestation_test.go
  3. 53 0
      acme/attestation_tpmsimulator_test.go
  4. 20 152
      acme/challenge.go

+ 212 - 0
acme/attestation.go

@@ -0,0 +1,212 @@
+package acme
+
+import (
+	"bytes"
+	"context"
+	"crypto/sha256"
+	"crypto/subtle"
+	"errors"
+	"slices"
+
+	"github.com/fxamacker/cbor/v2"
+	"github.com/smallstep/certificates/authority/provisioner"
+	"go.step.sm/crypto/jose"
+)
+
+// DeviceAttestationParams supplies the expected device-attest-01 bindings.
+// The caller must authorize Identifier and issue, expire, and consume Token.
+// AccountKey is the ACME account key used to form the key authorization; Apple
+// statements bind directly to Token and do not use AccountKey.
+type DeviceAttestationParams struct {
+	Token      string
+	Identifier string
+	AccountKey *jose.JSONWebKey
+}
+
+// DeviceAttestationResult describes the verified statement. Fingerprint uses
+// keyutil.Fingerprint's default encoding and must be compared with the key the
+// caller intends to enroll or certify. It is not an authorization decision.
+type DeviceAttestationResult struct {
+	Format      string
+	Fingerprint string
+	// ChallengeBound is false for legacy Apple statements without a nonce.
+	ChallengeBound bool
+	// IdentifierBound reports a nonempty expected identifier attested by the statement.
+	// It is false for TPM statements without permanent identifiers.
+	// ACME binds these later through the CSR subject; standalone callers must
+	// apply an equivalent check or reject the result.
+	IdentifierBound bool
+}
+
+// VerifyDeviceAttestation verifies a CBOR device-attest-01 attestation object
+// without reading or updating an ACME database. It enforces the provisioner's
+// format and trust-root policy, signatures, and the challenge and identifier
+// checks used by ACME. Android additionally requires a *provisioner.ACME for
+// its Android-specific policies. attObj is raw CBOR, not the base64url-encoded
+// JSON challenge response.
+//
+// Existing ACME compatibility is preserved: Apple statements may omit their
+// nonce and TPM statements may omit permanent identifiers. Callers must inspect
+// ChallengeBound and IdentifierBound and reject absent bindings unless they
+// provide equivalent assurance elsewhere. A successful result alone does not
+// prove freshness: the caller must enforce Token's lifecycle and compare the
+// returned Fingerprint with the public key being enrolled or certified.
+func VerifyDeviceAttestation(ctx context.Context, prov Provisioner, params DeviceAttestationParams, attObj []byte) (*DeviceAttestationResult, error) {
+	ch := &Challenge{Token: params.Token, Value: params.Identifier}
+	jwk := params.AccountKey
+	if len(attObj) == 0 || bytes.Equal(attObj, []byte("{}")) {
+		return nil, NewDetailedError(ErrorBadAttestationStatementType, "attObj must not be empty")
+	}
+
+	cborDecoderOptions := cbor.DecOptions{}
+	cborDecoder, err := cborDecoderOptions.DecMode()
+	if err != nil {
+		return nil, WrapErrorISE(err, "failed creating CBOR decoder")
+	}
+
+	if err := cborDecoder.Wellformed(attObj); err != nil {
+		return nil, NewDetailedError(ErrorBadAttestationStatementType, "attObj is not well formed CBOR: %v", err)
+	}
+
+	att := attestationObject{}
+	if err := cborDecoder.Unmarshal(attObj, &att); err != nil {
+		return nil, WrapErrorISE(err, "failed unmarshalling CBOR")
+	}
+
+	format := att.Format
+	if prov == nil {
+		return nil, NewErrorISE("attestation provisioner is required")
+	}
+	result := &DeviceAttestationResult{Format: format}
+	if !prov.IsAttestationFormatEnabled(ctx, provisioner.ACMEAttestationFormat(format)) {
+		if format != "apple" && format != "step" && format != "tpm" && format != "android-key" {
+			return nil, NewDetailedError(ErrorBadAttestationStatementType, "unsupported attestation object format %q", format)
+		}
+
+		return nil, NewError(ErrorBadAttestationStatementType, "attestation format %q is not enabled", format)
+	}
+
+	switch format {
+	case "android-key":
+		data, err := doAndroidKeyAttestationFormat(ctx, prov, ch, jwk, &att)
+		if err != nil {
+			if acmeError, ok := errors.AsType[*Error](err); ok {
+				return nil, acmeError
+			}
+			return nil, WrapErrorISE(err, "error validating attestation")
+		}
+
+		// Enforce hardware security level (TrustedEnvironment or StrongBox; Software not allowed)
+		if data.Attestation.AttestationSecurityLevel < 1 {
+			return nil, NewDetailedError(ErrorBadAttestationStatementType, "insufficient security level: %d", data.Attestation.AttestationSecurityLevel)
+		}
+
+		// Enforce hardware backed device serial
+		if ch.Value != string(data.Attestation.TeeEnforced.AttestationIdSerial) {
+			subproblem := NewSubproblemWithIdentifier(
+				ErrorRejectedIdentifierType,
+				Identifier{Type: "permanent-identifier", Value: ch.Value},
+				"challenge identifier %q doesn't match any of the attested hardware identifiers %q",
+				ch.Value, []string{string(data.Attestation.TeeEnforced.AttestationIdSerial)},
+			)
+			return nil, NewDetailedError(ErrorBadAttestationStatementType, "permanent identifier does not match").AddSubproblems(subproblem)
+		}
+
+		// Update attestation key fingerprint to compare against the CSR
+		result.Fingerprint = data.Fingerprint
+		result.IdentifierBound = ch.Value != ""
+		result.ChallengeBound = true
+	case "apple":
+		data, err := doAppleAttestationFormat(ctx, prov, ch, &att)
+		if err != nil {
+			if acmeError, ok := errors.AsType[*Error](err); ok {
+				return nil, acmeError
+			}
+			return nil, WrapErrorISE(err, "error validating attestation")
+		}
+
+		// Validate nonce with SHA-256 of the token.
+		if len(data.Nonce) != 0 {
+			sum := sha256.Sum256([]byte(ch.Token))
+			if subtle.ConstantTimeCompare(data.Nonce, sum[:]) != 1 {
+				return nil, NewDetailedError(ErrorBadAttestationStatementType, "challenge token does not match")
+			}
+		}
+
+		// Validate Apple's ClientIdentifier (Identifier.Value) with device
+		// identifiers.
+		//
+		// Note: We might want to use an external service for this.
+		if data.UDID != ch.Value && data.SerialNumber != ch.Value {
+			subproblem := NewSubproblemWithIdentifier(
+				ErrorRejectedIdentifierType,
+				Identifier{Type: "permanent-identifier", Value: ch.Value},
+				"challenge identifier %q doesn't match any of the attested hardware identifiers %q", ch.Value, []string{data.UDID, data.SerialNumber},
+			)
+			return nil, NewDetailedError(ErrorBadAttestationStatementType, "permanent identifier does not match").AddSubproblems(subproblem)
+		}
+
+		// Update attestation key fingerprint to compare against the CSR
+		result.Fingerprint = data.Fingerprint
+		result.IdentifierBound = ch.Value != ""
+		result.ChallengeBound = len(data.Nonce) != 0
+	case "step":
+		data, err := doStepAttestationFormat(ctx, prov, ch, jwk, &att)
+		if err != nil {
+			if acmeError, ok := errors.AsType[*Error](err); ok {
+				return nil, acmeError
+			}
+			return nil, WrapErrorISE(err, "error validating attestation")
+		}
+
+		// Validate the YubiKey serial number from the attestation
+		// certificate with the challenged Order value.
+		//
+		// Note: We might want to use an external service for this.
+		if data.SerialNumber != ch.Value {
+			subproblem := NewSubproblemWithIdentifier(
+				ErrorRejectedIdentifierType,
+				Identifier{Type: "permanent-identifier", Value: ch.Value},
+				"challenge identifier %q doesn't match the attested hardware identifier %q", ch.Value, data.SerialNumber,
+			)
+			return nil, NewDetailedError(ErrorBadAttestationStatementType, "permanent identifier does not match").AddSubproblems(subproblem)
+		}
+
+		// Update attestation key fingerprint to compare against the CSR
+		result.Fingerprint = data.Fingerprint
+		result.IdentifierBound = ch.Value != ""
+		result.ChallengeBound = true
+
+	case "tpm":
+		data, err := doTPMAttestationFormat(ctx, prov, ch, jwk, &att)
+		if err != nil {
+			if acmeError, ok := errors.AsType[*Error](err); ok {
+				return nil, acmeError
+			}
+			return nil, WrapErrorISE(err, "error validating attestation")
+		}
+
+		// TODO(hs): currently this will allow a request for which no PermanentIdentifiers have been
+		// extracted from the AK certificate. This is currently the case for AK certs from the CLI, as we
+		// haven't implemented a way for AK certs requested by the CLI to always contain the requested
+		// PermanentIdentifier. Omitting the check below doesn't allow just any request, as the Order can
+		// still fail if the challenge value isn't equal to the CSR subject.
+		if len(data.PermanentIdentifiers) > 0 && !slices.Contains(data.PermanentIdentifiers, ch.Value) { // TODO(hs): add support for HardwareModuleName
+			subproblem := NewSubproblemWithIdentifier(
+				ErrorRejectedIdentifierType,
+				Identifier{Type: "permanent-identifier", Value: ch.Value},
+				"challenge identifier %q doesn't match any of the attested hardware identifiers %q", ch.Value, data.PermanentIdentifiers,
+			)
+			return nil, NewDetailedError(ErrorBadAttestationStatementType, "permanent identifier does not match").AddSubproblems(subproblem)
+		}
+
+		// Update attestation key fingerprint to compare against the CSR
+		result.Fingerprint = data.Fingerprint
+		result.IdentifierBound = ch.Value != "" && len(data.PermanentIdentifiers) != 0
+		result.ChallengeBound = true
+	default:
+		return nil, NewDetailedError(ErrorBadAttestationStatementType, "unsupported attestation object format %q", format)
+	}
+
+	return result, nil
+}

+ 149 - 0
acme/attestation_test.go

@@ -0,0 +1,149 @@
+package acme_test
+
+import (
+	"context"
+	"crypto"
+	"crypto/ecdsa"
+	"crypto/elliptic"
+	"crypto/rand"
+	"crypto/sha256"
+	"crypto/x509"
+	"crypto/x509/pkix"
+	"encoding/asn1"
+	"testing"
+
+	"github.com/fxamacker/cbor/v2"
+	"github.com/smallstep/certificates/acme"
+	"github.com/smallstep/certificates/authority/provisioner"
+	"github.com/stretchr/testify/require"
+	"go.step.sm/crypto/jose"
+	"go.step.sm/crypto/keyutil"
+	"go.step.sm/crypto/minica"
+)
+
+// These are deliberately external-package tests: no ACME database, Challenge,
+// context provisioner, or private format helper is available to the caller.
+func TestVerifyDeviceAttestation(t *testing.T) {
+	ca, err := minica.New()
+	require.NoError(t, err)
+	key, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
+	require.NoError(t, err)
+	account, err := jose.GenerateJWK("EC", "P-256", "ES256", "sig", "", 0)
+	require.NoError(t, err)
+	params := acme.DeviceAttestationParams{Token: "one-time-token", Identifier: "1234", AccountKey: account}
+	roots := x509.NewCertPool()
+	roots.AddCert(ca.Root)
+	prov := &acme.MockProvisioner{MgetAttestationRoots: func() (*x509.CertPool, bool) { return roots, true }}
+	serial, err := asn1.Marshal(1234)
+	require.NoError(t, err)
+	leaf, err := ca.Sign(&x509.Certificate{
+		Subject: pkix.Name{CommonName: "test attestation"}, PublicKey: key.Public(),
+		ExtraExtensions: []pkix.Extension{{Id: asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 41482, 3, 7}, Value: serial}},
+	})
+	require.NoError(t, err)
+	keyAuth, err := acme.KeyAuthorization(params.Token, account)
+	require.NoError(t, err)
+	digest := sha256.Sum256([]byte(keyAuth))
+	signature, err := key.Sign(rand.Reader, digest[:], crypto.SHA256)
+	require.NoError(t, err)
+	cborSignature, err := cbor.Marshal(signature)
+	require.NoError(t, err)
+	statement := map[string]any{"x5c": []any{leaf.Raw, ca.Intermediate.Raw}, "sig": cborSignature}
+	marshal := func(format string, stmt map[string]any) []byte {
+		b, err := cbor.Marshal(map[string]any{"fmt": format, "attStmt": stmt})
+		require.NoError(t, err)
+		return b
+	}
+	object := marshal("step", statement)
+	wantFP, err := keyutil.Fingerprint(key.Public())
+	require.NoError(t, err)
+	t.Run("valid statement binds key challenge and identifier", func(t *testing.T) {
+		result, err := acme.VerifyDeviceAttestation(context.Background(), prov, params, object)
+		require.NoError(t, err)
+		require.Equal(t, &acme.DeviceAttestationResult{
+			Format: "step", Fingerprint: wantFP, ChallengeBound: true, IdentifierBound: true,
+		}, result)
+	})
+	for _, tc := range []struct {
+		name   string
+		change func(*acme.DeviceAttestationParams)
+	}{
+		{"wrong challenge", func(p *acme.DeviceAttestationParams) { p.Token = "another-token" }},
+		{"wrong identifier", func(p *acme.DeviceAttestationParams) { p.Identifier = "5678" }},
+		{"missing account key", func(p *acme.DeviceAttestationParams) { p.AccountKey = nil }},
+		{"wrong account key", func(p *acme.DeviceAttestationParams) {
+			other, err := jose.GenerateJWK("EC", "P-256", "ES256", "sig", "", 0)
+			require.NoError(t, err)
+			p.AccountKey = other
+		}},
+	} {
+		t.Run(tc.name, func(t *testing.T) {
+			p := params
+			tc.change(&p)
+			result, err := acme.VerifyDeviceAttestation(context.Background(), prov, p, object)
+			require.Error(t, err)
+			require.Nil(t, result)
+		})
+	}
+	t.Run("untrusted chain", func(t *testing.T) {
+		untrusted := &acme.MockProvisioner{MgetAttestationRoots: func() (*x509.CertPool, bool) { return x509.NewCertPool(), true }}
+		result, err := acme.VerifyDeviceAttestation(context.Background(), untrusted, params, object)
+		require.ErrorContains(t, err, "x5c is not valid")
+		require.Nil(t, result)
+	})
+	t.Run("disabled format", func(t *testing.T) {
+		disabled := &acme.MockProvisioner{MisAttFormatEnabled: func(context.Context, provisioner.ACMEAttestationFormat) bool { return false }}
+		result, err := acme.VerifyDeviceAttestation(context.Background(), disabled, params, object)
+		require.ErrorContains(t, err, "not enabled")
+		require.Nil(t, result)
+	})
+	t.Run("missing provisioner", func(t *testing.T) {
+		result, err := acme.VerifyDeviceAttestation(context.Background(), nil, params, object)
+		require.ErrorContains(t, err, "attestation provisioner is required")
+		require.Nil(t, result)
+	})
+	for name, data := range map[string][]byte{
+		"empty": nil, "malformed": object[:len(object)-1], "unknown format": marshal("unknown", statement),
+		"tampered signature": marshal("step", map[string]any{"x5c": statement["x5c"], "sig": []byte{0x41, 0}}),
+	} {
+		t.Run(name, func(t *testing.T) {
+			result, err := acme.VerifyDeviceAttestation(context.Background(), prov, params, data)
+			require.Error(t, err)
+			require.Nil(t, result)
+		})
+	}
+	for _, noncePresent := range []bool{true, false} {
+		name := "Apple with nonce"
+		if !noncePresent {
+			name = "legacy Apple without nonce reports missing binding"
+		}
+		t.Run(name, func(t *testing.T) {
+			extensions := []pkix.Extension{{Id: asn1.ObjectIdentifier{1, 2, 840, 113635, 100, 8, 9, 1}, Value: []byte(params.Identifier)}}
+			if noncePresent {
+				nonce := sha256.Sum256([]byte(params.Token))
+				extensions = append(extensions, pkix.Extension{Id: asn1.ObjectIdentifier{1, 2, 840, 113635, 100, 8, 11, 1}, Value: nonce[:]})
+			}
+			cert, err := ca.Sign(&x509.Certificate{Subject: pkix.Name{CommonName: "Apple test"}, PublicKey: key.Public(), ExtraExtensions: extensions})
+			require.NoError(t, err)
+			apple := marshal("apple", map[string]any{"x5c": []any{cert.Raw, ca.Intermediate.Raw}})
+			result, err := acme.VerifyDeviceAttestation(context.Background(), prov, params, apple)
+			require.NoError(t, err)
+			require.Equal(t, noncePresent, result.ChallengeBound)
+			require.True(t, result.IdentifierBound)
+			require.Equal(t, wantFP, result.Fingerprint)
+			// Apple permits matching an absent UDID against an empty expected
+			// identifier. Report that compatibility case without claiming a binding.
+			empty := params
+			empty.Identifier = ""
+			unbound, err := acme.VerifyDeviceAttestation(context.Background(), prov, empty, apple)
+			require.NoError(t, err)
+			require.False(t, unbound.IdentifierBound)
+			if noncePresent {
+				wrong := params
+				wrong.Token = "wrong"
+				_, err = acme.VerifyDeviceAttestation(context.Background(), prov, wrong, apple)
+				require.ErrorContains(t, err, "challenge token does not match")
+			}
+		})
+	}
+}

+ 53 - 0
acme/attestation_tpmsimulator_test.go

@@ -0,0 +1,53 @@
+//go:build tpmsimulator
+
+package acme
+
+import (
+	"context"
+	"encoding/base64"
+	"encoding/json"
+	"encoding/pem"
+	"testing"
+
+	"github.com/stretchr/testify/require"
+	"go.step.sm/crypto/keyutil"
+)
+
+func TestVerifyDeviceAttestationWithTPMSimulator(t *testing.T) {
+	for _, tc := range []struct {
+		name        string
+		identifiers []string
+	}{
+		{"attested identifier", []string{"device.id.12345678"}},
+		{"legacy without identifier", nil},
+	} {
+		t.Run(tc.name, func(t *testing.T) {
+			account, keyAuth := mustAccountAndKeyAuthorization(t, "token")
+			payload, signer, root := mustAttestTPM(t, keyAuth, tc.identifiers)
+			prov := mustAttestationProvisioner(t, pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: root.Raw}))
+			var response payloadType
+			require.NoError(t, json.Unmarshal(payload, &response))
+			object, err := base64.RawURLEncoding.DecodeString(response.AttObj)
+			require.NoError(t, err)
+			params := DeviceAttestationParams{Token: "token", Identifier: "device.id.12345678", AccountKey: account}
+			result, err := VerifyDeviceAttestation(context.Background(), prov, params, object)
+			require.NoError(t, err)
+			fingerprint, err := keyutil.Fingerprint(signer.Public())
+			require.NoError(t, err)
+			require.Equal(t, &DeviceAttestationResult{
+				Format: "tpm", Fingerprint: fingerprint, ChallengeBound: true, IdentifierBound: len(tc.identifiers) != 0,
+			}, result)
+
+			wrongToken := params
+			wrongToken.Token = "wrong"
+			_, err = VerifyDeviceAttestation(context.Background(), prov, wrongToken, object)
+			require.Error(t, err)
+			if len(tc.identifiers) != 0 {
+				wrongIdentifier := params
+				wrongIdentifier.Identifier = "another-device"
+				_, err = VerifyDeviceAttestation(context.Background(), prov, wrongIdentifier, object)
+				require.ErrorContains(t, err, "permanent identifier does not match")
+			}
+		})
+	}
+}

+ 20 - 152
acme/challenge.go

@@ -1,7 +1,6 @@
 package acme
 
 import (
-	"bytes"
 	"context"
 	"crypto"
 	"crypto/ecdsa"
@@ -788,7 +787,6 @@ type attestationObject struct {
 	AttStatement map[string]any `json:"attStmt,omitempty"`
 }
 
-// TODO(bweeks): move attestation verification to a shared package.
 func deviceAttest01Validate(ctx context.Context, ch *Challenge, db DB, jwk *jose.JSONWebKey, payload []byte) error {
 	// Update challenge with the payload
 	ch.Payload = payload
@@ -814,160 +812,21 @@ func deviceAttest01Validate(ctx context.Context, ch *Challenge, db DB, jwk *jose
 		return storeError(ctx, db, ch, true, NewDetailedError(ErrorBadAttestationStatementType, "failed base64 decoding attObj %q", p.AttObj))
 	}
 
-	if len(attObj) == 0 || bytes.Equal(attObj, []byte("{}")) {
-		return storeError(ctx, db, ch, true, NewDetailedError(ErrorBadAttestationStatementType, "attObj must not be empty"))
+	var prov Provisioner
+	if ctx != nil {
+		prov, _ = ProvisionerFromContext(ctx)
 	}
-
-	cborDecoderOptions := cbor.DecOptions{}
-	cborDecoder, err := cborDecoderOptions.DecMode()
+	data, err := VerifyDeviceAttestation(ctx, prov, DeviceAttestationParams{
+		Token: ch.Token, Identifier: ch.Value, AccountKey: jwk,
+	}, attObj)
 	if err != nil {
-		return WrapErrorISE(err, "failed creating CBOR decoder")
-	}
-
-	if err := cborDecoder.Wellformed(attObj); err != nil {
-		return storeError(ctx, db, ch, true, NewDetailedError(ErrorBadAttestationStatementType, "attObj is not well formed CBOR: %v", err))
-	}
-
-	att := attestationObject{}
-	if err := cborDecoder.Unmarshal(attObj, &att); err != nil {
-		return WrapErrorISE(err, "failed unmarshalling CBOR")
-	}
-
-	format := att.Format
-	prov := MustProvisionerFromContext(ctx)
-	if !prov.IsAttestationFormatEnabled(ctx, provisioner.ACMEAttestationFormat(format)) {
-		if format != "apple" && format != "step" && format != "tpm" && format != "android-key" {
-			return storeError(ctx, db, ch, true, NewDetailedError(ErrorBadAttestationStatementType, "unsupported attestation object format %q", format))
+		if acmeError, ok := errors.AsType[*Error](err); ok && acmeError.Status != 500 {
+			return storeError(ctx, db, ch, true, acmeError)
 		}
-
-		return storeError(ctx, db, ch, true,
-			NewError(ErrorBadAttestationStatementType, "attestation format %q is not enabled", format))
-	}
-
-	switch format {
-	case "android-key":
-		data, err := doAndroidKeyAttestationFormat(ctx, prov, ch, jwk, &att)
-		if err != nil {
-			if acmeError, ok := errors.AsType[*Error](err); ok {
-				if acmeError.Status == 500 {
-					return acmeError
-				}
-				return storeError(ctx, db, ch, true, acmeError)
-			}
-			return WrapErrorISE(err, "error validating attestation")
-		}
-
-		// Enforce hardware security level (TrustedEnvironment or StrongBox; Software not allowed)
-		if data.Attestation.AttestationSecurityLevel < 1 {
-			return storeError(ctx, db, ch, true, NewDetailedError(ErrorBadAttestationStatementType, "insufficient security level: %d", data.Attestation.AttestationSecurityLevel))
-		}
-
-		// Enforce hardware backed device serial
-		if ch.Value != string(data.Attestation.TeeEnforced.AttestationIdSerial) {
-			subproblem := NewSubproblemWithIdentifier(
-				ErrorRejectedIdentifierType,
-				Identifier{Type: "permanent-identifier", Value: ch.Value},
-				"challenge identifier %q doesn't match any of the attested hardware identifiers %q", ch.Value, []string{string(data.Attestation.TeeEnforced.AttestationIdSerial)},
-			)
-			return storeError(ctx, db, ch, true, NewDetailedError(ErrorBadAttestationStatementType, "permanent identifier does not match").AddSubproblems(subproblem))
-		}
-
-		// Update attestation key fingerprint to compare against the CSR
-		az.Fingerprint = data.Fingerprint
-	case "apple":
-		data, err := doAppleAttestationFormat(ctx, prov, ch, &att)
-		if err != nil {
-			if acmeError, ok := errors.AsType[*Error](err); ok {
-				if acmeError.Status == 500 {
-					return acmeError
-				}
-				return storeError(ctx, db, ch, true, acmeError)
-			}
-			return WrapErrorISE(err, "error validating attestation")
-		}
-
-		// Validate nonce with SHA-256 of the token.
-		if len(data.Nonce) != 0 {
-			sum := sha256.Sum256([]byte(ch.Token))
-			if subtle.ConstantTimeCompare(data.Nonce, sum[:]) != 1 {
-				return storeError(ctx, db, ch, true, NewDetailedError(ErrorBadAttestationStatementType, "challenge token does not match"))
-			}
-		}
-
-		// Validate Apple's ClientIdentifier (Identifier.Value) with device
-		// identifiers.
-		//
-		// Note: We might want to use an external service for this.
-		if data.UDID != ch.Value && data.SerialNumber != ch.Value {
-			subproblem := NewSubproblemWithIdentifier(
-				ErrorRejectedIdentifierType,
-				Identifier{Type: "permanent-identifier", Value: ch.Value},
-				"challenge identifier %q doesn't match any of the attested hardware identifiers %q", ch.Value, []string{data.UDID, data.SerialNumber},
-			)
-			return storeError(ctx, db, ch, true, NewDetailedError(ErrorBadAttestationStatementType, "permanent identifier does not match").AddSubproblems(subproblem))
-		}
-
-		// Update attestation key fingerprint to compare against the CSR
-		az.Fingerprint = data.Fingerprint
-	case "step":
-		data, err := doStepAttestationFormat(ctx, prov, ch, jwk, &att)
-		if err != nil {
-			if acmeError, ok := errors.AsType[*Error](err); ok {
-				if acmeError.Status == 500 {
-					return acmeError
-				}
-				return storeError(ctx, db, ch, true, acmeError)
-			}
-			return WrapErrorISE(err, "error validating attestation")
-		}
-
-		// Validate the YubiKey serial number from the attestation
-		// certificate with the challenged Order value.
-		//
-		// Note: We might want to use an external service for this.
-		if data.SerialNumber != ch.Value {
-			subproblem := NewSubproblemWithIdentifier(
-				ErrorRejectedIdentifierType,
-				Identifier{Type: "permanent-identifier", Value: ch.Value},
-				"challenge identifier %q doesn't match the attested hardware identifier %q", ch.Value, data.SerialNumber,
-			)
-			return storeError(ctx, db, ch, true, NewDetailedError(ErrorBadAttestationStatementType, "permanent identifier does not match").AddSubproblems(subproblem))
-		}
-
-		// Update attestation key fingerprint to compare against the CSR
-		az.Fingerprint = data.Fingerprint
-
-	case "tpm":
-		data, err := doTPMAttestationFormat(ctx, prov, ch, jwk, &att)
-		if err != nil {
-			if acmeError, ok := errors.AsType[*Error](err); ok {
-				if acmeError.Status == 500 {
-					return acmeError
-				}
-				return storeError(ctx, db, ch, true, acmeError)
-			}
-			return WrapErrorISE(err, "error validating attestation")
-		}
-
-		// TODO(hs): currently this will allow a request for which no PermanentIdentifiers have been
-		// extracted from the AK certificate. This is currently the case for AK certs from the CLI, as we
-		// haven't implemented a way for AK certs requested by the CLI to always contain the requested
-		// PermanentIdentifier. Omitting the check below doesn't allow just any request, as the Order can
-		// still fail if the challenge value isn't equal to the CSR subject.
-		if len(data.PermanentIdentifiers) > 0 && !slices.Contains(data.PermanentIdentifiers, ch.Value) { // TODO(hs): add support for HardwareModuleName
-			subproblem := NewSubproblemWithIdentifier(
-				ErrorRejectedIdentifierType,
-				Identifier{Type: "permanent-identifier", Value: ch.Value},
-				"challenge identifier %q doesn't match any of the attested hardware identifiers %q", ch.Value, data.PermanentIdentifiers,
-			)
-			return storeError(ctx, db, ch, true, NewDetailedError(ErrorBadAttestationStatementType, "permanent identifier does not match").AddSubproblems(subproblem))
-		}
-
-		// Update attestation key fingerprint to compare against the CSR
-		az.Fingerprint = data.Fingerprint
-	default:
-		return storeError(ctx, db, ch, true, NewDetailedError(ErrorBadAttestationStatementType, "unsupported attestation object format %q", format))
+		return err
 	}
+	format := data.Format
+	az.Fingerprint = data.Fingerprint
 
 	// Update and store the challenge.
 	ch.Status = StatusValid
@@ -1169,6 +1028,9 @@ func doTPMAttestationFormat(_ context.Context, prov Provisioner, ch *Challenge,
 		return nil, WrapDetailedError(ErrorBadAttestationStatementType, err, "failed decoding attestation data")
 	}
 
+	if jwk == nil {
+		return nil, NewErrorISE("attestation account key is required")
+	}
 	keyAuth, err := KeyAuthorization(ch.Token, jwk)
 	if err != nil {
 		return nil, WrapErrorISE(err, "failed creating key auth digest")
@@ -1591,6 +1453,9 @@ func doAndroidKeyAttestationFormat(ctx context.Context, prov Provisioner, ch *Ch
 		return nil, NewDetailedError(ErrorBadAttestationStatementType, "sig not present")
 	}
 
+	if jwk == nil {
+		return nil, NewErrorISE("attestation account key is required")
+	}
 	keyAuth, err := KeyAuthorization(ch.Token, jwk)
 	if err != nil {
 		return nil, err
@@ -1761,6 +1626,9 @@ func doStepAttestationFormat(_ context.Context, prov Provisioner, ch *Challenge,
 		return nil, NewDetailedError(ErrorBadAttestationStatementType, "sig is malformed")
 	}
 
+	if jwk == nil {
+		return nil, NewErrorISE("attestation account key is required")
+	}
 	keyAuth, err := KeyAuthorization(ch.Token, jwk)
 	if err != nil {
 		return nil, err