瀏覽代碼

Add the remote-attestation identifier and remote-attest-01 challenge

This is the plumbing for draft-ietf-acme-rats-03. Validation lands in the
next commit; until then a remote-attest-01 challenge is refused.

- newOrder accepts at most one remote-attestation identifier. Its value
  is a hint of up to 128 bytes, which may be empty. The identifier is
  exempt from the name policies, since it puts nothing in the
  certificate. It is refused unless the provisioner enables
  remote-attest-01.
- With remoteAttestation.require, newOrder adds a remote-attestation
  identifier to an order that has none, as section 3.2 allows.
- Each remote-attest-01 challenge gets its own freshnessNonce (32 random
  bytes, base64url) and the provisioner's attestClaimsHint. Both are sent
  to the client and stored with the challenge.
- The ACME provisioner gets a remoteAttestation block: formats (tdx,
  sev-snp, confidential-space), claimsHint, root overrides, and the
  Confidential Space roots, audience, maximum age and expectations. Init
  builds the verifiers once, with a shared collateral cache on the
  provisioner's HTTP client.
- VerifyRemoteAttestation, which acme reaches through the Provisioner
  interface, verifies a CMW record under a 10-second timeout. It returns
  the result and the 64 bytes the evidence binds: the report data of a
  TDX quote or SEV-SNP report sent as a configfs-tsm report, or the first
  two eat_nonce values of a Confidential Space token.

The SEV-SNP test checks revocation too: sevsnptest can now sign a CRL
with its test ARK, which the provisioner's HTTP client serves.

Claude-Session: https://claude.ai/code/session_01CjfEMLGpnHQaWsmxe1zmLF
Josh Drake 1 月之前
父節點
當前提交
0ae17f4013

+ 8 - 0
acme/api/account_test.go

@@ -21,6 +21,8 @@ import (
 
 	"github.com/smallstep/assert"
 	"github.com/smallstep/certificates/acme"
+	"github.com/smallstep/certificates/attestation"
+	"github.com/smallstep/certificates/attestation/cmw"
 	"github.com/smallstep/certificates/authority/provisioner"
 )
 
