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

Add android-key attestation format support

Add a new attestationFormat for ACME device-attest-01 challenge to
support Android attestation (android-key) as defined by WebAuthn and
modify by RFC (sig use key authorization).

The implementation involve adding a CRL. ACME provider support a new
configuration key called RootCRLs (rootCRLs in json).
When 'android-key' is specified in attestationFormat and the list is
not provided by the configuration, the list will be populated and
updated
automatically based on the validation implementation procedure.
Other ACME challenge could use IsRootRevoked and RootCRLs in the future
independantly to android-key or device-attest-01 challenge.
Jean-Baptiste Pin 1 год назад
Родитель
Сommit
5e3b8433cf
7 измененных файлов с 473 добавлено и 5 удалено
  1. 222 1
      acme/challenge.go
  2. 178 0
      acme/challenge_test.go
  3. 61 2
      authority/provisioner/acme.go
  4. 5 2
      authority/provisioner/acme_test.go
  5. 4 0
      authority/provisioners.go
  6. 1 0
      go.mod
  7. 2 0
      go.sum

+ 222 - 1
acme/challenge.go

@@ -16,6 +16,7 @@ import (
 	"encoding/base64"
 	"encoding/hex"
 	"encoding/json"
+	"encoding/pem"
 	"errors"
 	"fmt"
 	"io"
@@ -37,6 +38,7 @@ import (
 	"go.step.sm/crypto/pemutil"
 	"go.step.sm/crypto/x509util"
 
+	"github.com/mbreban/attestation"
 	"github.com/smallstep/certificates/acme/wire"
 	"github.com/smallstep/certificates/authority/provisioner"
 	wireprovisioner "github.com/smallstep/certificates/authority/provisioner/wire"
@@ -838,7 +840,7 @@ func deviceAttest01Validate(ctx context.Context, ch *Challenge, db DB, jwk *jose
 	format := att.Format
 	prov := MustProvisionerFromContext(ctx)
 	if !prov.IsAttestationFormatEnabled(ctx, provisioner.ACMEAttestationFormat(format)) {
-		if format != "apple" && format != "step" && format != "tpm" {
+		if format != "apple" && format != "step" && format != "tpm" && format != "android-key" {
 			return storeError(ctx, db, ch, true, NewDetailedError(ErrorBadAttestationStatementType, "unsupported attestation object format %q", format))
 		}
 
@@ -847,6 +849,36 @@ func deviceAttest01Validate(ctx context.Context, ch *Challenge, db DB, jwk *jose
 	}
 
 	switch format {
+	case "android-key":
+		data, err := doAndroidKeyAttestionFormat(ctx, prov, ch, jwk, &att)
+		if err != nil {
+			var acmeError *Error
+			if errors.As(err, &acmeError) {
+				if acmeError.Status == 500 {
+					return acmeError
+				}
+				return storeError(ctx, db, ch, true, acmeError)
+			}
+			return WrapErrorISE(err, "error validating attestation")
+		}
+
+		// 1. attestationSecurityLevel > 0
+		if data.Attestation.AttestationSecurityLevel < 1 {
+			return storeError(ctx, db, ch, true, NewDetailedError(ErrorBadAttestationStatementType, "Security Level does not match"))
+		}
+
+		// 2. hardwareEnforced
+		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 {
@@ -1370,6 +1402,195 @@ func doAppleAttestationFormat(_ context.Context, prov Provisioner, _ *Challenge,
 	return data, nil
 }
 
+// Android Root CA
+// https://developer.android.com/privacy-and-security/security-key-attestation#root_certificate
+const AndroidRootCAPubKey = `-----BEGIN PUBLIC KEY-----
+MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAr7bHgiuxpwHsK7Qui8xU
+FmOr75gvMsd/dTEDDJdSSxtf6An7xyqpRR90PL2abxM1dEqlXnf2tqw1Ne4Xwl5j
+lRfdnJLmN0pTy/4lj4/7tv0Sk3iiKkypnEUtR6WfMgH0QZfKHM1+di+y9TFRtv6y
+//0rb+T+W8a9nsNL/ggjnar86461qO0rOs2cXjp3kOG1FEJ5MVmFmBGtnrKpa73X
+pXyTqRxB/M0n1n/W9nGqC4FSYa04T6N5RIZGBN2z2MT5IKGbFlbC8UrW0DxW7AYI
+mQQcHtGl/m00QLVWutHQoVJYnFPlXTcHYvASLu+RhhsbDmxMgJJ0mcDpvsC4PjvB
++TxywElgS70vE0XmLD+OJtvsBslHZvPBKCOdT0MS+tgSOIfga+z1Z1g7+DVagf7q
+uvmag8jfPioyKvxnK/EgsTUVi2ghzq8wm27ud/mIM7AY2qEORR8Go3TVB4HzWQgp
+Zrt3i5MIlCaY504LzSRiigHCzAPlHws+W0rB5N+er5/2pJKnfBSDiCiFAVtCLOZ7
+gLiMm0jhO2B6tUXHI/+MRPjy02i59lINMRRev56GKtcd9qO/0kUJWdZTdA2XoS82
+ixPvZtXQpUpuL12ab+9EaDK8Z4RHJYYfCT3Q5vNAXaiWQ+8PTWm2QgBR/bkwSWc+
+NpUFgNPN9PvQi8WEg5UmAGMCAwEAAQ==
+-----END PUBLIC KEY-----`
+
+// Attestion oid for Android, encoded as an integer.
+// https://source.android.com/docs/security/features/keystore/attestation#id-attestation
+var oidAndroidAttestation = asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 11129, 2, 1, 17}
+
+type androidKeyAttestationData struct {
+	Certificate *x509.Certificate
+	Fingerprint string
+	Attestation *attestation.KeyDescription
+}
+
+func findAndroidAttestationCert(intermediates []*x509.Certificate) (*x509.Certificate, error) {
+	for _, cert := range intermediates {
+		for _, ext := range cert.Extensions {
+			if ext.Id.Equal(oidAndroidAttestation) {
+				return cert, nil
+			}
+		}
+	}
+	return nil, errors.New("no attestation certificate with OID 1.3.6.1.4.1.11129.2.1.17 found in the cert chain")
+}
+
+// https://developer.android.com/privacy-and-security/security-key-attestation
+// 3. Verify that the root public certificate is trustworthy and that each certificate signs the next certificate in the chain.
+// 4. Check each certificate's revocation status to ensure that none of the certificates have been revoked.
+// 5. Optionally, inspect the provisioning information certificate extension that is only present in newer certificate chains.
+//    Obtain a reference to the CBOR parser library that is most appropriate for your toolset. Find the nearest certificate to the root that contains the provisioning information certificate extension. Use the parser to extract the provisioning information certificate extension data from that certificate.
+//    See the section about the provisioning information extension for more details.
+// 6. Find the nearest certificate to the root that contains the key attestation certificate extension. If the provisioning information certificate extension was present, the key attestation certificate extension must be in the immediately subsequent certificate. Use the parser to extract the key attestation certificate extension data from that certificate.
+// 7. Check the extension data that you've retrieved in the previous steps for consistency and compare with the set of values that you expect the hardware-backed key to contain.
+
+func doAndroidKeyAttestionFormat(_ context.Context, prov Provisioner, ch *Challenge, jwk *jose.JSONWebKey, att *attestationObject) (*androidKeyAttestationData, error) {
+	// Extract x5c and verify certificate
+	acme := prov.(*provisioner.ACME)
+	certs := []*x509.Certificate{}
+	x5c, ok := att.AttStatement["x5c"].([]any)
+	if !ok {
+		return nil, NewDetailedError(ErrorBadAttestationStatementType, "x5c not present")
+	}
+	if len(x5c) == 0 {
+		return nil, NewDetailedError(ErrorRejectedIdentifierType, "x5c is empty")
+	}
+	der, ok := x5c[0].([]byte)
+	if !ok {
+		return nil, NewDetailedError(ErrorBadAttestationStatementType, "x5c[0] is not a DER []byte")
+	}
+	leaf, err := x509.ParseCertificate(der)
+	if err != nil {
+		return nil, WrapDetailedError(ErrorBadAttestationStatementType, err, "failed to parse leaf certificate")
+	}
+	certs = append(certs, leaf)
+
+	// Parse intermediates and root
+	intermediates := x509.NewCertPool()
+	var root *x509.Certificate
+	for i, v := range x5c[1:] {
+		der, ok := v.([]byte)
+		if !ok {
+			return nil, NewDetailedError(ErrorBadAttestationStatementType, "x5c element is not a DER []byte")
+		}
+		cert, err := x509.ParseCertificate(der)
+		if err != nil {
+			return nil, WrapDetailedError(ErrorBadAttestationStatementType, err, "failed to parse intermediate/root certificate")
+		}
+		// Verify CRL
+		if acme.IsRootRevoked(cert.SerialNumber.String()) {
+			return nil, NewDetailedError(ErrorBadAttestationStatementType, "x5c element contain a revoked certificate")
+		}
+		if i == len(x5c)-2 {
+			// Last cert = root
+			certs = append(certs, cert)
+			root = cert
+		} else {
+			certs = append(certs, cert)
+			intermediates.AddCert(cert)
+		}
+	}
+
+	if root == nil {
+		return nil, NewDetailedError(ErrorBadAttestationStatementType, "missing root certificate in x5c chain")
+	}
+
+	block, _ := pem.Decode([]byte(AndroidRootCAPubKey))
+	trustedPubKey, err := x509.ParsePKIXPublicKey(block.Bytes)
+	switch root.PublicKey.(type) {
+	case *rsa.PublicKey:
+		if !root.PublicKey.(*rsa.PublicKey).Equal(trustedPubKey) {
+			return nil, NewDetailedError(ErrorBadAttestationStatementType, "Root certificate not signed by Android")
+		}
+	default:
+		return nil, NewDetailedError(ErrorBadAttestationStatementType, "Invalid root certificate signature algorithm")
+	}
+
+	// Validate the full chain including root as trust anchor
+	roots := x509.NewCertPool()
+	roots.AddCert(root)
+
+	if _, err := leaf.Verify(x509.VerifyOptions{
+		Intermediates: intermediates,
+		Roots:         roots,
+		CurrentTime:   time.Now().Add(2 * time.Second).Truncate(time.Second),
+		KeyUsages:     []x509.ExtKeyUsage{x509.ExtKeyUsageCodeSigning},
+	}); err != nil {
+		return nil, WrapDetailedError(ErrorBadAttestationStatementType, err, "x5c chain verification failed")
+	}
+
+	// Get signature
+	sig, ok := att.AttStatement["sig"].([]byte)
+	if !ok {
+		return nil, NewDetailedError(ErrorBadAttestationStatementType, "sig not present")
+	}
+
+	keyAuth, err := KeyAuthorization(ch.Token, jwk)
+	if err != nil {
+		return nil, err
+	}
+
+	// Parse attestation data:
+	// find the attestation certificate
+	attCert, err := findAndroidAttestationCert(certs)
+	if err != nil {
+		return nil, WrapDetailedError(ErrorBadAttestationStatementType, err, "")
+	}
+
+	switch pub := attCert.PublicKey.(type) {
+	case *ecdsa.PublicKey:
+		if pub.Curve != elliptic.P256() {
+			return nil, WrapDetailedError(ErrorBadAttestationStatementType, err, "unsupported elliptic curve %s", pub.Curve)
+		}
+		sum := sha256.Sum256([]byte(keyAuth))
+		if !ecdsa.VerifyASN1(pub, sum[:], sig) {
+			return nil, NewDetailedError(ErrorBadAttestationStatementType, "failed to validate signature")
+		}
+	case *rsa.PublicKey:
+		sum := sha256.Sum256([]byte(keyAuth))
+		if err := rsa.VerifyPKCS1v15(pub, crypto.SHA256, sum[:], sig); err != nil {
+			return nil, NewDetailedError(ErrorBadAttestationStatementType, "failed to validate signature")
+		}
+	case ed25519.PublicKey:
+		if !ed25519.Verify(pub, []byte(keyAuth), sig) {
+			return nil, NewDetailedError(ErrorBadAttestationStatementType, "failed to validate signature")
+		}
+	default:
+		return nil, NewDetailedError(ErrorBadAttestationStatementType, "unsupported public key type %T", pub)
+	}
+
+	data := &androidKeyAttestationData{
+		Certificate: attCert,
+	}
+	if data.Fingerprint, err = keyutil.Fingerprint(attCert.PublicKey); err != nil {
+		return nil, WrapErrorISE(err, "error calculating key fingerprint")
+	}
+
+	for _, ext := range attCert.Extensions {
+		if !ext.Id.Equal(oidAndroidAttestation) {
+			continue
+		}
+		keyDesc, err := attestation.ParseExtension(ext.Value)
+		if err != nil {
+			return nil, WrapError(ErrorBadAttestationStatementType, err, "error parsing attestation")
+		}
+		data.Attestation = keyDesc
+		break
+	}
+
+	// validate challenge
+	if string(data.Attestation.AttestationChallenge) != keyAuth {
+		return nil, NewDetailedError(ErrorBadAttestationStatementType, "Challenge mismatach: "+string(data.Attestation.AttestationChallenge))
+	}
+
+	return data, nil
+}
+
 // Yubico PIV Root CA Serial 263751
 // https://developers.yubico.com/PIV/Introduction/piv-attestation-ca.pem
 const yubicoPIVRootCA = `-----BEGIN CERTIFICATE-----

+ 178 - 0
acme/challenge_test.go

@@ -31,6 +31,7 @@ import (
 	"time"
 
 	"github.com/fxamacker/cbor/v2"
+	"github.com/mbreban/attestation"
 	"github.com/stretchr/testify/assert"
 	"github.com/stretchr/testify/require"
 
@@ -98,6 +99,24 @@ func mustAttestationProvisioner(t *testing.T, roots []byte) Provisioner {
 	return prov
 }
 
+func mustNonCRLAttestationProvisioner(t *testing.T, roots []byte, CRLs []string) Provisioner {
+	t.Helper()
+
+	prov := &provisioner.ACME{
+		Type:             "ACME",
+		Name:             "acme",
+		Challenges:       []provisioner.ACMEChallenge{provisioner.DEVICE_ATTEST_01},
+		AttestationRoots: roots,
+		RootCRLs:         CRLs,
+	}
+	if err := prov.Init(provisioner.Config{
+		Claims: config.GlobalProvisionerClaims,
+	}); err != nil {
+		t.Fatal(err)
+	}
+	return prov
+}
+
 func mustAccountAndKeyAuthorization(t *testing.T, token string) (*jose.JSONWebKey, string) {
 	t.Helper()
 
@@ -109,6 +128,75 @@ func mustAccountAndKeyAuthorization(t *testing.T, token string) (*jose.JSONWebKe
 	return jwk, keyAuth
 }
 
+func mustAttestAndroid(t *testing.T, keyAuthorization string) ([]byte, *x509.Certificate, *x509.Certificate, *x509.Certificate) {
+	t.Helper()
+
+	ca, err := minica.New()
+	fatalError(t, err)
+
+	signer, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
+	fatalError(t, err)
+
+	keyAuthSum := sha256.Sum256([]byte(keyAuthorization))
+	fatalError(t, err)
+
+	sig, err := signer.Sign(rand.Reader, keyAuthSum[:], crypto.SHA256)
+	fatalError(t, err)
+
+	atts := attestation.KeyDescription{
+		AttestationVersion:       300,
+		AttestationSecurityLevel: 1,
+		AttestationChallenge:     sig,
+		TeeEnforced: attestation.AuthorizationList{
+			AttestationIdSerial: []byte("serial-number"),
+		},
+	}
+	attestByte, err := attestation.CreateKeyDescription(&atts)
+	if err != nil {
+		fatalError(t, err)
+	}
+
+	block, _ := pem.Decode([]byte(AndroidRootCAPubKey))
+	trustedPubKey, err := x509.ParsePKIXPublicKey(block.Bytes)
+
+	rootAndroid, err := ca.Sign(&x509.Certificate{
+		Subject:   pkix.Name{CommonName: "attestation cert"},
+		PublicKey: trustedPubKey,
+		Extensions: []pkix.Extension{
+			{Id: oidAndroidAttestation, Value: attestByte},
+		},
+	})
+
+	leaf, err := ca.Sign(&x509.Certificate{
+		Subject:   pkix.Name{CommonName: "attestation cert"},
+		PublicKey: signer.Public(),
+		Extensions: []pkix.Extension{
+			{Id: oidAndroidAttestation, Value: attestByte},
+		},
+	})
+	fatalError(t, err)
+
+	attObj, err := cbor.Marshal(struct {
+		Format       string                 `json:"fmt"`
+		AttStatement map[string]interface{} `json:"attStmt,omitempty"`
+	}{
+		Format: "android-key",
+		AttStatement: map[string]interface{}{
+			"x5c": []interface{}{leaf.Raw, ca.Intermediate.Raw, rootAndroid},
+		},
+	})
+	fatalError(t, err)
+
+	payload, err := json.Marshal(struct {
+		AttObj string `json:"attObj"`
+	}{
+		AttObj: base64.RawURLEncoding.EncodeToString(attObj),
+	})
+	fatalError(t, err)
+
+	return payload, leaf, ca.Root, rootAndroid
+}
+
 func mustAttestApple(t *testing.T, nonce string) ([]byte, *x509.Certificate, *x509.Certificate) {
 	t.Helper()
 
@@ -4503,6 +4591,96 @@ func Test_deviceAttest01Validate(t *testing.T) {
 				wantErr: nil,
 			}
 		},
+		"ok/doAndroidAttestationFormat": func(t *testing.T) test {
+
+			jwk, keyAuth := mustAccountAndKeyAuthorization(t, "token")
+			payload, _, root, _ := mustAttestAndroid(t, keyAuth)
+
+			caRoot := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: root.Raw})
+			ctx := NewProvisionerContext(context.Background(), mustAttestationProvisioner(t, caRoot))
+			return test{
+				args: args{
+					ctx: ctx,
+					jwk: jwk,
+					ch: &Challenge{
+						ID:              "chID",
+						AuthorizationID: "azID",
+						Token:           "nonce",
+						Type:            "device-attest-01",
+						Status:          StatusPending,
+						Value:           "serial-number",
+					},
+					payload: payload,
+					db: &MockDB{
+						MockGetAuthorization: func(ctx context.Context, id string) (*Authorization, error) {
+							assert.Equal(t, "azID", id)
+							return &Authorization{ID: "azID"}, nil
+						},
+						MockUpdateChallenge: func(ctx context.Context, updch *Challenge) error {
+							assert.Equal(t, "chID", updch.ID)
+							assert.Equal(t, "nonce", updch.Token)
+							assert.Equal(t, StatusInvalid, updch.Status)
+							assert.Equal(t, ChallengeType("device-attest-01"), updch.Type)
+							assert.Equal(t, "serial-number", updch.Value)
+							assert.Nil(t, updch.Payload)
+							assert.Empty(t, updch.PayloadFormat)
+
+							return nil
+						},
+					},
+				},
+				wantErr: nil,
+			}
+		},
+		"ok/doAndroidAttestationFormat-invalid-root": func(t *testing.T) test {
+
+			jwk, keyAuth := mustAccountAndKeyAuthorization(t, "token")
+			payload, _, root, attestationRoot := mustAttestAndroid(t, keyAuth)
+
+			caRoot := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: root.Raw})
+			ctx := NewProvisionerContext(context.Background(), mustNonCRLAttestationProvisioner(t, caRoot, []string{attestationRoot.SerialNumber.String()}))
+			return test{
+				args: args{
+					ctx: ctx,
+					jwk: jwk,
+					ch: &Challenge{
+						ID:              "chID",
+						AuthorizationID: "azID",
+						Token:           "nonce",
+						Type:            "device-attest-01",
+						Status:          StatusPending,
+						Value:           "serial-number",
+					},
+					payload: payload,
+					db: &MockDB{
+						MockGetAuthorization: func(ctx context.Context, id string) (*Authorization, error) {
+							assert.Equal(t, "azID", id)
+							return &Authorization{ID: "azID"}, nil
+						},
+						MockUpdateChallenge: func(ctx context.Context, updch *Challenge) error {
+							assert.Equal(t, "chID", updch.ID)
+							assert.Equal(t, "nonce", updch.Token)
+							assert.Equal(t, StatusInvalid, updch.Status)
+							assert.Equal(t, ChallengeType("device-attest-01"), updch.Type)
+							assert.Equal(t, "serial-number", updch.Value)
+							assert.Nil(t, updch.Payload)
+							assert.Empty(t, updch.PayloadFormat)
+
+							err := NewDetailedError(ErrorBadAttestationStatementType, "x5c element contain a revoked certificate")
+
+							assert.EqualError(t, updch.Error.Err, err.Err.Error())
+							assert.Equal(t, err.Type, updch.Error.Type)
+							assert.Equal(t, err.Detail, updch.Error.Detail)
+							assert.Equal(t, err.Status, updch.Error.Status)
+							assert.Equal(t, err.Subproblems, updch.Error.Subproblems)
+
+							return nil
+						},
+					},
+				},
+				wantErr: nil,
+			}
+		},
 		"ok/doStepAttestationFormat-storeError": func(t *testing.T) test {
 			ca, err := minica.New()
 			require.NoError(t, err)

+ 61 - 2
authority/provisioner/acme.go

@@ -3,9 +3,14 @@ package provisioner
 import (
 	"context"
 	"crypto/x509"
+	"encoding/json"
 	"encoding/pem"
 	"fmt"
+	"io"
+	"log"
 	"net"
+	"net/http"
+	"slices"
 	"strings"
 	"time"
 
@@ -53,6 +58,9 @@ func (c ACMEChallenge) Validate() error {
 type ACMEAttestationFormat string
 
 const (
+	// APPLE is the format used to enable device-attest-01 on Apple devices.
+	ANDROID ACMEAttestationFormat = "android-key"
+
 	// APPLE is the format used to enable device-attest-01 on Apple devices.
 	APPLE ACMEAttestationFormat = "apple"
 
@@ -74,7 +82,7 @@ func (f ACMEAttestationFormat) String() string {
 // Validate returns an error if the attestation format is not a valid one.
 func (f ACMEAttestationFormat) Validate() error {
 	switch ACMEAttestationFormat(f.String()) {
-	case APPLE, STEP, TPM:
+	case APPLE, STEP, TPM, ANDROID:
 		return nil
 	default:
 		return fmt.Errorf("acme attestation format %q is not supported", f)
@@ -120,6 +128,8 @@ type ACME struct {
 	AttestationRoots    []byte   `json:"attestationRoots,omitempty"`
 	Claims              *Claims  `json:"claims,omitempty"`
 	Options             *Options `json:"options,omitempty"`
+	RootCRLs            []string `json:"rootCRLs,omitempty"`
+	androidCRLTimeout   time.Time
 	attestationRootPool *x509.CertPool
 	ctl                 *Controller
 }
@@ -217,10 +227,50 @@ func (p *ACME) Init(config Config) (err error) {
 		return fmt.Errorf("failed initializing Wire options: %w", err)
 	}
 
+	if slices.Contains(p.AttestationFormats, "android-key") && len(p.RootCRLs) == 0 {
+		p.initializeAndroidCRL()
+	}
+
 	p.ctl, err = NewController(p, p.Claims, config, p.Options)
 	return
 }
 
+const ANDROID_ATTESTATION_STATUS_URL = "https://android.googleapis.com/attestation/status"
+
+// fetch CRL https://android.googleapis.com/attestation/status and build a list of serial number
+func (p *ACME) initializeAndroidCRL() error {
+	log.Printf("Updating Android CRL list for %s ACME provisioner", p.Name)
+	var CRLResponse struct {
+		Entries map[string]struct {
+			Status string `json:"status"`
+			Reason string `json:"reason"`
+		} `json:"entries"`
+	}
+	res, err := http.Get(ANDROID_ATTESTATION_STATUS_URL)
+	if err != nil {
+		return fmt.Errorf("client: error making Android CRL request: %s\n", err)
+	}
+	defer res.Body.Close()
+
+	if res.StatusCode != http.StatusOK {
+		bodyBytes, _ := io.ReadAll(res.Body)
+		return fmt.Errorf("unexpected Android CRL response %d: %s", res.StatusCode, string(bodyBytes))
+	}
+
+	if err := json.NewDecoder(res.Body).Decode(&CRLResponse); err != nil {
+		return fmt.Errorf("error decoding Android CRL JSON: %w", err)
+	}
+
+	// Extract keys into a slice
+	keys := make([]string, 0, len(CRLResponse.Entries))
+	for k := range CRLResponse.Entries {
+		keys = append(keys, k)
+	}
+	p.RootCRLs = keys
+	p.androidCRLTimeout = time.Now().Add(24 * time.Hour)
+	return nil
+}
+
 // initializeWireOptions initializes the options for the ACME Wire
 // integration. It'll return early if no Wire challenge types are
 // enabled.
@@ -372,7 +422,7 @@ func (p *ACME) IsChallengeEnabled(_ context.Context, challenge ACMEChallenge) bo
 // AttestationFormat provisioner property should have at least one element.
 func (p *ACME) IsAttestationFormatEnabled(_ context.Context, format ACMEAttestationFormat) bool {
 	enabledFormats := []ACMEAttestationFormat{
-		APPLE, STEP, TPM,
+		APPLE, STEP, TPM, ANDROID,
 	}
 	if len(p.AttestationFormats) > 0 {
 		enabledFormats = p.AttestationFormats
@@ -393,3 +443,12 @@ func (p *ACME) IsAttestationFormatEnabled(_ context.Context, format ACMEAttestat
 func (p *ACME) GetAttestationRoots() (*x509.CertPool, bool) {
 	return p.attestationRootPool, p.attestationRootPool != nil
 }
+
+// IsRootRevoked return a true if the serialNumber is part of the list
+// It will also be in charge of updating the list periodically if no CRL list is provided at configuration.
+func (p *ACME) IsRootRevoked(serialNumber string) bool {
+	if slices.Contains(p.AttestationFormats, "android-key") && !p.androidCRLTimeout.IsZero() && time.Now().After(p.androidCRLTimeout) {
+		p.initializeAndroidCRL()
+	}
+	return len(p.RootCRLs) > 0 && slices.Contains(p.RootCRLs, serialNumber)
+}

+ 5 - 2
authority/provisioner/acme_test.go

@@ -51,6 +51,7 @@ func TestACMEAttestationFormat_Validate(t *testing.T) {
 		f       ACMEAttestationFormat
 		wantErr bool
 	}{
+		{"android", ANDROID, false},
 		{"apple", APPLE, false},
 		{"step", STEP, false},
 		{"tpm", TPM, false},
@@ -201,7 +202,7 @@ MCowBQYDK2VwAyEA5c+4NKZSNQcR1T8qN6SjwgdPZQ0Ge12Ylx/YeGAJ35k=
 					Name:               "foo",
 					Type:               "ACME",
 					Challenges:         []ACMEChallenge{DNS_01, DEVICE_ATTEST_01},
-					AttestationFormats: []ACMEAttestationFormat{APPLE, STEP},
+					AttestationFormats: []ACMEAttestationFormat{APPLE, STEP, ANDROID},
 					AttestationRoots:   bytes.Join([][]byte{appleCA, yubicoCA}, []byte("\n")),
 				},
 			}
@@ -429,14 +430,16 @@ func TestACME_IsAttestationFormatEnabled(t *testing.T) {
 		args   args
 		want   bool
 	}{
-		{"ok", fields{[]ACMEAttestationFormat{APPLE, STEP, TPM}}, args{ctx, TPM}, true},
+		{"ok", fields{[]ACMEAttestationFormat{APPLE, STEP, TPM, ANDROID}}, args{ctx, TPM}, true},
 		{"ok empty apple", fields{nil}, args{ctx, APPLE}, true},
 		{"ok empty step", fields{nil}, args{ctx, STEP}, true},
 		{"ok empty tpm", fields{[]ACMEAttestationFormat{}}, args{ctx, "tpm"}, true},
+		{"ok empty android", fields{[]ACMEAttestationFormat{}}, args{ctx, "android-key"}, true},
 		{"ok uppercase", fields{[]ACMEAttestationFormat{APPLE, STEP, TPM}}, args{ctx, "STEP"}, true},
 		{"fail apple", fields{[]ACMEAttestationFormat{STEP, TPM}}, args{ctx, APPLE}, false},
 		{"fail step", fields{[]ACMEAttestationFormat{APPLE, TPM}}, args{ctx, STEP}, false},
 		{"fail step", fields{[]ACMEAttestationFormat{APPLE, STEP}}, args{ctx, TPM}, false},
+		{"fail android", fields{[]ACMEAttestationFormat{APPLE, STEP}}, args{ctx, ANDROID}, false},
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {

+ 4 - 0
authority/provisioners.go

@@ -1360,6 +1360,8 @@ func attestationFormatsToCertificates(formats []linkedca.ACMEProvisioner_Attesta
 	ret := make([]provisioner.ACMEAttestationFormat, 0, len(formats))
 	for _, f := range formats {
 		switch f {
+		case 4:
+			ret = append(ret, provisioner.ANDROID)
 		case linkedca.ACMEProvisioner_APPLE:
 			ret = append(ret, provisioner.APPLE)
 		case linkedca.ACMEProvisioner_STEP:
@@ -1377,6 +1379,8 @@ func attestationFormatsToLinkedca(formats []provisioner.ACMEAttestationFormat) [
 	ret := make([]linkedca.ACMEProvisioner_AttestationFormatType, 0, len(formats))
 	for _, f := range formats {
 		switch provisioner.ACMEAttestationFormat(f.String()) {
+		case provisioner.ANDROID:
+			ret = append(ret, 4)
 		case provisioner.APPLE:
 			ret = append(ret, linkedca.ACMEProvisioner_APPLE)
 		case provisioner.STEP:

+ 1 - 0
go.mod

@@ -22,6 +22,7 @@ require (
 	github.com/hashicorp/vault/api/auth/approle v0.12.0
 	github.com/hashicorp/vault/api/auth/aws v0.12.0
 	github.com/hashicorp/vault/api/auth/kubernetes v0.12.0
+	github.com/mbreban/attestation v0.1.0
 	github.com/newrelic/go-agent/v3 v3.44.1
 	github.com/pkg/errors v0.9.1
 	github.com/prometheus/client_golang v1.24.0

+ 2 - 0
go.sum

@@ -293,6 +293,8 @@ github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Ky
 github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
 github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
 github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
+github.com/mbreban/attestation v0.1.0 h1:oNPb7tdTboEw14lXdXCAvzd2fq/W5yyVlbO+01kAb0w=
+github.com/mbreban/attestation v0.1.0/go.mod h1:YWaxLRaBYCI4+EvJIOaMtEiP/8m9XTN3u0ltPWbfZ1Y=
 github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d h1:5PJl274Y63IEHC+7izoQE9x6ikvDFZS2mDVS3drnohI=
 github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
 github.com/miekg/pkcs11 v1.1.2 h1:/VxmeAX5qU6Q3EwafypogwWbYryHFmF2RpkJmw3m4MQ=