Просмотр исходного кода

Move the apple device attestation verifier to attestation/apple

The verifier of the "apple" format of device-attest-01 moves from
acme/challenge.go to attestation/apple, with Apple's Enterprise
Attestation root. apple.Verify takes the attestation statement and the
roots, nil for Apple's, and returns what the attestation certificate
attests; errors of the statement match attestation.ErrInvalidEvidence.
acme keeps the nonce and identifier checks and maps the verifier's
errors back to the same ACME errors: a bad attestation statement with
the error in its detail, or an internal error.

The draft-ietf-acme-rats (remote-attest-01) work on this branch needs one
place for attestation verifiers, and the device-attest-01 formats are the
first to move there.

Claude-Session: https://claude.ai/code/session_01CjfEMLGpnHQaWsmxe1zmLF
Josh Drake 1 месяц назад
Родитель
Сommit
0bd2c99994
4 измененных файлов с 262 добавлено и 234 удалено
  1. 27 117
      acme/challenge.go
  2. 7 117
      acme/challenge_test.go
  3. 133 0
      attestation/apple/apple.go
  4. 95 0
      attestation/apple/apple_test.go

+ 27 - 117
acme/challenge.go

@@ -31,7 +31,7 @@ import (
 	"github.com/fxamacker/cbor/v2"
 	"github.com/google/go-tpm/legacy/tpm2"
 
-	attestation "github.com/smallstep/android-attestation"
+	androidattestation "github.com/smallstep/android-attestation"
 	"github.com/smallstep/go-attestation/attest"
 	"go.step.sm/crypto/jose"
 	"go.step.sm/crypto/keyutil"
@@ -40,6 +40,8 @@ import (
 	"go.step.sm/crypto/x509util"
 
 	"github.com/smallstep/certificates/acme/wire"
+	"github.com/smallstep/certificates/attestation"
+	"github.com/smallstep/certificates/attestation/apple"
 	"github.com/smallstep/certificates/authority/provisioner"
 	wireprovisioner "github.com/smallstep/certificates/authority/provisioner/wire"
 	"github.com/smallstep/certificates/internal/cast"
@@ -886,15 +888,9 @@ func deviceAttest01Validate(ctx context.Context, ch *Challenge, db DB, jwk *jose
 		// Update attestation key fingerprint to compare against the CSR
 		az.Fingerprint = data.Fingerprint
 	case "apple":
-		data, err := doAppleAttestationFormat(ctx, prov, ch, &att)
+		data, err := apple.Verify(att.AttStatement, attestationRoots(prov))
 		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")
+			return storeAttestationError(ctx, db, ch, err)
 		}
 
 		// Validate nonce with SHA-256 of the token.
@@ -1001,6 +997,26 @@ func deviceAttest01Validate(ctx context.Context, ch *Challenge, db DB, jwk *jose
 	return nil
 }
 
+// attestationRoots returns the attestation roots configured in the
+// provisioner, or nil, which makes a verifier use its default roots.
+func attestationRoots(prov Provisioner) *x509.CertPool {
+	if roots, ok := prov.GetAttestationRoots(); ok {
+		return roots
+	}
+	return nil
+}
+
+// storeAttestationError handles an error of a device-attest-01 verifier. An
+// error of the attestation statement is stored in the challenge, which becomes
+// invalid, as a bad attestation statement with the error in its detail. Any
+// other error is returned as an internal error.
+func storeAttestationError(ctx context.Context, db DB, ch *Challenge, err error) error {
+	if !errors.Is(err, attestation.ErrInvalidEvidence) {
+		return newError(ErrorServerInternalType, err)
+	}
+	return storeError(ctx, db, ch, true, newError(ErrorBadAttestationStatementType, err).withDetail())
+}
+
 var (
 	oidSubjectAlternativeName = asn1.ObjectIdentifier{2, 5, 29, 17}
 )
@@ -1299,112 +1315,6 @@ func validateAKCertificateExtendedKeyUsage(c *x509.Certificate) error {
 	return nil
 }
 
-// Apple Enterprise Attestation Root CA from
-// https://www.apple.com/certificateauthority/private/
-const appleEnterpriseAttestationRootCA = `-----BEGIN CERTIFICATE-----
-MIICJDCCAamgAwIBAgIUQsDCuyxyfFxeq/bxpm8frF15hzcwCgYIKoZIzj0EAwMw
-UTEtMCsGA1UEAwwkQXBwbGUgRW50ZXJwcmlzZSBBdHRlc3RhdGlvbiBSb290IENB
-MRMwEQYDVQQKDApBcHBsZSBJbmMuMQswCQYDVQQGEwJVUzAeFw0yMjAyMTYxOTAx
-MjRaFw00NzAyMjAwMDAwMDBaMFExLTArBgNVBAMMJEFwcGxlIEVudGVycHJpc2Ug
-QXR0ZXN0YXRpb24gUm9vdCBDQTETMBEGA1UECgwKQXBwbGUgSW5jLjELMAkGA1UE
-BhMCVVMwdjAQBgcqhkjOPQIBBgUrgQQAIgNiAAT6Jigq+Ps9Q4CoT8t8q+UnOe2p
-oT9nRaUfGhBTbgvqSGXPjVkbYlIWYO+1zPk2Sz9hQ5ozzmLrPmTBgEWRcHjA2/y7
-7GEicps9wn2tj+G89l3INNDKETdxSPPIZpPj8VmjQjBAMA8GA1UdEwEB/wQFMAMB
-Af8wHQYDVR0OBBYEFPNqTQGd8muBpV5du+UIbVbi+d66MA4GA1UdDwEB/wQEAwIB
-BjAKBggqhkjOPQQDAwNpADBmAjEA1xpWmTLSpr1VH4f8Ypk8f3jMUKYz4QPG8mL5
-8m9sX/b2+eXpTv2pH4RZgJjucnbcAjEA4ZSB6S45FlPuS/u4pTnzoz632rA+xW/T
-ZwFEh9bhKjJ+5VQ9/Do1os0u3LEkgN/r
------END CERTIFICATE-----`
-
-var (
-	oidAppleSerialNumber                    = asn1.ObjectIdentifier{1, 2, 840, 113635, 100, 8, 9, 1}
-	oidAppleUniqueDeviceIdentifier          = asn1.ObjectIdentifier{1, 2, 840, 113635, 100, 8, 9, 2}
-	oidAppleSecureEnclaveProcessorOSVersion = asn1.ObjectIdentifier{1, 2, 840, 113635, 100, 8, 10, 2}
-	oidAppleNonce                           = asn1.ObjectIdentifier{1, 2, 840, 113635, 100, 8, 11, 1}
-)
-
-type appleAttestationData struct {
-	Nonce        []byte
-	SerialNumber string
-	UDID         string
-	SEPVersion   string
-	Certificate  *x509.Certificate
-	Fingerprint  string
-}
-
-func doAppleAttestationFormat(_ context.Context, prov Provisioner, _ *Challenge, att *attestationObject) (*appleAttestationData, error) {
-	// Use configured or default attestation roots if none is configured.
-	roots, ok := prov.GetAttestationRoots()
-	if !ok {
-		root, err := pemutil.ParseCertificate([]byte(appleEnterpriseAttestationRootCA))
-		if err != nil {
-			return nil, WrapErrorISE(err, "error parsing apple enterprise ca")
-		}
-		roots = x509.NewCertPool()
-		roots.AddCert(root)
-	}
-
-	x5c, ok := att.AttStatement["x5c"].([]any)
-	if !ok {
-		return nil, NewDetailedError(ErrorBadAttestationStatementType, "x5c not present")
-	}
-	if len(x5c) == 0 {
-		return nil, NewDetailedError(ErrorBadAttestationStatementType, "x5c is empty")
-	}
-
-	der, ok := x5c[0].([]byte)
-	if !ok {
-		return nil, NewDetailedError(ErrorBadAttestationStatementType, "x5c is malformed")
-	}
-	leaf, err := x509.ParseCertificate(der)
-	if err != nil {
-		return nil, WrapDetailedError(ErrorBadAttestationStatementType, err, "x5c is malformed")
-	}
-
-	intermediates := x509.NewCertPool()
-	for _, v := range x5c[1:] {
-		der, ok = v.([]byte)
-		if !ok {
-			return nil, NewDetailedError(ErrorBadAttestationStatementType, "x5c is malformed")
-		}
-		cert, err := x509.ParseCertificate(der)
-		if err != nil {
-			return nil, WrapDetailedError(ErrorBadAttestationStatementType, err, "x5c is malformed")
-		}
-		intermediates.AddCert(cert)
-	}
-
-	if _, err := leaf.Verify(x509.VerifyOptions{
-		Intermediates: intermediates,
-		Roots:         roots,
-		CurrentTime:   time.Now().Truncate(time.Second),
-		KeyUsages:     []x509.ExtKeyUsage{x509.ExtKeyUsageAny},
-	}); err != nil {
-		return nil, WrapDetailedError(ErrorBadAttestationStatementType, err, "x5c is not valid")
-	}
-
-	data := &appleAttestationData{
-		Certificate: leaf,
-	}
-	if data.Fingerprint, err = keyutil.Fingerprint(leaf.PublicKey); err != nil {
-		return nil, WrapErrorISE(err, "error calculating key fingerprint")
-	}
-	for _, ext := range leaf.Extensions {
-		switch {
-		case ext.Id.Equal(oidAppleSerialNumber):
-			data.SerialNumber = string(ext.Value)
-		case ext.Id.Equal(oidAppleUniqueDeviceIdentifier):
-			data.UDID = string(ext.Value)
-		case ext.Id.Equal(oidAppleSecureEnclaveProcessorOSVersion):
-			data.SEPVersion = string(ext.Value)
-		case ext.Id.Equal(oidAppleNonce):
-			data.Nonce = ext.Value
-		}
-	}
-
-	return data, nil
-}
-
 // Android RSA Root CA
 // https://developer.android.com/privacy-and-security/security-key-attestation#root_certificate
 var androidRSARootCA = `-----BEGIN CERTIFICATE-----
@@ -1461,7 +1371,7 @@ var oidAndroidAttestation = asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 11129, 2, 1,
 type androidKeyAttestationData struct {
 	Certificate *x509.Certificate
 	Fingerprint string
-	Attestation *attestation.KeyDescription
+	Attestation *androidattestation.KeyDescription
 }
 
 // findAndroidAttestationCert traverses the slice of [*x509.Certificate] from
@@ -1629,7 +1539,7 @@ func doAndroidKeyAttestationFormat(ctx context.Context, prov Provisioner, ch *Ch
 		if !ext.Id.Equal(oidAndroidAttestation) {
 			continue
 		}
-		keyDesc, err := attestation.ParseExtension(ext.Value)
+		keyDesc, err := androidattestation.ParseExtension(ext.Value)
 		if err != nil {
 			return nil, WrapError(ErrorBadAttestationStatementType, err, "error parsing attestation")
 		}

+ 7 - 117
acme/challenge_test.go

@@ -194,6 +194,13 @@ func mustAttestAndroid(t *testing.T, keyAuthorization string) ([]byte, *x509.Cer
 	return payload, leaf, ca.Root
 }
 
+var (
+	oidAppleSerialNumber                    = asn1.ObjectIdentifier{1, 2, 840, 113635, 100, 8, 9, 1}
+	oidAppleUniqueDeviceIdentifier          = asn1.ObjectIdentifier{1, 2, 840, 113635, 100, 8, 9, 2}
+	oidAppleSecureEnclaveProcessorOSVersion = asn1.ObjectIdentifier{1, 2, 840, 113635, 100, 8, 10, 2}
+	oidAppleNonce                           = asn1.ObjectIdentifier{1, 2, 840, 113635, 100, 8, 11, 1}
+)
+
 func mustAttestApple(t *testing.T, nonce string) ([]byte, *x509.Certificate, *x509.Certificate) {
 	t.Helper()
 
@@ -3514,123 +3521,6 @@ func Test_http01ChallengeHost(t *testing.T) {
 	}
 }
 
-func Test_doAppleAttestationFormat(t *testing.T) {
-	ctx := context.Background()
-	ca, err := minica.New()
-	if err != nil {
-		t.Fatal(err)
-	}
-	caRoot := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: ca.Root.Raw})
-	signer, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
-	if err != nil {
-		t.Fatal(err)
-	}
-	leaf, err := ca.Sign(&x509.Certificate{
-		Subject:   pkix.Name{CommonName: "attestation cert"},
-		PublicKey: signer.Public(),
-		ExtraExtensions: []pkix.Extension{
-			{Id: oidAppleSerialNumber, Value: []byte("serial-number")},
-			{Id: oidAppleUniqueDeviceIdentifier, Value: []byte("udid")},
-			{Id: oidAppleSecureEnclaveProcessorOSVersion, Value: []byte("16.0")},
-			{Id: oidAppleNonce, Value: []byte("nonce")},
-		},
-	})
-	if err != nil {
-		t.Fatal(err)
-	}
-	fingerprint, err := keyutil.Fingerprint(signer.Public())
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	type args struct {
-		ctx  context.Context
-		prov Provisioner
-		ch   *Challenge
-		att  *attestationObject
-	}
-	tests := []struct {
-		name    string
-		args    args
-		want    *appleAttestationData
-		wantErr bool
-	}{
-		{"ok", args{ctx, mustAttestationProvisioner(t, caRoot), &Challenge{}, &attestationObject{
-			Format: "apple",
-			AttStatement: map[string]any{
-				"x5c": []any{leaf.Raw, ca.Intermediate.Raw},
-			},
-		}}, &appleAttestationData{
-			Nonce:        []byte("nonce"),
-			SerialNumber: "serial-number",
-			UDID:         "udid",
-			SEPVersion:   "16.0",
-			Certificate:  leaf,
-			Fingerprint:  fingerprint,
-		}, false},
-		{"fail apple issuer", args{ctx, mustAttestationProvisioner(t, nil), &Challenge{}, &attestationObject{
-			Format: "apple",
-			AttStatement: map[string]any{
-				"x5c": []any{leaf.Raw, ca.Intermediate.Raw},
-			},
-		}}, nil, true},
-		{"fail missing x5c", args{ctx, mustAttestationProvisioner(t, caRoot), &Challenge{}, &attestationObject{
-			Format: "apple",
-			AttStatement: map[string]any{
-				"foo": "bar",
-			},
-		}}, nil, true},
-		{"fail empty issuer", args{ctx, mustAttestationProvisioner(t, caRoot), &Challenge{}, &attestationObject{
-			Format: "apple",
-			AttStatement: map[string]any{
-				"x5c": []any{},
-			},
-		}}, nil, true},
-		{"fail leaf type", args{ctx, mustAttestationProvisioner(t, caRoot), &Challenge{}, &attestationObject{
-			Format: "apple",
-			AttStatement: map[string]any{
-				"x5c": []any{"leaf", ca.Intermediate.Raw},
-			},
-		}}, nil, true},
-		{"fail leaf parse", args{ctx, mustAttestationProvisioner(t, caRoot), &Challenge{}, &attestationObject{
-			Format: "apple",
-			AttStatement: map[string]any{
-				"x5c": []any{leaf.Raw[:100], ca.Intermediate.Raw},
-			},
-		}}, nil, true},
-		{"fail intermediate type", args{ctx, mustAttestationProvisioner(t, caRoot), &Challenge{}, &attestationObject{
-			Format: "apple",
-			AttStatement: map[string]any{
-				"x5c": []any{leaf.Raw, "intermediate"},
-			},
-		}}, nil, true},
-		{"fail intermediate parse", args{ctx, mustAttestationProvisioner(t, caRoot), &Challenge{}, &attestationObject{
-			Format: "apple",
-			AttStatement: map[string]any{
-				"x5c": []any{leaf.Raw, ca.Intermediate.Raw[:100]},
-			},
-		}}, nil, true},
-		{"fail verify", args{ctx, mustAttestationProvisioner(t, caRoot), &Challenge{}, &attestationObject{
-			Format: "apple",
-			AttStatement: map[string]any{
-				"x5c": []any{leaf.Raw},
-			},
-		}}, nil, true},
-	}
-	for _, tt := range tests {
-		t.Run(tt.name, func(t *testing.T) {
-			got, err := doAppleAttestationFormat(tt.args.ctx, tt.args.prov, tt.args.ch, tt.args.att)
-			if (err != nil) != tt.wantErr {
-				t.Errorf("doAppleAttestationFormat() error = %v, wantErr %v", err, tt.wantErr)
-				return
-			}
-			if !reflect.DeepEqual(got, tt.want) {
-				t.Errorf("doAppleAttestationFormat() = %v, want %v", got, tt.want)
-			}
-		})
-	}
-}
-
 func Test_doStepAttestationFormat(t *testing.T) {
 	ctx := context.Background()
 	ca, err := minica.New()

+ 133 - 0
attestation/apple/apple.go

@@ -0,0 +1,133 @@
+// Package apple verifies attestation statements of the "apple" format of ACME
+// device-attest-01 challenges, made by Apple's Managed Device Attestation.
+package apple
+
+import (
+	"crypto/x509"
+	"encoding/asn1"
+	"fmt"
+	"time"
+
+	"go.step.sm/crypto/keyutil"
+	"go.step.sm/crypto/pemutil"
+
+	"github.com/smallstep/certificates/attestation"
+)
+
+// Apple Enterprise Attestation Root CA from
+// https://www.apple.com/certificateauthority/private/
+const appleEnterpriseAttestationRootCA = `-----BEGIN CERTIFICATE-----
+MIICJDCCAamgAwIBAgIUQsDCuyxyfFxeq/bxpm8frF15hzcwCgYIKoZIzj0EAwMw
+UTEtMCsGA1UEAwwkQXBwbGUgRW50ZXJwcmlzZSBBdHRlc3RhdGlvbiBSb290IENB
+MRMwEQYDVQQKDApBcHBsZSBJbmMuMQswCQYDVQQGEwJVUzAeFw0yMjAyMTYxOTAx
+MjRaFw00NzAyMjAwMDAwMDBaMFExLTArBgNVBAMMJEFwcGxlIEVudGVycHJpc2Ug
+QXR0ZXN0YXRpb24gUm9vdCBDQTETMBEGA1UECgwKQXBwbGUgSW5jLjELMAkGA1UE
+BhMCVVMwdjAQBgcqhkjOPQIBBgUrgQQAIgNiAAT6Jigq+Ps9Q4CoT8t8q+UnOe2p
+oT9nRaUfGhBTbgvqSGXPjVkbYlIWYO+1zPk2Sz9hQ5ozzmLrPmTBgEWRcHjA2/y7
+7GEicps9wn2tj+G89l3INNDKETdxSPPIZpPj8VmjQjBAMA8GA1UdEwEB/wQFMAMB
+Af8wHQYDVR0OBBYEFPNqTQGd8muBpV5du+UIbVbi+d66MA4GA1UdDwEB/wQEAwIB
+BjAKBggqhkjOPQQDAwNpADBmAjEA1xpWmTLSpr1VH4f8Ypk8f3jMUKYz4QPG8mL5
+8m9sX/b2+eXpTv2pH4RZgJjucnbcAjEA4ZSB6S45FlPuS/u4pTnzoz632rA+xW/T
+ZwFEh9bhKjJ+5VQ9/Do1os0u3LEkgN/r
+-----END CERTIFICATE-----`
+
+var (
+	oidAppleSerialNumber                    = asn1.ObjectIdentifier{1, 2, 840, 113635, 100, 8, 9, 1}
+	oidAppleUniqueDeviceIdentifier          = asn1.ObjectIdentifier{1, 2, 840, 113635, 100, 8, 9, 2}
+	oidAppleSecureEnclaveProcessorOSVersion = asn1.ObjectIdentifier{1, 2, 840, 113635, 100, 8, 10, 2}
+	oidAppleNonce                           = asn1.ObjectIdentifier{1, 2, 840, 113635, 100, 8, 11, 1}
+)
+
+// Data is what a verified "apple" attestation statement attests.
+type Data struct {
+	// Nonce is the freshness nonce the attestation certificate binds, if any.
+	Nonce []byte
+	// SerialNumber is the serial number of the device.
+	SerialNumber string
+	// UDID is the unique device identifier of the device.
+	UDID string
+	// SEPVersion is the version of the operating system of the device's
+	// Secure Enclave Processor.
+	SEPVersion string
+	// Certificate is the attestation certificate, the leaf of the x5c chain,
+	// which holds the attested key.
+	Certificate *x509.Certificate
+	// Fingerprint is the fingerprint of the attested key.
+	Fingerprint string
+}
+
+// Verify verifies the x5c chain of an "apple" attestation statement against
+// roots, or against Apple's Enterprise Attestation Root CA if roots is nil,
+// and returns what its attestation certificate attests. Errors of the
+// statement match attestation.ErrInvalidEvidence.
+func Verify(attStmt map[string]any, roots *x509.CertPool) (*Data, error) {
+	// Use the default attestation root if none is configured.
+	if roots == nil {
+		root, err := pemutil.ParseCertificate([]byte(appleEnterpriseAttestationRootCA))
+		if err != nil {
+			return nil, fmt.Errorf("error parsing apple enterprise ca: %w", err)
+		}
+		roots = x509.NewCertPool()
+		roots.AddCert(root)
+	}
+
+	x5c, ok := attStmt["x5c"].([]any)
+	if !ok {
+		return nil, attestation.Invalidf("x5c not present")
+	}
+	if len(x5c) == 0 {
+		return nil, attestation.Invalidf("x5c is empty")
+	}
+
+	der, ok := x5c[0].([]byte)
+	if !ok {
+		return nil, attestation.Invalidf("x5c is malformed")
+	}
+	leaf, err := x509.ParseCertificate(der)
+	if err != nil {
+		return nil, attestation.Invalidf("x5c is malformed: %w", err)
+	}
+
+	intermediates := x509.NewCertPool()
+	for _, v := range x5c[1:] {
+		der, ok = v.([]byte)
+		if !ok {
+			return nil, attestation.Invalidf("x5c is malformed")
+		}
+		cert, err := x509.ParseCertificate(der)
+		if err != nil {
+			return nil, attestation.Invalidf("x5c is malformed: %w", err)
+		}
+		intermediates.AddCert(cert)
+	}
+
+	if _, err := leaf.Verify(x509.VerifyOptions{
+		Intermediates: intermediates,
+		Roots:         roots,
+		CurrentTime:   time.Now().Truncate(time.Second),
+		KeyUsages:     []x509.ExtKeyUsage{x509.ExtKeyUsageAny},
+	}); err != nil {
+		return nil, attestation.Invalidf("x5c is not valid: %w", err)
+	}
+
+	data := &Data{
+		Certificate: leaf,
+	}
+	if data.Fingerprint, err = keyutil.Fingerprint(leaf.PublicKey); err != nil {
+		return nil, fmt.Errorf("error calculating key fingerprint: %w", err)
+	}
+	for _, ext := range leaf.Extensions {
+		switch {
+		case ext.Id.Equal(oidAppleSerialNumber):
+			data.SerialNumber = string(ext.Value)
+		case ext.Id.Equal(oidAppleUniqueDeviceIdentifier):
+			data.UDID = string(ext.Value)
+		case ext.Id.Equal(oidAppleSecureEnclaveProcessorOSVersion):
+			data.SEPVersion = string(ext.Value)
+		case ext.Id.Equal(oidAppleNonce):
+			data.Nonce = ext.Value
+		}
+	}
+
+	return data, nil
+}

+ 95 - 0
attestation/apple/apple_test.go

@@ -0,0 +1,95 @@
+package apple
+
+import (
+	"crypto/ecdsa"
+	"crypto/elliptic"
+	"crypto/rand"
+	"crypto/x509"
+	"crypto/x509/pkix"
+	"testing"
+
+	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/require"
+	"go.step.sm/crypto/keyutil"
+	"go.step.sm/crypto/minica"
+
+	"github.com/smallstep/certificates/attestation"
+)
+
+func TestVerify(t *testing.T) {
+	ca, err := minica.New()
+	require.NoError(t, err)
+	roots := x509.NewCertPool()
+	roots.AddCert(ca.Root)
+
+	signer, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
+	require.NoError(t, err)
+	leaf, err := ca.Sign(&x509.Certificate{
+		Subject:   pkix.Name{CommonName: "attestation cert"},
+		PublicKey: signer.Public(),
+		ExtraExtensions: []pkix.Extension{
+			{Id: oidAppleSerialNumber, Value: []byte("serial-number")},
+			{Id: oidAppleUniqueDeviceIdentifier, Value: []byte("udid")},
+			{Id: oidAppleSecureEnclaveProcessorOSVersion, Value: []byte("16.0")},
+			{Id: oidAppleNonce, Value: []byte("nonce")},
+		},
+	})
+	require.NoError(t, err)
+	fingerprint, err := keyutil.Fingerprint(signer.Public())
+	require.NoError(t, err)
+
+	tests := []struct {
+		name    string
+		attStmt map[string]any
+		roots   *x509.CertPool
+		want    *Data
+		wantErr bool
+	}{
+		{"ok", map[string]any{
+			"x5c": []any{leaf.Raw, ca.Intermediate.Raw},
+		}, roots, &Data{
+			Nonce:        []byte("nonce"),
+			SerialNumber: "serial-number",
+			UDID:         "udid",
+			SEPVersion:   "16.0",
+			Certificate:  leaf,
+			Fingerprint:  fingerprint,
+		}, false},
+		{"fail apple issuer", map[string]any{
+			"x5c": []any{leaf.Raw, ca.Intermediate.Raw},
+		}, nil, nil, true},
+		{"fail missing x5c", map[string]any{
+			"foo": "bar",
+		}, roots, nil, true},
+		{"fail empty issuer", map[string]any{
+			"x5c": []any{},
+		}, roots, nil, true},
+		{"fail leaf type", map[string]any{
+			"x5c": []any{"leaf", ca.Intermediate.Raw},
+		}, roots, nil, true},
+		{"fail leaf parse", map[string]any{
+			"x5c": []any{leaf.Raw[:100], ca.Intermediate.Raw},
+		}, roots, nil, true},
+		{"fail intermediate type", map[string]any{
+			"x5c": []any{leaf.Raw, "intermediate"},
+		}, roots, nil, true},
+		{"fail intermediate parse", map[string]any{
+			"x5c": []any{leaf.Raw, ca.Intermediate.Raw[:100]},
+		}, roots, nil, true},
+		{"fail verify", map[string]any{
+			"x5c": []any{leaf.Raw},
+		}, roots, nil, true},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			got, err := Verify(tt.attStmt, tt.roots)
+			if tt.wantErr {
+				assert.ErrorIs(t, err, attestation.ErrInvalidEvidence)
+				assert.Nil(t, got)
+				return
+			}
+			require.NoError(t, err)
+			assert.Equal(t, tt.want, got)
+		})
+	}
+}