@@ -56,6 +58,12 @@ func (*fakeProvisioner) GetID() string                                 { return
 func (*fakeProvisioner) GetName() string                               { return "" }
 func (*fakeProvisioner) DefaultTLSCertDuration() time.Duration         { return 0 }
 func (*fakeProvisioner) GetOptions() *provisioner.Options              { return nil }
+func (*fakeProvisioner) GetRemoteAttestation() *provisioner.ACMERemoteAttestation {
+	return nil
+}
+func (*fakeProvisioner) VerifyRemoteAttestation(context.Context, *cmw.Record, string) (*attestation.Result, []byte, error) {
+	return nil, nil, nil
+}
 
 func newProv() acme.Provisioner {
 	// Initialize provisioners

+ 61 - 0
acme/api/order.go

@@ -2,6 +2,7 @@ package api
 
 import (
 	"context"
+	"crypto/rand"
 	"crypto/x509"
 	"encoding/base64"
 	"encoding/json"
@@ -23,6 +24,10 @@ import (
 	"github.com/smallstep/certificates/authority/provisioner"
 )
 
+// maxRemoteAttestationHint is the maximum length of the value of a
+// remote-attestation identifier.
+const maxRemoteAttestationHint = 128
+
 // NewOrderRequest represents the body for a NewOrder request.
 type NewOrderRequest struct {
 	Identifiers []acme.Identifier `json:"identifiers"`
@@ -35,6 +40,7 @@ func (n *NewOrderRequest) Validate() error {
 	if len(n.Identifiers) == 0 {
 		return acme.NewError(acme.ErrorMalformedType, "identifiers list cannot be empty")
 	}
+	var remoteAttestations int
 	for _, id := range n.Identifiers {
 		switch id.Type {
 		case acme.IP:
@@ -54,6 +60,17 @@ func (n *NewOrderRequest) Validate() error {
 			// validation of Wire identifiers is performed in `validateWireIdentifiers`, but
 			// marked here as known and supported types.
 			continue
+		case acme.RemoteAttestation:
+			// The value is a hint, which may be empty.
+			if len(id.Value) > maxRemoteAttestationHint {
+				return acme.NewError(acme.ErrorMalformedType, "remote-attestation identifier value cannot be longer than %d bytes", maxRemoteAttestationHint)
+			}
+			// One attestation per order, so that finalize, the webhooks
+			// and the templates each see a single one.
+			remoteAttestations++
+			if remoteAttestations > 1 {
+				return acme.NewError(acme.ErrorMalformedType, "an order cannot have more than one remote-attestation identifier")
+			}
 		default:
 			return acme.NewError(acme.ErrorMalformedType, "identifier type unsupported: %s", id.Type)
 		}
@@ -206,6 +223,11 @@ func NewOrder(w http.ResponseWriter, r *http.Request) {
 		return
 	}
 
+	if err := addRemoteAttestationIdentifier(ctx, acmeProv, &nor); err != nil {
+		render.Error(w, r, err)
+		return
+	}
+
 	var eak *acme.ExternalAccountKey
 	if acmeProv.RequireEAB {
 		if eak, err = db.GetExternalAccountKeyByAccountID(ctx, prov.GetID(), acc.ID); err != nil {
@@ -221,6 +243,11 @@ func NewOrder(w http.ResponseWriter, r *http.Request) {
 	}
 
 	for _, identifier := range nor.Identifiers {
+		// A remote-attestation identifier names nothing in the certificate,
+		// so the name policies do not apply to it.
+		if identifier.Type == acme.RemoteAttestation {
+			continue
+		}
 		// evaluate the ACME account level policy
 		if err = isIdentifierAllowed(acmePolicy, identifier); err != nil {
 			render.Error(w, r, acme.WrapError(acme.ErrorRejectedIdentifierType, err, "not authorized"))
@@ -294,6 +321,26 @@ func NewOrder(w http.ResponseWriter, r *http.Request) {
 	render.JSONStatus(w, r, o, http.StatusCreated)
 }
 
+// addRemoteAttestationIdentifier refuses a remote-attestation identifier if the
+// provisioner does not enable remote-attest-01, and adds one with an empty hint
+// if the provisioner requires remote attestation and the order has none, as
+// draft-ietf-acme-rats-03 section 3.2 allows.
+func addRemoteAttestationIdentifier(ctx context.Context, prov *provisioner.ACME, nor *NewOrderRequest) error {
+	enabled := prov.IsChallengeEnabled(ctx, provisioner.REMOTE_ATTEST_01)
+	for _, id := range nor.Identifiers {
+		if id.Type == acme.RemoteAttestation {
+			if !enabled {
+				return acme.NewError(acme.ErrorUnsupportedIdentifierType, "remote-attestation identifiers are not supported by this provisioner")
+			}
+			return nil
+		}
+	}
+	if enabled && prov.GetRemoteAttestation().IsRequired() {
+		nor.Identifiers = append(nor.Identifiers, acme.Identifier{Type: acme.RemoteAttestation})
+	}
+	return nil
+}
+
 func isIdentifierAllowed(acmePolicy policy.X509Policy, identifier acme.Identifier) error {
 	if acmePolicy == nil {
 		return nil
@@ -378,6 +425,10 @@ func newAuthorization(ctx context.Context, az *acme.Authorization) error {
 			Status:    acme.StatusPending,
 			Target:    target,
 		}
+		if typ == acme.REMOTEATTEST01 {
+			ch.FreshnessNonce = newFreshnessNonce()
+			ch.AttestClaimsHint = prov.GetRemoteAttestation().GetClaimsHint()
+		}
 		if err := db.CreateChallenge(ctx, ch); err != nil {
 			return acme.WrapErrorISE(err, "error creating challenge")
 		}
@@ -389,6 +440,14 @@ func newAuthorization(ctx context.Context, az *acme.Authorization) error {
 	return nil
 }
 
+// newFreshnessNonce returns the freshness nonce of a remote-attest-01
+// challenge: 32 random bytes, base64url encoded without padding.
+func newFreshnessNonce() string {
+	b := make([]byte, 32)
+	_, _ = rand.Read(b) // never fails
+	return base64.RawURLEncoding.EncodeToString(b)
+}
+
 // GetOrder ACME api for retrieving an order.
 func GetOrder(w http.ResponseWriter, r *http.Request) {
 	ctx := r.Context()
@@ -512,6 +571,8 @@ func challengeTypes(az *acme.Authorization) []acme.ChallengeType {
 		chTypes = []acme.ChallengeType{acme.WIREOIDC01}
 	case acme.WireDevice:
 		chTypes = []acme.ChallengeType{acme.WIREDPOP01}
+	case acme.RemoteAttestation:
+		chTypes = []acme.ChallengeType{acme.REMOTEATTEST01}
 	default:
 		chTypes = []acme.ChallengeType{}
 	}

+ 141 - 0
acme/api/order_remote_attestation_test.go

@@ -0,0 +1,141 @@
+package api
+
+import (
+	"context"
+	"encoding/base64"
+	"strings"
+	"testing"
+
+	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/require"
+
+	"github.com/smallstep/certificates/acme"
+	"github.com/smallstep/certificates/authority/provisioner"
+)
+
+func newRemoteAttestationProv(t *testing.T, challenges []provisioner.ACMEChallenge, o *provisioner.ACMERemoteAttestation) *provisioner.ACME {
+	t.Helper()
+	p := &provisioner.ACME{
+		Type:              "ACME",
+		Name:              "attested",
+		Challenges:        challenges,
+		RemoteAttestation: o,
+	}
+	require.NoError(t, p.Init(provisioner.Config{Claims: globalProvisionerClaims}))
+	return p
+}
+
+func TestNewOrderRequest_Validate_remoteAttestation(t *testing.T) {
+	tests := []struct {
+		name    string
+		ids     []acme.Identifier
+		wantErr string
+	}{
+		{"ok empty hint", []acme.Identifier{{Type: acme.RemoteAttestation}}, ""},
+		{"ok with dns", []acme.Identifier{{Type: acme.DNS, Value: "example.com"}, {Type: acme.RemoteAttestation, Value: "measured_boot"}}, ""},
+		{"ok longest hint", []acme.Identifier{{Type: acme.RemoteAttestation, Value: strings.Repeat("a", maxRemoteAttestationHint)}}, ""},
+		{"fail hint too long", []acme.Identifier{{Type: acme.RemoteAttestation, Value: strings.Repeat("a", maxRemoteAttestationHint+1)}},
+			"remote-attestation identifier value cannot be longer than 128 bytes"},
+		{"fail two", []acme.Identifier{{Type: acme.RemoteAttestation}, {Type: acme.RemoteAttestation, Value: "hsm"}},
+			"an order cannot have more than one remote-attestation identifier"},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			err := (&NewOrderRequest{Identifiers: tt.ids}).Validate()
+			if tt.wantErr == "" {
+				assert.NoError(t, err)
+				return
+			}
+			var acmeErr *acme.Error
+			require.ErrorAs(t, err, &acmeErr)
+			assert.Equal(t, acme.NewError(acme.ErrorMalformedType, "").Type, acmeErr.Type)
+			assert.ErrorContains(t, err, tt.wantErr)
+		})
+	}
+}
+
+func TestAddRemoteAttestationIdentifier(t *testing.T) {
+	enabled := []provisioner.ACMEChallenge{provisioner.DNS_01, provisioner.REMOTE_ATTEST_01}
+	dns := acme.Identifier{Type: acme.DNS, Value: "example.com"}
+	ra := acme.Identifier{Type: acme.RemoteAttestation, Value: "hsm"}
+
+	tests := []struct {
+		name    string
+		prov    *provisioner.ACME
+		ids     []acme.Identifier
+		want    []acme.Identifier
+		wantErr bool
+	}{
+		{"ok not required", newRemoteAttestationProv(t, enabled, nil), []acme.Identifier{dns}, []acme.Identifier{dns}, false},
+		{"ok required", newRemoteAttestationProv(t, enabled, &provisioner.ACMERemoteAttestation{Require: true}),
+			[]acme.Identifier{dns}, []acme.Identifier{dns, {Type: acme.RemoteAttestation}}, false},
+		{"ok required and present", newRemoteAttestationProv(t, enabled, &provisioner.ACMERemoteAttestation{Require: true}),
+			[]acme.Identifier{ra, dns}, []acme.Identifier{ra, dns}, false},
+		{"ok required but not enabled", newRemoteAttestationProv(t, nil, &provisioner.ACMERemoteAttestation{Require: true}),
+			[]acme.Identifier{dns}, []acme.Identifier{dns}, false},
+		{"fail not enabled", newRemoteAttestationProv(t, nil, nil), []acme.Identifier{dns, ra}, nil, true},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			nor := &NewOrderRequest{Identifiers: tt.ids}
+			err := addRemoteAttestationIdentifier(context.Background(), tt.prov, nor)
+			if tt.wantErr {
+				var acmeErr *acme.Error
+				require.ErrorAs(t, err, &acmeErr)
+				assert.Equal(t, acme.NewError(acme.ErrorUnsupportedIdentifierType, "").Type, acmeErr.Type)
+				return
+			}
+			require.NoError(t, err)
+			assert.Equal(t, tt.want, nor.Identifiers)
+		})
+	}
+}
+
+func TestChallengeTypes_remoteAttestation(t *testing.T) {
+	got := challengeTypes(&acme.Authorization{Identifier: acme.Identifier{Type: acme.RemoteAttestation}})
+	assert.Equal(t, []acme.ChallengeType{acme.REMOTEATTEST01}, got)
+}
+
+func TestNewAuthorization_remoteAttestation(t *testing.T) {
+	prov := newRemoteAttestationProv(t, []provisioner.ACMEChallenge{provisioner.REMOTE_ATTEST_01}, &provisioner.ACMERemoteAttestation{
+		ClaimsHint: []string{"hwmodel", "swversion"},
+	})
+	var created []*acme.Challenge
+	db := &acme.MockDB{
+		MockCreateChallenge: func(_ context.Context, ch *acme.Challenge) error {
+			ch.ID = "chID"
+			created = append(created, ch)
+			return nil
+		},
+		MockCreateAuthorization: func(_ context.Context, az *acme.Authorization) error {
+			az.ID = "azID"
+			return nil
+		},
+	}
+	ctx := acme.NewProvisionerContext(context.Background(), prov)
+	ctx = acme.NewDatabaseContext(ctx, db)
+
+	az := &acme.Authorization{
+		AccountID:  "accID",
+		Identifier: acme.Identifier{Type: acme.RemoteAttestation, Value: "measured_boot"},
+		Status:     acme.StatusPending,
+	}
+	require.NoError(t, newAuthorization(ctx, az))
+	require.Len(t, created, 1)
+	ch := created[0]
+	assert.Equal(t, acme.REMOTEATTEST01, ch.Type)
+	assert.Equal(t, "measured_boot", ch.Value)
+	assert.Equal(t, []string{"hwmodel", "swversion"}, ch.AttestClaimsHint)
+	nonce, err := base64.RawURLEncoding.DecodeString(ch.FreshnessNonce)
+	require.NoError(t, err)
+	assert.Len(t, nonce, 32)
+	assert.Equal(t, []*acme.Challenge{ch}, az.Challenges)
+
+	// Each challenge gets its own nonce.
+	require.NoError(t, newAuthorization(ctx, &acme.Authorization{
+		AccountID:  "accID",
+		Identifier: acme.Identifier{Type: acme.RemoteAttestation},
+	}))
+	require.Len(t, created, 2)
+	assert.NotEqual(t, created[0].FreshnessNonce, created[1].FreshnessNonce)
+}

+ 14 - 3
acme/challenge.go

@@ -60,6 +60,9 @@ const (
 	WIREOIDC01 ChallengeType = "wire-oidc-01"
 	// WIREDPOP01 is the Wire DPoP challenge type
 	WIREDPOP01 ChallengeType = "wire-dpop-01"
+	// REMOTEATTEST01 is the remote-attest-01 ACME challenge type defined in
+	// https://datatracker.ietf.org/doc/html/draft-ietf-acme-rats-03
+	REMOTEATTEST01 ChallengeType = "remote-attest-01"
 )
 
 var (
@@ -91,9 +94,15 @@ type Challenge struct {
 	ValidatedAt     string        `json:"validated,omitempty"`
 	URL             string        `json:"url"`
 	Target          string        `json:"target,omitempty"`
-	Error           *Error        `json:"error,omitempty"`
-	Payload         []byte        `json:"-"`
-	PayloadFormat   string        `json:"-"`
+	// FreshnessNonce is the nonce the evidence of a remote-attest-01
+	// challenge must include, through its key authorization.
+	FreshnessNonce string `json:"freshnessNonce,omitempty"`
+	// AttestClaimsHint names the claims a remote-attest-01 challenge asks
+	// for.
+	AttestClaimsHint []string `json:"attestClaimsHint,omitempty"`
+	Error            *Error   `json:"error,omitempty"`
+	Payload          []byte   `json:"-"`
+	PayloadFormat    string   `json:"-"`
 }
 
 // ToLog enables response logging.
@@ -134,6 +143,8 @@ func (ch *Challenge) Validate(ctx context.Context, db DB, jwk *jose.JSONWebKey,
 			return NewErrorISE("db %T is not a WireDB", db)
 		}
 		return wireDPOP01Validate(ctx, ch, wireDB, jwk, payload)
+	case REMOTEATTEST01:
+		return NewError(ErrorMalformedType, "remote-attest-01 is not implemented yet")
 	default:
 		return NewErrorISE("unexpected challenge type %q", ch.Type)
 	}

+ 22 - 0
acme/common.go

@@ -5,6 +5,8 @@ import (
 	"crypto/x509"
 	"time"
 
+	"github.com/smallstep/certificates/attestation"
+	"github.com/smallstep/certificates/attestation/cmw"
 	"github.com/smallstep/certificates/authority"
 	"github.com/smallstep/certificates/authority/provisioner"
 )
@@ -79,6 +81,8 @@ type Provisioner interface {
 	GetName() string
 	DefaultTLSCertDuration() time.Duration
 	GetOptions() *provisioner.Options
+	GetRemoteAttestation() *provisioner.ACMERemoteAttestation
+	VerifyRemoteAttestation(ctx context.Context, record *cmw.Record, defaultAudience string) (*attestation.Result, []byte, error)
 }
 
 type provisionerKey struct{}
@@ -121,6 +125,8 @@ type MockProvisioner struct {
 	MgetAttestationRoots      func() (*x509.CertPool, bool)
 	MdefaultTLSCertDuration   func() time.Duration
 	MgetOptions               func() *provisioner.Options
+	MgetRemoteAttestation     func() *provisioner.ACMERemoteAttestation
+	MverifyRemoteAttestation  func(ctx context.Context, record *cmw.Record, defaultAudience string) (*attestation.Result, []byte, error)
 }
 
 // GetName mock
@@ -194,6 +200,22 @@ func (m *MockProvisioner) GetOptions() *provisioner.Options {
 	return m.Mret1.(*provisioner.Options)
 }
 
+// GetRemoteAttestation mock
+func (m *MockProvisioner) GetRemoteAttestation() *provisioner.ACMERemoteAttestation {
+	if m.MgetRemoteAttestation != nil {
+		return m.MgetRemoteAttestation()
+	}
+	return nil
+}
+
+// VerifyRemoteAttestation mock
+func (m *MockProvisioner) VerifyRemoteAttestation(ctx context.Context, record *cmw.Record, defaultAudience string) (*attestation.Result, []byte, error) {
+	if m.MverifyRemoteAttestation != nil {
+		return m.MverifyRemoteAttestation(ctx, record, defaultAudience)
+	}
+	return nil, nil, m.Merr
+}
+
 // GetID mock
 func (m *MockProvisioner) GetID() string {
 	if m.MgetID != nil {

+ 10 - 0
acme/db/nosql/challenge.go

@@ -23,6 +23,10 @@ type dbChallenge struct {
 	ValidatedAt string             `json:"validatedAt"`
 	CreatedAt   time.Time          `json:"createdAt"`
 	Error       *acme.Error        `json:"error"` // TODO(hs): a bit dangerous; should become db-specific type
+	// FreshnessNonce and AttestClaimsHint are set on remote-attest-01
+	// challenges.
+	FreshnessNonce   string   `json:"freshnessNonce,omitempty"`
+	AttestClaimsHint []string `json:"attestClaimsHint,omitempty"`
 }
 
 func (dbc *dbChallenge) clone() *dbChallenge {
@@ -63,6 +67,9 @@ func (db *DB) CreateChallenge(ctx context.Context, ch *acme.Challenge) error {
 		CreatedAt: clock.Now(),
 		Type:      ch.Type,
 		Target:    ch.Target,
+
+		FreshnessNonce:   ch.FreshnessNonce,
+		AttestClaimsHint: ch.AttestClaimsHint,
 	}
 
 	return db.save(ctx, ch.ID, dbch, nil, "challenge", challengeTable)
@@ -87,6 +94,9 @@ func (db *DB) GetChallenge(ctx context.Context, id, authzID string) (*acme.Chall
 		Error:       dbch.Error,
 		ValidatedAt: dbch.ValidatedAt,
 		Target:      dbch.Target,
+
+		FreshnessNonce:   dbch.FreshnessNonce,
+		AttestClaimsHint: dbch.AttestClaimsHint,
 	}
 	return ch, nil
 }

+ 50 - 0
acme/db/nosql/challenge_remote_attestation_test.go

@@ -0,0 +1,50 @@
+package nosql
+
+import (
+	"context"
+	"testing"
+
+	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/require"
+
+	"github.com/smallstep/certificates/acme"
+	"github.com/smallstep/certificates/db"
+)
+
+// TestDB_Challenge_remoteAttestation checks that the fields of a
+// remote-attest-01 challenge are stored and read back.
+func TestDB_Challenge_remoteAttestation(t *testing.T) {
+	var stored []byte
+	d := DB{db: &db.MockNoSQLDB{
+		MCmpAndSwap: func(_, _, _, nu []byte) ([]byte, bool, error) {
+			stored = nu
+			return nu, true, nil
+		},
+		MGet: func(bucket, key []byte) ([]byte, error) {
+			assert.Equal(t, challengeTable, bucket)
+			return stored, nil
+		},
+	}}
+
+	ch := &acme.Challenge{
+		AccountID:        "accountID",
+		Type:             acme.REMOTEATTEST01,
+		Status:           acme.StatusPending,
+		Token:            "token",
+		FreshnessNonce:   "yoW1RL2zPBzYEHBQ06Jy",
+		AttestClaimsHint: []string{"hwmodel", "swversion"},
+	}
+	require.NoError(t, d.CreateChallenge(context.Background(), ch))
+	assert.Contains(t, string(stored), `"freshnessNonce":"yoW1RL2zPBzYEHBQ06Jy"`)
+
+	got, err := d.GetChallenge(context.Background(), ch.ID, "azID")
+	require.NoError(t, err)
+	assert.Equal(t, acme.REMOTEATTEST01, got.Type)
+	assert.Equal(t, ch.FreshnessNonce, got.FreshnessNonce)
+	assert.Equal(t, ch.AttestClaimsHint, got.AttestClaimsHint)
+
+	// Other challenges store neither field.
+	require.NoError(t, d.CreateChallenge(context.Background(), &acme.Challenge{Type: acme.DNS01, Token: "token"}))
+	assert.NotContains(t, string(stored), "freshnessNonce")
+	assert.NotContains(t, string(stored), "attestClaimsHint")
+}

+ 5 - 0
acme/order.go

@@ -37,6 +37,11 @@ const (
 	WireUser IdentifierType = "wireapp-user"
 	// WireDevice is the Wire device identifier type
 	WireDevice IdentifierType = "wireapp-device"
+	// RemoteAttestation is the remote-attestation identifier type defined in
+	// https://datatracker.ietf.org/doc/html/draft-ietf-acme-rats-03. Its
+	// value is a hint of the attestation asked for, and it puts nothing in
+	// the certificate.
+	RemoteAttestation IdentifierType = "remote-attestation"
 )
 
 // Identifier encodes the type that an order pertains to.

+ 22 - 0
attestation/sevsnp/sevsnptest/sevsnptest.go

@@ -14,6 +14,7 @@ import (
 	"crypto/x509"
 	"encoding/binary"
 	"encoding/pem"
+	"math/big"
 	"testing"
 	"time"
 
@@ -103,6 +104,27 @@ func (s *Signer) Report(t testing.TB, reportData []byte, debug bool) []byte {
 	return report
 }
 
+// CRL returns a revocation list, signed by the signer's ARK, that revokes
+// nothing, and the URL go-sev-guest fetches it from when it checks
+// revocations.
+func (s *Signer) CRL(t testing.TB) (url string, crl []byte) {
+	t.Helper()
+	if len(s.signer.Ask.CRLDistributionPoints) == 0 {
+		t.Fatal("the test ASK has no CRL distribution point")
+	}
+	now := time.Now()
+	crl, err := x509.CreateRevocationList(rand.Reader, &x509.RevocationList{
+		Number:             big.NewInt(1),
+		ThisUpdate:         now.Add(-time.Hour),
+		NextUpdate:         now.Add(time.Hour),
+		SignatureAlgorithm: x509.SHA384WithRSAPSS,
+	}, s.signer.Ark, s.signer.Keys.Ark)
+	if err != nil {
+		t.Fatal(err)
+	}
+	return s.signer.Ask.CRLDistributionPoints[0], crl
+}
+
 func pemEncode(certs ...*x509.Certificate) []byte {
 	var out []byte
 	for _, c := range certs {

+ 31 - 8
authority/provisioner/acme.go

@@ -37,6 +37,9 @@ const (
 	WIREOIDC_01 ACMEChallenge = "wire-oidc-01"
 	// WIREDPOP_01 is the Wire DPoP challenge.
 	WIREDPOP_01 ACMEChallenge = "wire-dpop-01"
+	// REMOTE_ATTEST_01 is the remote-attest-01 ACME challenge
+	// (draft-ietf-acme-rats).
+	REMOTE_ATTEST_01 ACMEChallenge = "remote-attest-01"
 )
 
 // String returns a normalized version of the challenge.
@@ -47,7 +50,7 @@ func (c ACMEChallenge) String() string {
 // Validate returns an error if the acme challenge is not a valid one.
 func (c ACMEChallenge) Validate() error {
 	switch ACMEChallenge(c.String()) {
-	case HTTP_01, DNS_01, TLS_ALPN_01, DEVICE_ATTEST_01, WIREOIDC_01, WIREDPOP_01:
+	case HTTP_01, DNS_01, TLS_ALPN_01, DEVICE_ATTEST_01, WIREOIDC_01, WIREDPOP_01, REMOTE_ATTEST_01:
 		return nil
 	default:
 		return fmt.Errorf("acme challenge %q is not supported", c)
@@ -116,8 +119,8 @@ type ACME struct {
 	RequireEAB bool `json:"requireEAB,omitempty"`
 	// Challenges contains the enabled challenges for this provisioner. If this
 	// value is not set the default http-01, dns-01 and tls-alpn-01 challenges
-	// will be enabled, device-attest-01, wire-oidc-01 and wire-dpop-01 will be
-	// disabled.
+	// will be enabled, device-attest-01, wire-oidc-01, wire-dpop-01 and
+	// remote-attest-01 will be disabled.
 	Challenges []ACMEChallenge `json:"challenges,omitempty"`
 	// AttestationFormats contains the enabled attestation formats for this
 	// provisioner. If this value is not set the default apple, step and tpm
@@ -126,11 +129,15 @@ type ACME struct {
 	// AttestationRoots contains a bundle of root certificates in PEM format
 	// that will be used to verify the attestation certificates. If provided,
 	// this bundle will be used even for well-known CAs like Apple and Yubico.
-	AttestationRoots    []byte   `json:"attestationRoots,omitempty"`
-	Claims              *Claims  `json:"claims,omitempty"`
-	Options             *Options `json:"options,omitempty"`
+	AttestationRoots []byte `json:"attestationRoots,omitempty"`
+	// RemoteAttestation configures the remote-attest-01 challenge, if it is
+	// enabled.
+	RemoteAttestation   *ACMERemoteAttestation `json:"remoteAttestation,omitempty"`
+	Claims              *Claims                `json:"claims,omitempty"`
+	Options             *Options               `json:"options,omitempty"`
 	androidCRL          *androidCRLCache
 	attestationRootPool *x509.CertPool
+	remoteAttestation   *remoteAttestationVerifier
 	ctl                 *Controller
 }
 
@@ -252,8 +259,14 @@ func (p *ACME) Init(config Config) (err error) {
 
 	p.androidCRL = &androidCRLCache{}
 
-	p.ctl, err = NewController(p, p.Claims, config, p.Options)
-	return
+	if p.ctl, err = NewController(p, p.Claims, config, p.Options); err != nil {
+		return err
+	}
+
+	if err := p.initializeRemoteAttestation(); err != nil {
+		return fmt.Errorf("failed initializing remote attestation: %w", err)
+	}
+	return nil
 }
 
 const (
@@ -381,6 +394,10 @@ const (
 	WireUser ACMEIdentifierType = "wireapp-user"
 	// WireDevice is the Wire device identifier type
 	WireDevice ACMEIdentifierType = "wireapp-device"
+	// RemoteAttestation is the remote-attestation identifier type
+	// (draft-ietf-acme-rats). Its value is a hint of the attestation asked
+	// for, and it puts nothing in the certificate.
+	RemoteAttestation ACMEIdentifierType = "remote-attestation"
 )
 
 // ACMEIdentifier encodes ACME Order Identifiers
@@ -392,6 +409,12 @@ type ACMEIdentifier struct {
 // AuthorizeOrderIdentifier verifies the provisioner is allowed to issue a
 // certificate for an ACME Order Identifier.
 func (p *ACME) AuthorizeOrderIdentifier(_ context.Context, identifier ACMEIdentifier) error {
+	// A remote-attestation identifier names nothing in the certificate, so
+	// no name policy applies to it.
+	if identifier.Type == RemoteAttestation {
+		return nil
+	}
+
 	x509Policy := p.ctl.getPolicy().getX509()
 
 	// identifier is allowed if no policy is configured

+ 309 - 0
authority/provisioner/acme_remote_attestation.go

@@ -0,0 +1,309 @@
+package provisioner
+
+import (
+	"context"
+	"crypto/sha256"
+	"crypto/x509"
+	"encoding/base64"
+	"errors"
+	"fmt"
+	"mime"
+	"slices"
+	"time"
+
+	"github.com/smallstep/certificates/attestation"
+	"github.com/smallstep/certificates/attestation/cmw"
+	"github.com/smallstep/certificates/attestation/collateral"
+	"github.com/smallstep/certificates/attestation/confidentialspace"
+	"github.com/smallstep/certificates/attestation/sevsnp"
+	"github.com/smallstep/certificates/attestation/tdx"
+	"github.com/smallstep/certificates/attestation/tsm"
+)
+
+// RemoteAttestationBoundSize is the size of the data the evidence of a
+// remote-attest-01 challenge binds: the SHA-256 digest of the challenge's key
+// authorization followed by the SHA-256 digest of the DER SubjectPublicKeyInfo
+// of the key to be certified.
+const RemoteAttestationBoundSize = 2 * sha256.Size
+
+// remoteAttestationTimeout bounds the verification of the evidence of a
+// remote-attest-01 challenge, which may fetch collateral from Intel's and AMD's
+// services.
+const remoteAttestationTimeout = 10 * time.Second
+
+// ACMERemoteAttestation configures the remote-attest-01 challenge of an ACME
+// provisioner (draft-ietf-acme-rats). The challenge is enabled through the
+// provisioner's challenges; this configures it.
+type ACMERemoteAttestation struct {
+	// Require adds a remote-attestation identifier to every order that does
+	// not have one, so that every certificate needs attestation.
+	Require bool `json:"require,omitempty"`
+	// Formats are the evidence formats accepted: tdx, sev-snp and
+	// confidential-space. It defaults to tdx and sev-snp, and to
+	// confidential-space too if ConfidentialSpace is set.
+	Formats []attestation.Format `json:"formats,omitempty"`
+	// ClaimsHint is sent to clients as the challenge's attestClaimsHint.
+	ClaimsHint []string `json:"claimsHint,omitempty"`
+	// TDXRoots is a PEM bundle that replaces Intel's SGX root CA.
+	TDXRoots []byte `json:"tdxRoots,omitempty"`
+	// SEVSNPRoots is a PEM bundle of ARK, ASK and ASVK certificates that
+	// replaces AMD's.
+	SEVSNPRoots []byte `json:"sevSnpRoots,omitempty"`
+	// ConfidentialSpace configures the confidential-space format.
+	ConfidentialSpace *ACMEConfidentialSpace `json:"confidentialSpace,omitempty"`
+}
+
+// ACMEConfidentialSpace configures the confidential-space format of the
+// remote-attest-01 challenge, which accepts the PKI tokens Google Cloud
+// Attestation issues to Confidential Space workloads.
+type ACMEConfidentialSpace struct {
+	// Roots is a PEM bundle with the roots of Google Cloud Attestation's
+	// PKI. It is required.
+	Roots []byte `json:"roots,omitempty"`
+	// Audience is the audience the token must have been requested for. It
+	// defaults to the ACME directory URL.
+	Audience string `json:"audience,omitempty"`
+	// MaxTokenAge is the maximum age of the token. It defaults to 5 minutes.
+	MaxTokenAge *Duration `json:"maxTokenAge,omitempty"`
+	// Expectations are the values the attested workload must match.
+	confidentialspace.Expectations
+}
+
+// IsRequired reports whether every order needs a remote-attestation
+// identifier.
+func (o *ACMERemoteAttestation) IsRequired() bool {
+	return o != nil && o.Require
+}
+
+// GetClaimsHint returns the claims hint sent to clients.
+func (o *ACMERemoteAttestation) GetClaimsHint() []string {
+	if o == nil {
+		return nil
+	}
+	return o.ClaimsHint
+}
+
+// remoteAttestationVerifier verifies the evidence of remote-attest-01
+// challenges with the provisioner's configuration.
+type remoteAttestationVerifier struct {
+	formats     []attestation.Format
+	tdx         *tdx.Verifier
+	sevsnp      *sevsnp.Verifier
+	csRoots     *x509.CertPool
+	csAudience  string
+	csMaxAge    time.Duration
+	csExpecting *confidentialspace.Expectations
+	now         func() time.Time
+}
+
+// initializeRemoteAttestation validates the remote attestation options and
+// creates the verifiers. It returns early if remote-attest-01 is not enabled.
+func (p *ACME) initializeRemoteAttestation() error {
+	if !slices.ContainsFunc(p.Challenges, func(c ACMEChallenge) bool {
+		return ACMEChallenge(c.String()) == REMOTE_ATTEST_01
+	}) {
+		return nil
+	}
+
+	o := p.RemoteAttestation
+	if o == nil {
+		o = &ACMERemoteAttestation{}
+	}
+	if slices.Contains(o.ClaimsHint, "") {
+		return errors.New("claimsHint cannot contain empty values")
+	}
+
+	v := &remoteAttestationVerifier{
+		formats: o.Formats,
+		now:     time.Now,
+	}
+	if len(v.formats) == 0 {
+		v.formats = []attestation.Format{attestation.FormatTDX, attestation.FormatSEVSNP}
+		if o.ConfidentialSpace != nil {
+			v.formats = append(v.formats, attestation.FormatConfidentialSpace)
+		}
+	}
+
+	getter := collateral.New(p.ctl.GetHTTPClient())
+	for _, f := range v.formats {
+		if err := f.Validate(); err != nil {
+			return err
+		}
+		var err error
+		switch f {
+		case attestation.FormatTDX:
+			v.tdx, err = tdx.New(o.TDXRoots, collateral.TDX{Getter: getter})
+		case attestation.FormatSEVSNP:
+			v.sevsnp, err = sevsnp.New(o.SEVSNPRoots, collateral.SEVSNP{Getter: getter})
+		case attestation.FormatConfidentialSpace:
+			err = v.initializeConfidentialSpace(o.ConfidentialSpace)
+		}
+		if err != nil {
+			return fmt.Errorf("error initializing the %s format: %w", f, err)
+		}
+	}
+
+	p.remoteAttestation = v
+	return nil
+}
+
+func (v *remoteAttestationVerifier) initializeConfidentialSpace(o *ACMEConfidentialSpace) error {
+	if o == nil || len(o.Roots) == 0 {
+		return errors.New("confidentialSpace.roots is required")
+	}
+	v.csRoots = x509.NewCertPool()
+	if !v.csRoots.AppendCertsFromPEM(o.Roots) {
+		return errors.New("no certificates found in confidentialSpace.roots")
+	}
+	if o.MaxTokenAge != nil {
+		if o.MaxTokenAge.Duration <= 0 {
+			return errors.New("confidentialSpace.maxTokenAge must be greater than 0")
+		}
+		v.csMaxAge = o.MaxTokenAge.Duration
+	}
+	if err := o.Expectations.Validate(); err != nil {
+		return fmt.Errorf("confidentialSpace: %w", err)
+	}
+	v.csAudience = o.Audience
+	v.csExpecting = &o.Expectations
+	return nil
+}
+
+// GetRemoteAttestation returns the remote attestation options.
+func (p *ACME) GetRemoteAttestation() *ACMERemoteAttestation {
+	return p.RemoteAttestation
+}
+
+// VerifyRemoteAttestation verifies the evidence of a remote-attest-01
+// challenge, a CMW record, and returns it with the RemoteAttestationBoundSize
+// bytes it binds:
+//
+//   - For a TDX quote or an SEV-SNP report, sent as a configfs-tsm report
+//     (application/vnd.veraison.tsm-report+json or +cbor), its report data.
+//   - For a Confidential Space token (application/eat+jwt or application/jwt),
+//     its first two eat_nonce values, each the base64url encoding, without
+//     padding, of 32 bytes. The token must have been requested for the
+//     configured audience, or else for the given default audience.
+//
+// The caller checks what the bound data must be. Errors of the evidence match
+// attestation.ErrInvalidEvidence.
+func (p *ACME) VerifyRemoteAttestation(ctx context.Context, r *cmw.Record, defaultAudience string) (*attestation.Result, []byte, error) {
+	v := p.remoteAttestation
+	if v == nil {
+		return nil, nil, errors.New("remote-attest-01 is not enabled")
+	}
+	ctx, cancel := context.WithTimeout(ctx, remoteAttestationTimeout)
+	defer cancel()
+
+	var (
+		res   *attestation.Result
+		bound []byte
+		err   error
+	)
+	switch {
+	case tsm.IsMediaType(r.MediaType):
+		res, bound, err = v.verifyTSMReport(ctx, r)
+	case isJWTMediaType(r.MediaType):
+		res, bound, err = v.verifyConfidentialSpace(r, defaultAudience)
+	default:
+		return nil, nil, attestation.Invalidf("evidence media type %q is not supported", r.MediaType)
+	}
+	if err != nil {
+		return nil, nil, err
+	}
+	if len(bound) != RemoteAttestationBoundSize {
+		return nil, nil, attestation.Invalidf("evidence binds %d bytes, not %d", len(bound), RemoteAttestationBoundSize)
+	}
+	res.MediaType = r.MediaType
+	res.Evidence = r.Value
+	return res, bound, nil
+}
+
+func (v *remoteAttestationVerifier) enabled(f attestation.Format) error {
+	if !slices.Contains(v.formats, f) {
+		return attestation.Invalidf("attestation format %s is not enabled", f)
+	}
+	return nil
+}
+
+func (v *remoteAttestationVerifier) verifyTSMReport(ctx context.Context, r *cmw.Record) (*attestation.Result, []byte, error) {
+	if r.Indicator != 0 && !r.Indicator.Has(cmw.Evidence) {
+		return nil, nil, attestation.Invalidf("a tsm report must be indicated as evidence")
+	}
+	report, err := tsm.Parse(r.MediaType, r.Value)
+	if err != nil {
+		return nil, nil, err
+	}
+
+	switch report.Provider {
+	case tsm.ProviderTDX:
+		if err := v.enabled(attestation.FormatTDX); err != nil {
+			return nil, nil, err
+		}
+		if len(report.AuxBlob) > 0 {
+			return nil, nil, attestation.Invalidf("a tdx tsm report does not take an auxblob")
+		}
+		res, reportData, err := v.tdx.Verify(ctx, report.OutBlob)
+		if err != nil {
+			return nil, nil, err
+		}
+		return &attestation.Result{Format: attestation.FormatTDX, TDX: res}, reportData, nil
+	case tsm.ProviderSEVSNP:
+		if err := v.enabled(attestation.FormatSEVSNP); err != nil {
+			return nil, nil, err
+		}
+		res, reportData, err := v.sevsnp.Verify(ctx, report.OutBlob, report.AuxBlob)
+		if err != nil {
+			return nil, nil, err
+		}
+		return &attestation.Result{Format: attestation.FormatSEVSNP, SEVSNP: res}, reportData, nil
+	default:
+		return nil, nil, attestation.Invalidf("tsm report provider %q is not supported", report.Provider)
+	}
+}
+
+func (v *remoteAttestationVerifier) verifyConfidentialSpace(r *cmw.Record, defaultAudience string) (*attestation.Result, []byte, error) {
+	if err := v.enabled(attestation.FormatConfidentialSpace); err != nil {
+		return nil, nil, err
+	}
+	if r.Indicator != 0 && !r.Indicator.Has(cmw.AttestationResults) {
+		return nil, nil, attestation.Invalidf("an attestation token must be indicated as an attestation result")
+	}
+	audience := v.csAudience
+	if audience == "" {
+		audience = defaultAudience
+	}
+	tok, err := confidentialspace.Verify(string(r.Value), confidentialspace.Options{
+		Roots:       v.csRoots,
+		Audience:    audience,
+		MaxTokenAge: v.csMaxAge,
+		MinNonces:   2,
+		Now:         v.now(),
+	})
+	if err != nil {
+		return nil, nil, err
+	}
+	if err := v.csExpecting.Check(&tok.Claims); err != nil {
+		return nil, nil, err
+	}
+
+	bound := make([]byte, 0, RemoteAttestationBoundSize)
+	for i, nonce := range tok.Claims.EATNonce[:2] {
+		b, err := base64.RawURLEncoding.DecodeString(nonce)
+		if err != nil || len(b) != sha256.Size {
+			return nil, nil, attestation.Invalidf("eat_nonce[%d] is not the base64url encoding of %d bytes", i, sha256.Size)
+		}
+		bound = append(bound, b...)
+	}
+	return &attestation.Result{
+		Format:            attestation.FormatConfidentialSpace,
+		ConfidentialSpace: tok.Result(),
+	}, bound, nil
+}
+
+// isJWTMediaType reports whether mediaType is application/jwt or
+// application/eat+jwt, with or without parameters.
+func isJWTMediaType(mediaType string) bool {
+	mt, _, err := mime.ParseMediaType(mediaType)
+	return err == nil && (mt == "application/jwt" || mt == "application/eat+jwt")
+}

+ 293 - 0
authority/provisioner/acme_remote_attestation_test.go

@@ -0,0 +1,293 @@
+package provisioner
+
+import (
+	"bytes"
+	"context"
+	"crypto/sha256"
+	"encoding/base64"
+	"errors"
+	"io"
+	"net/http"
+	"strings"
+	"testing"
+	"time"
+
+	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/require"
+
+	"github.com/smallstep/certificates/attestation"
+	"github.com/smallstep/certificates/attestation/cmw"
+	"github.com/smallstep/certificates/attestation/confidentialspace"
+	cstest "github.com/smallstep/certificates/attestation/confidentialspace/confidentialspacetest"
+	"github.com/smallstep/certificates/authority/policy"
+)
+
+const testRemoteAttestationAudience = "https://ca.example.com/acme/attested/directory"
+
+// staticHTTPClient serves fixed responses by URL and fails any other request,
+// so that a test fails instead of reaching a vendor's service.
+type staticHTTPClient map[string][]byte
+
+func (c staticHTTPClient) Do(req *http.Request) (*http.Response, error) {
+	body, ok := c[req.URL.String()]
+	if !ok {
+		return nil, errors.New("unexpected request to " + req.URL.String())
+	}
+	return &http.Response{
+		StatusCode: http.StatusOK,
+		Header:     http.Header{},
+		Body:       io.NopCloser(bytes.NewReader(body)),
+	}, nil
+}
+
+func (c staticHTTPClient) Get(url string) (*http.Response, error) {
+	req, err := http.NewRequest(http.MethodGet, url, http.NoBody)
+	if err != nil {
+		return nil, err
+	}
+	return c.Do(req)
+}
+
+func newRemoteAttestationACME(t *testing.T, o *ACMERemoteAttestation, client HTTPClient) *ACME {
+	t.Helper()
+	p := &ACME{
+		Type:              "ACME",
+		Name:              "attested",
+		Challenges:        []ACMEChallenge{REMOTE_ATTEST_01},
+		RemoteAttestation: o,
+	}
+	require.NoError(t, p.Init(Config{Claims: globalProvisionerClaims, HTTPClient: client}))
+	return p
+}
+
+// testBound returns the data a client binds to its evidence, 32 bytes for
+// the key authorization's digest and 32 for the key's.
+func testBound() []byte {
+	ka := sha256.Sum256([]byte("token.thumbprint"))
+	key := sha256.Sum256([]byte("spki"))
+	return append(ka[:], key[:]...)
+}
+
+func jsonCMW(mediaType string, value []byte, ind cmw.Indicator) *cmw.Record {
+	return &cmw.Record{MediaType: mediaType, Value: value, Indicator: ind}
+}
+
+func TestACME_Init_remoteAttestation(t *testing.T) {
+	pki := cstest.New(t)
+	tests := []struct {
+		name        string
+		challenges  []ACMEChallenge
+		o           *ACMERemoteAttestation
+		wantFormats []attestation.Format
+		wantErr     string
+	}{
+		{"ok defaults", []ACMEChallenge{REMOTE_ATTEST_01}, nil,
+			[]attestation.Format{attestation.FormatTDX, attestation.FormatSEVSNP}, ""},
+		{"ok uppercase challenge", []ACMEChallenge{"REMOTE-ATTEST-01"}, nil,
+			[]attestation.Format{attestation.FormatTDX, attestation.FormatSEVSNP}, ""},
+		{"ok confidential space by default", []ACMEChallenge{REMOTE_ATTEST_01},
+			&ACMERemoteAttestation{ConfidentialSpace: &ACMEConfidentialSpace{Roots: pki.RootPEM()}},
+			[]attestation.Format{attestation.FormatTDX, attestation.FormatSEVSNP, attestation.FormatConfidentialSpace}, ""},
+		{"ok formats", []ACMEChallenge{REMOTE_ATTEST_01},
+			&ACMERemoteAttestation{Formats: []attestation.Format{attestation.FormatSEVSNP}},
+			[]attestation.Format{attestation.FormatSEVSNP}, ""},
+		{"ok not enabled", []ACMEChallenge{DNS_01},
+			&ACMERemoteAttestation{Formats: []attestation.Format{"tpm"}}, nil, ""},
+		{"fail format", []ACMEChallenge{REMOTE_ATTEST_01},
+			&ACMERemoteAttestation{Formats: []attestation.Format{"tpm"}}, nil, `attestation format "tpm" is not supported`},
+		{"fail claims hint", []ACMEChallenge{REMOTE_ATTEST_01},
+			&ACMERemoteAttestation{ClaimsHint: []string{"hwmodel", ""}}, nil, "claimsHint cannot contain empty values"},
+		{"fail tdx roots", []ACMEChallenge{REMOTE_ATTEST_01},
+			&ACMERemoteAttestation{TDXRoots: []byte("not pem")}, nil, "error initializing the tdx format"},
+		{"fail sev-snp roots", []ACMEChallenge{REMOTE_ATTEST_01},
+			&ACMERemoteAttestation{SEVSNPRoots: pki.RootPEM()}, nil, "error initializing the sev-snp format"},
+		{"fail confidential space without roots", []ACMEChallenge{REMOTE_ATTEST_01},
+			&ACMERemoteAttestation{Formats: []attestation.Format{attestation.FormatConfidentialSpace}}, nil,
+			"confidentialSpace.roots is required"},
+		{"fail confidential space roots", []ACMEChallenge{REMOTE_ATTEST_01},
+			&ACMERemoteAttestation{ConfidentialSpace: &ACMEConfidentialSpace{Roots: []byte("not pem")}}, nil,
+			"no certificates found in confidentialSpace.roots"},
+		{"fail confidential space max age", []ACMEChallenge{REMOTE_ATTEST_01},
+			&ACMERemoteAttestation{ConfidentialSpace: &ACMEConfidentialSpace{Roots: pki.RootPEM(), MaxTokenAge: &Duration{}}}, nil,
+			"confidentialSpace.maxTokenAge must be greater than 0"},
+		{"fail confidential space expectations", []ACMEChallenge{REMOTE_ATTEST_01},
+			&ACMERemoteAttestation{ConfidentialSpace: &ACMEConfidentialSpace{
+				Roots:        pki.RootPEM(),
+				Expectations: confidentialspace.Expectations{ProjectIDs: []string{""}},
+			}}, nil, "confidentialSpace: projectIDs cannot contain empty values"},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			p := &ACME{
+				Type:              "ACME",
+				Name:              "attested",
+				Challenges:        tt.challenges,
+				RemoteAttestation: tt.o,
+			}
+			err := p.Init(Config{Claims: globalProvisionerClaims})
+			if tt.wantErr != "" {
+				assert.ErrorContains(t, err, tt.wantErr)
+				return
+			}
+			require.NoError(t, err)
+			if tt.wantFormats == nil {
+				assert.Nil(t, p.remoteAttestation)
+				return
+			}
+			require.NotNil(t, p.remoteAttestation)
+			assert.Equal(t, tt.wantFormats, p.remoteAttestation.formats)
+		})
+	}
+}
+
+func TestACMERemoteAttestation_getters(t *testing.T) {
+	var o *ACMERemoteAttestation
+	assert.False(t, o.IsRequired())
+	assert.Nil(t, o.GetClaimsHint())
+	o = &ACMERemoteAttestation{Require: true, ClaimsHint: []string{"hwmodel"}}
+	assert.True(t, o.IsRequired())
+	assert.Equal(t, []string{"hwmodel"}, o.GetClaimsHint())
+	assert.Equal(t, o, (&ACME{RemoteAttestation: o}).GetRemoteAttestation())
+}
+
+func TestACME_AuthorizeOrderIdentifier_remoteAttestation(t *testing.T) {
+	// A policy that allows nothing still allows a remote-attestation
+	// identifier, which names nothing in the certificate.
+	p := &ACME{
+		Type: "ACME",
+		Name: "attested",
+		Options: &Options{X509: &X509Options{
+			AllowedNames: &policy.X509NameOptions{DNSDomains: []string{"*.example.com"}},
+		}},
+	}
+	require.NoError(t, p.Init(Config{Claims: globalProvisionerClaims}))
+	ctx := context.Background()
+	assert.NoError(t, p.AuthorizeOrderIdentifier(ctx, ACMEIdentifier{Type: RemoteAttestation, Value: "anything"}))
+	assert.Error(t, p.AuthorizeOrderIdentifier(ctx, ACMEIdentifier{Type: DNS, Value: "anything"}))
+}
+
+func TestACME_VerifyRemoteAttestation_confidentialSpace(t *testing.T) {
+	pki := cstest.New(t)
+	now := time.Now()
+	bound := testBound()
+	nonces := []string{
+		base64.RawURLEncoding.EncodeToString(bound[:32]),
+		base64.RawURLEncoding.EncodeToString(bound[32:]),
+		"extra-nonce",
+	}
+	newProv := func(cs *ACMEConfidentialSpace) *ACME {
+		cs.Roots = pki.RootPEM()
+		return newRemoteAttestationACME(t, &ACMERemoteAttestation{ConfidentialSpace: cs}, staticHTTPClient{})
+	}
+	mint := func(audience string, nonces ...string) []byte {
+		return []byte(pki.Mint(t, cstest.Claims(now, audience, nonces...)))
+	}
+
+	t.Run("ok default audience", func(t *testing.T) {
+		got, gotBound, err := newProv(&ACMEConfidentialSpace{}).VerifyRemoteAttestation(context.Background(),
+			jsonCMW("application/eat+jwt", mint(testRemoteAttestationAudience, nonces...), cmw.AttestationResults),
+			testRemoteAttestationAudience)
+		require.NoError(t, err)
+		assert.Equal(t, bound, gotBound)
+		assert.Equal(t, attestation.FormatConfidentialSpace, got.Format)
+		assert.Equal(t, "application/eat+jwt", got.MediaType)
+		assert.NotEmpty(t, got.Evidence)
+		require.NotNil(t, got.ConfidentialSpace)
+		assert.Equal(t, "GCP_INTEL_TDX", got.ConfidentialSpace.Claims["hwmodel"])
+		assert.Nil(t, got.TDX)
+		assert.Nil(t, got.SEVSNP)
+	})
+
+	t.Run("ok configured audience and no indicator", func(t *testing.T) {
+		_, gotBound, err := newProv(&ACMEConfidentialSpace{Audience: "my-project"}).VerifyRemoteAttestation(context.Background(),
+			jsonCMW("application/jwt", mint("my-project", nonces...), 0), testRemoteAttestationAudience)
+		require.NoError(t, err)
+		assert.Equal(t, bound, gotBound)
+	})
+
+	tests := []struct {
+		name    string
+		cs      *ACMEConfidentialSpace
+		record  *cmw.Record
+		wantErr string
+	}{
+		{"fail indicator", &ACMEConfidentialSpace{},
+			jsonCMW("application/eat+jwt", mint(testRemoteAttestationAudience, nonces...), cmw.Evidence),
+			"must be indicated as an attestation result"},
+		{"fail audience", &ACMEConfidentialSpace{},
+			jsonCMW("application/eat+jwt", mint("https://other.example.com", nonces...), 0), "attestation token is not valid"},
+		{"fail one nonce", &ACMEConfidentialSpace{},
+			jsonCMW("application/eat+jwt", mint(testRemoteAttestationAudience, nonces[0]), 0), "between 2 and 6 nonces"},
+		{"fail nonce encoding", &ACMEConfidentialSpace{},
+			jsonCMW("application/eat+jwt", mint(testRemoteAttestationAudience, nonces[0], "SHA256:"+nonces[1]), 0),
+			"eat_nonce[1] is not the base64url encoding of 32 bytes"},
+		{"fail nonce size", &ACMEConfidentialSpace{},
+			jsonCMW("application/eat+jwt", mint(testRemoteAttestationAudience, "c2hvcnQ", nonces[1]), 0),
+			"eat_nonce[0] is not the base64url encoding of 32 bytes"},
+		{"fail expectations", &ACMEConfidentialSpace{
+			Expectations: confidentialspace.Expectations{ProjectIDs: []string{"other"}},
+		}, jsonCMW("application/eat+jwt", mint(testRemoteAttestationAudience, nonces...), 0), `project "my-project" is not allowed`},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			_, _, err := newProv(tt.cs).VerifyRemoteAttestation(context.Background(), tt.record, testRemoteAttestationAudience)
+			assert.ErrorContains(t, err, tt.wantErr)
+			assert.ErrorIs(t, err, attestation.ErrInvalidEvidence)
+		})
+	}
+}
+
+func TestACME_VerifyRemoteAttestation(t *testing.T) {
+	pki := cstest.New(t)
+	tdxOnly := newRemoteAttestationACME(t, &ACMERemoteAttestation{Formats: []attestation.Format{attestation.FormatTDX}}, staticHTTPClient{})
+	defaults := newRemoteAttestationACME(t, nil, staticHTTPClient{})
+	tsmJSON := func(provider, aux string) []byte {
+		s := `{"provider":"` + provider + `","outblob":"AAEC"`
+		if aux != "" {
+			s += `,"auxblob":"` + aux + `"`
+		}
+		return []byte(s + "}")
+	}
+	token := []byte(pki.Mint(t, cstest.Claims(time.Now(), testRemoteAttestationAudience, "a", "b")))
+
+	tests := []struct {
+		name        string
+		p           *ACME
+		record      *cmw.Record
+		wantErr     string
+		wantInvalid bool
+	}{
+		{"fail not enabled", &ACME{}, jsonCMW("application/eat+jwt", token, 0), "remote-attest-01 is not enabled", false},
+		{"fail media type", defaults, jsonCMW("text/plain", []byte("x"), 0), `evidence media type "text/plain" is not supported`, true},
+		{"fail tsm indicator", defaults, jsonCMW("application/vnd.veraison.tsm-report+json", tsmJSON("tdx_guest", ""), cmw.AttestationResults),
+			"a tsm report must be indicated as evidence", true},
+		{"fail tsm parse", defaults, jsonCMW("application/vnd.veraison.tsm-report+json", []byte("{"), cmw.Evidence),
+			"error parsing tsm report", true},
+		{"fail tsm provider", defaults, jsonCMW("application/vnd.veraison.tsm-report+json", tsmJSON("arm_cca_guest", ""), 0),
+			`tsm report provider "arm_cca_guest" is not supported`, true},
+		{"fail tdx auxblob", defaults, jsonCMW("application/vnd.veraison.tsm-report+json", tsmJSON("tdx_guest", "AAEC"), 0),
+			"a tdx tsm report does not take an auxblob", true},
+		{"fail tdx quote", defaults, jsonCMW("application/vnd.veraison.tsm-report+json", tsmJSON("tdx_guest", ""), 0),
+			"error parsing tdx quote", true},
+		{"fail sev-snp report", defaults, jsonCMW("application/vnd.veraison.tsm-report+json", tsmJSON("sev_guest", ""), 0),
+			"error parsing sev-snp report", true},
+		{"fail sev-snp not enabled", tdxOnly, jsonCMW("application/vnd.veraison.tsm-report+json", tsmJSON("sev_guest", ""), 0),
+			"attestation format sev-snp is not enabled", true},
+		{"fail confidential space not enabled", defaults, jsonCMW("application/eat+jwt", token, 0),
+			"attestation format confidential-space is not enabled", true},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			_, _, err := tt.p.VerifyRemoteAttestation(context.Background(), tt.record, testRemoteAttestationAudience)
+			assert.ErrorContains(t, err, tt.wantErr)
+			assert.Equal(t, tt.wantInvalid, errors.Is(err, attestation.ErrInvalidEvidence))
+		})
+	}
+}
+
+func TestIsJWTMediaType(t *testing.T) {
+	assert.True(t, isJWTMediaType("application/jwt"))
+	assert.True(t, isJWTMediaType(`application/eat+jwt; eat_profile="tag:example.com,2026:x"`))
+	assert.False(t, isJWTMediaType("application/eat+cwt"))
+	assert.False(t, isJWTMediaType(strings.Repeat(";", 3)))
+}

+ 63 - 0
authority/provisioner/acme_remote_attestation_unix_test.go

@@ -0,0 +1,63 @@
+//go:build unix
+
+// go-sev-guest's testing package, which signs reports with test-only AMD keys,
+// imports golang.org/x/sys/unix.
+
+package provisioner
+
+import (
+	"context"
+	"encoding/base64"
+	"errors"
+	"testing"
+
+	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/require"
+
+	"github.com/smallstep/certificates/attestation"
+	"github.com/smallstep/certificates/attestation/cmw"
+	"github.com/smallstep/certificates/attestation/sevsnp/sevsnptest"
+)
+
+// TestACME_VerifyRemoteAttestation_sevsnp verifies a signed SEV-SNP report the
+// way the remote-attest-01 challenge does, revocation included: the revocation
+// list is signed by the test ARK and served by the provisioner's HTTP client.
+func TestACME_VerifyRemoteAttestation_sevsnp(t *testing.T) {
+	s := sevsnptest.New(t, false)
+	crlURL, crl := s.CRL(t)
+	p := newRemoteAttestationACME(t, &ACMERemoteAttestation{SEVSNPRoots: s.Roots}, staticHTTPClient{crlURL: crl})
+	bound := testBound()
+
+	tsmReport := func(report, certTable []byte) []byte {
+		return []byte(`{"provider":"sev_guest","outblob":"` + base64.RawURLEncoding.EncodeToString(report) +
+			`","auxblob":"` + base64.RawURLEncoding.EncodeToString(certTable) + `"}`)
+	}
+	const mediaType = `application/vnd.veraison.tsm-report+json; provider="sev_guest"`
+
+	t.Run("ok", func(t *testing.T) {
+		value := tsmReport(s.Report(t, bound, false), s.CertTable)
+		got, gotBound, err := p.VerifyRemoteAttestation(context.Background(), jsonCMW(mediaType, value, cmw.Evidence), "")
+		require.NoError(t, err)
+		assert.Equal(t, bound, gotBound)
+		assert.Equal(t, attestation.FormatSEVSNP, got.Format)
+		assert.Equal(t, mediaType, got.MediaType)
+		assert.Equal(t, value, got.Evidence)
+		require.NotNil(t, got.SEVSNP)
+		assert.Equal(t, "vcek", got.SEVSNP.SigningKey)
+	})
+
+	t.Run("fail debug", func(t *testing.T) {
+		value := tsmReport(s.Report(t, bound, true), s.CertTable)
+		_, _, err := p.VerifyRemoteAttestation(context.Background(), jsonCMW(mediaType, value, 0), "")
+		assert.ErrorContains(t, err, "policy allows debugging")
+		assert.ErrorIs(t, err, attestation.ErrInvalidEvidence)
+	})
+
+	t.Run("fail crl unreachable", func(t *testing.T) {
+		p := newRemoteAttestationACME(t, &ACMERemoteAttestation{SEVSNPRoots: s.Roots}, staticHTTPClient{})
+		value := tsmReport(s.Report(t, bound, false), s.CertTable)
+		_, _, err := p.VerifyRemoteAttestation(context.Background(), jsonCMW(mediaType, value, 0), "")
+		assert.ErrorContains(t, err, "error fetching sev-snp certificates")
+		assert.False(t, errors.Is(err, attestation.ErrInvalidEvidence))
+	})
+}

+ 1 - 0
authority/provisioner/acme_test.go

@@ -36,6 +36,7 @@ func TestACMEChallenge_Validate(t *testing.T) {
 		{"device-attest-01", DEVICE_ATTEST_01, false},
 		{"wire-oidc-01", DEVICE_ATTEST_01, false},
 		{"wire-dpop-01", DEVICE_ATTEST_01, false},
+		{"remote-attest-01", REMOTE_ATTEST_01, false},
 		{"uppercase", "HTTP-01", false},
 		{"fail", "http-02", true},
 	}