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

Check one remote-attest-01 binding at finalize and add a claim nonce

The evidence now carries one binding first: SHA-256 of the challenge's
key authorization followed by the DER SubjectPublicKeyInfo of the
certificate key. The CSR arrives only at finalize, so the challenge
verifies the evidence and stores the key authorization and the binding
on the authorization, and Finalize recomputes the binding over the CSR's
RawSubjectPublicKeyInfo. Evidence replayed from another challenge or
account validates its challenge but never finalizes.

This frees room for the relying party:
- a TDX quote or SEV-SNP report carries the binding and then a 32-byte
  claim nonce in its 64 bytes of report data;
- a Confidential Space token carries the binding as eat_nonce[0], and
  the relying party's own nonces after it.
The dispatcher checks 64 bytes for configfs-tsm evidence and 32 for
tokens.

webhook.Attestation replaces keyAuthorizationDigest and keyDigest with
keyAuthorization, bindingDigest, claimNonce, and account (the ACME
account and the EAB key it was created with), so a webhook can tell
which registered client the evidence comes from. nosql's
GetExternalAccountKeyByAccountID, which returned nothing, now finds the
key among the provisioner's keys.

Confidential Space roots default to the pinned Google root; the format
still has to be enabled.

Claude-Session: https://claude.ai/code/session_01CjfEMLGpnHQaWsmxe1zmLF
Josh Drake 1 месяц назад
Родитель
Сommit
60e5a73be0

+ 11 - 5
CHANGELOG.md

@@ -38,11 +38,17 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
   Intel TDX quote or an AMD SEV-SNP report as a configfs-tsm report
   (`application/vnd.veraison.tsm-report+json` or `+cbor`), or a Google
   Confidential Space PKI token (`application/eat+jwt`). The draft defines no
-  binding, so step-ca requires the evidence to bind the SHA-256 digests of the
-  challenge's key authorization, computed over its `freshnessNonce`, and of the
-  DER SubjectPublicKeyInfo of the key the order is finalized with. The verified
-  attestation is sent to webhooks as `attestation` and given to templates as
-  `.Attestation`. The challenge can be configured in `ca.json` only for now.
+  binding, so step-ca requires the evidence to carry first SHA-256 of the
+  challenge's key authorization, computed over its `freshnessNonce`, followed
+  by the DER SubjectPublicKeyInfo of the key the order is finalized with; the
+  binding is checked at finalize. A TDX quote or SEV-SNP report carries the
+  relying party's nonce in the second half of its report data, and a
+  Confidential Space token its relying party's nonces after the binding.
+  Google Cloud Attestation's root is embedded, so Confidential Space tokens
+  verify without configured roots. The verified attestation, with the ACME
+  account and the EAB key it was created with, is sent to webhooks as
+  `attestation` and given to templates as `.Attestation`. The challenge can be
+  configured in `ca.json` only for now.
 - The `attestation` package and its subpackages, which verify TDX quotes,
   SEV-SNP reports and Confidential Space tokens, and parse CMW records and
   configfs-tsm reports. The `device-attest-01` formats' verifiers (`apple`,

+ 40 - 30
acme/challenge_remote_attestation.go

@@ -4,8 +4,8 @@ import (
 	"bytes"
 	"context"
 	"crypto/sha256"
-	"crypto/subtle"
 	"crypto/x509"
+	"encoding/base64"
 	"encoding/hex"
 	"errors"
 	"time"
@@ -22,19 +22,23 @@ import (
 // (draft-ietf-acme-rats-03). The payload is a CMW record (RFC 9999) holding the
 // evidence: a TDX quote or an SEV-SNP report in a configfs-tsm report, or a
 // Confidential Space token. step-ca profiles the draft, which defines no
-// binding, by requiring the evidence to bind 64 bytes:
+// binding, by requiring the evidence to bind first
 //
-//   - The SHA-256 digest of the key authorization of the challenge, computed
-//     over its freshnessNonce: freshnessNonce || '.' || base64url(JWK
-//     thumbprint of the account key). It makes the evidence fresh and binds it
-//     to the account.
-//   - The SHA-256 digest of the DER SubjectPublicKeyInfo of the key the order
-//     will be finalized with. The CSR has not been sent yet, so the digest is
-//     stored on the authorization and finalize compares it with the CSR's key.
+//	SHA-256(keyAuthorization || DER SubjectPublicKeyInfo of the certificate key)
 //
-// A TDX quote or SEV-SNP report carries the 64 bytes as its report data; a
-// Confidential Space token carries each digest, base64url encoded without
-// padding, as its first two eat_nonce values.
+// where keyAuthorization is freshnessNonce || '.' || base64url(JWK thumbprint
+// of the account key). The binding makes the evidence fresh, ties it to the
+// account, and attests the key the order will be finalized with. A TDX quote or
+// an SEV-SNP report carries it as the first half of its report data and the
+// relying party's nonce, its claim nonce, as the second half; a Confidential
+// Space token carries it, base64url encoded without padding, as its first
+// eat_nonce value, and the relying party's nonces after it.
+//
+// The certificate request is sent only when the order is finalized, so this
+// validation verifies the evidence and stores the key authorization, the
+// binding and the claim nonce on the authorization, and Finalize checks the
+// binding against the request's key. Evidence replayed from another challenge
+// validates the challenge but can never finalize the order.
 //
 // An empty payload, or an empty JSON object, leaves the challenge unchanged.
 func remoteAttest01Validate(ctx context.Context, ch *Challenge, db DB, jwk *jose.JSONWebKey, payload []byte) error {
@@ -61,31 +65,34 @@ func remoteAttest01Validate(ctx context.Context, ch *Challenge, db DB, jwk *jose
 		return storeError(ctx, db, ch, true, WrapDetailedError(ErrorBadAttestationStatementType, err, "%s", err))
 	case err != nil:
 		return WrapErrorISE(err, "error verifying remote attestation")
-	case len(bound) != provisioner.RemoteAttestationBoundSize:
-		return NewErrorISE("remote attestation binds %d bytes, not %d", len(bound), provisioner.RemoteAttestationBoundSize)
+	}
+
+	var claimNonce string
+	switch len(bound) {
+	case provisioner.RemoteAttestationBindingSize:
+	case provisioner.RemoteAttestationBindingSize + provisioner.RemoteAttestationClaimNonceSize:
+		claimNonce = base64.RawURLEncoding.EncodeToString(bound[provisioner.RemoteAttestationBindingSize:])
+	default:
+		return NewErrorISE("remote attestation binds %d bytes", len(bound))
 	}
 
 	keyAuth, err := KeyAuthorization(ch.FreshnessNonce, jwk)
 	if err != nil {
 		return err
 	}
-	keyAuthDigest := sha256.Sum256([]byte(keyAuth))
-	if subtle.ConstantTimeCompare(bound[:sha256.Size], keyAuthDigest[:]) != 1 {
-		return storeError(ctx, db, ch, true, NewDetailedError(ErrorBadAttestationStatementType,
-			"the evidence does not bind the key authorization of the challenge"))
-	}
 
 	az, err := db.GetAuthorization(ctx, ch.AuthorizationID)
 	if err != nil {
 		return WrapErrorISE(err, "error loading authorization")
 	}
 	az.Attestation = &webhook.Attestation{
-		Challenge:              string(REMOTEATTEST01),
-		Hint:                   az.Identifier.Value,
-		FreshnessNonce:         ch.FreshnessNonce,
-		KeyAuthorizationDigest: hex.EncodeToString(keyAuthDigest[:]),
-		KeyDigest:              hex.EncodeToString(bound[sha256.Size:]),
-		Result:                 result,
+		Challenge:        string(REMOTEATTEST01),
+		Hint:             az.Identifier.Value,
+		FreshnessNonce:   ch.FreshnessNonce,
+		KeyAuthorization: keyAuth,
+		BindingDigest:    hex.EncodeToString(bound[:provisioner.RemoteAttestationBindingSize]),
+		ClaimNonce:       claimNonce,
+		Result:           result,
 	}
 
 	ch.Status = StatusValid
@@ -103,9 +110,12 @@ func remoteAttest01Validate(ctx context.Context, ch *Challenge, db DB, jwk *jose
 	return nil
 }
 
-// remoteAttestationKeyDigest returns the hex encoded SHA-256 digest of the DER
-// SubjectPublicKeyInfo of the CSR's key, which remote-attest-01 evidence binds.
-func remoteAttestationKeyDigest(csr *x509.CertificateRequest) string {
-	sum := sha256.Sum256(csr.RawSubjectPublicKeyInfo)
-	return hex.EncodeToString(sum[:])
+// RemoteAttestationBinding returns the hex encoded binding remote-attest-01
+// evidence carries for a certificate request: SHA-256 of the key authorization
+// followed by the DER SubjectPublicKeyInfo of the request's key.
+func RemoteAttestationBinding(keyAuthorization string, csr *x509.CertificateRequest) string {
+	h := sha256.New()
+	h.Write([]byte(keyAuthorization))
+	h.Write(csr.RawSubjectPublicKeyInfo)
+	return hex.EncodeToString(h.Sum(nil))
 }

+ 126 - 61
acme/challenge_remote_attestation_test.go

@@ -9,6 +9,7 @@ import (
 	"crypto/sha256"
 	"crypto/x509"
 	"crypto/x509/pkix"
+	"encoding/base64"
 	"encoding/hex"
 	"errors"
 	"testing"
@@ -16,7 +17,6 @@ import (
 
 	"github.com/stretchr/testify/assert"
 	"github.com/stretchr/testify/require"
-	"go.step.sm/crypto/jose"
 	"go.step.sm/crypto/keyutil"
 	"go.step.sm/crypto/x509util"
 
@@ -45,34 +45,45 @@ func mustCSR(t *testing.T, cn string) (*x509.CertificateRequest, crypto.Signer)
 	return csr, key
 }
 
-// testBoundData returns the data the evidence of a challenge with the given
-// account key binds, for the given CSR's key.
-func testBoundData(t *testing.T, jwk *jose.JSONWebKey, csr *x509.CertificateRequest) []byte {
-	t.Helper()
-	keyAuth, err := KeyAuthorization(testFreshnessNonce, jwk)
-	require.NoError(t, err)
-	ka := sha256.Sum256([]byte(keyAuth))
-	key := sha256.Sum256(csr.RawSubjectPublicKeyInfo)
-	return append(ka[:], key[:]...)
+// testBinding returns the binding the evidence of a challenge with the given
+// key authorization carries for the CSR's key.
+func testBinding(keyAuth string, csr *x509.CertificateRequest) []byte {
+	sum := sha256.Sum256(append([]byte(keyAuth), csr.RawSubjectPublicKeyInfo...))
+	return sum[:]
+}
+
+func TestRemoteAttestationBinding(t *testing.T) {
+	csr, _ := mustCSR(t, "")
+	want := testBinding("nonce.thumbprint", csr)
+	assert.Equal(t, hex.EncodeToString(want), RemoteAttestationBinding("nonce.thumbprint", csr))
+	assert.NotEqual(t, hex.EncodeToString(want), RemoteAttestationBinding("other.thumbprint", csr))
 }
 
 func TestRemoteAttest01Validate(t *testing.T) {
-	jwk, _ := mustAccountAndKeyAuthorization(t, testFreshnessNonce)
+	jwk, keyAuth := mustAccountAndKeyAuthorization(t, testFreshnessNonce)
 	csr, _ := mustCSR(t, "")
-	bound := testBoundData(t, jwk, csr)
-	result := &attestation.Result{
+	binding := testBinding(keyAuth, csr)
+	claimNonce := make([]byte, 32)
+	for i := range claimNonce {
+		claimNonce[i] = byte(i)
+	}
+	csResult := &attestation.Result{
 		Format:            attestation.FormatConfidentialSpace,
 		MediaType:         "application/eat+jwt",
 		Evidence:          []byte("token"),
 		ConfidentialSpace: &attestation.ConfidentialSpace{Claims: map[string]any{"hwmodel": "GCP_INTEL_TDX"}},
 	}
+	tdxResult := &attestation.Result{Format: attestation.FormatTDX, TDX: &attestation.TDX{MRTD: "aa"}}
 
 	type want struct {
-		status    Status
-		errType   string
-		errDetail string
-		err       string
-		stored    bool
+		status     Status
+		errType    string
+		errDetail  string
+		err        string
+		stored     bool
+		format     string
+		claimNonce string
+		result     *attestation.Result
 	}
 	tests := []struct {
 		name    string
@@ -81,12 +92,25 @@ func TestRemoteAttest01Validate(t *testing.T) {
 		verify  func(context.Context, *cmw.Record, string) (*attestation.Result, []byte, error)
 		want    want
 	}{
-		{"ok", testRemoteAttestationCMW, testFreshnessNonce,
+		{"ok confidential space", testRemoteAttestationCMW, testFreshnessNonce,
 			func(_ context.Context, r *cmw.Record, aud string) (*attestation.Result, []byte, error) {
 				assert.Equal(t, "application/eat+jwt", r.MediaType)
 				assert.Equal(t, "https://ca.example.com/acme/acme/directory", aud)
-				return result, bound, nil
-			}, want{status: StatusValid, stored: true}},
+				return csResult, binding, nil
+			}, want{status: StatusValid, stored: true, format: "confidential-space", result: csResult}},
+		// A quote's report data carries the relying party's claim nonce after
+		// the binding.
+		{"ok tdx with claim nonce", testRemoteAttestationCMW, testFreshnessNonce,
+			func(context.Context, *cmw.Record, string) (*attestation.Result, []byte, error) {
+				return tdxResult, append(append([]byte(nil), binding...), claimNonce...), nil
+			}, want{status: StatusValid, stored: true, format: "tdx", result: tdxResult,
+				claimNonce: base64.RawURLEncoding.EncodeToString(claimNonce)}},
+		// The binding is checked when the order is finalized, so evidence
+		// with any binding validates the challenge.
+		{"ok binding checked at finalize", testRemoteAttestationCMW, testFreshnessNonce,
+			func(context.Context, *cmw.Record, string) (*attestation.Result, []byte, error) {
+				return csResult, make([]byte, 32), nil
+			}, want{status: StatusValid, stored: true, format: "confidential-space", result: csResult}},
 		{"ok empty payload", nil, testFreshnessNonce, nil, want{status: StatusPending}},
 		{"ok empty object", []byte(" {} "), testFreshnessNonce, nil, want{status: StatusPending}},
 		{"fail no nonce", testRemoteAttestationCMW, "", nil, want{status: StatusPending, err: "has no freshness nonce"}},
@@ -102,14 +126,8 @@ func TestRemoteAttest01Validate(t *testing.T) {
 			}, want{status: StatusPending, err: "error verifying remote attestation"}},
 		{"fail bound size", testRemoteAttestationCMW, testFreshnessNonce,
 			func(context.Context, *cmw.Record, string) (*attestation.Result, []byte, error) {
-				return result, bound[:32], nil
-			}, want{status: StatusPending, err: "binds 32 bytes"}},
-		{"fail key authorization", testRemoteAttestationCMW, testFreshnessNonce,
-			func(context.Context, *cmw.Record, string) (*attestation.Result, []byte, error) {
-				other := append([]byte(nil), bound...)
-				other[0] ^= 1
-				return result, other, nil
-			}, want{status: StatusInvalid, errType: "badAttestationStatement", errDetail: "does not bind the key authorization"}},
+				return csResult, binding[:16], nil
+			}, want{status: StatusPending, err: "binds 16 bytes"}},
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
@@ -171,16 +189,18 @@ func TestRemoteAttest01Validate(t *testing.T) {
 			require.NotNil(t, updatedCh)
 			assert.Nil(t, ch.Error)
 			assert.NotEmpty(t, ch.ValidatedAt)
-			assert.Equal(t, "confidential-space", ch.PayloadFormat)
+			assert.Equal(t, tt.want.format, ch.PayloadFormat)
 			require.NotNil(t, updatedAz)
 			require.NotNil(t, updatedAz.Attestation)
 			att := updatedAz.Attestation
 			assert.Equal(t, "remote-attest-01", att.Challenge)
 			assert.Equal(t, "measured_boot", att.Hint)
 			assert.Equal(t, testFreshnessNonce, att.FreshnessNonce)
-			assert.Equal(t, hex.EncodeToString(bound[:32]), att.KeyAuthorizationDigest)
-			assert.Equal(t, remoteAttestationKeyDigest(csr), att.KeyDigest)
-			assert.Equal(t, result, att.Result)
+			assert.Equal(t, keyAuth, att.KeyAuthorization)
+			assert.Len(t, att.BindingDigest, 64)
+			assert.Equal(t, tt.want.claimNonce, att.ClaimNonce)
+			assert.Nil(t, att.Account, "the account is added at finalize")
+			assert.Equal(t, tt.want.result, att.Result)
 		})
 	}
 }
@@ -192,8 +212,19 @@ func TestOrder_checkAttestedKeys(t *testing.T) {
 	require.NoError(t, err)
 	otherFP, err := keyutil.Fingerprint(otherCSR.PublicKey)
 	require.NoError(t, err)
-	att := &webhook.Attestation{Challenge: "remote-attest-01", KeyDigest: remoteAttestationKeyDigest(csr)}
-	otherAtt := &webhook.Attestation{Challenge: "remote-attest-01", KeyDigest: remoteAttestationKeyDigest(otherCSR)}
+	newAtt := func(keyAuth string, csr *x509.CertificateRequest) *webhook.Attestation {
+		return &webhook.Attestation{
+			Challenge:        "remote-attest-01",
+			KeyAuthorization: keyAuth,
+			BindingDigest:    hex.EncodeToString(testBinding(keyAuth, csr)),
+		}
+	}
+	att := newAtt("nonce.thumbprint", csr)
+	otherKeyAtt := newAtt("nonce.thumbprint", otherCSR)
+	// The binding is stored with one key authorization but was computed with
+	// another, as evidence replayed from another challenge or account would be.
+	replayedAtt := newAtt("nonce.thumbprint", csr)
+	replayedAtt.KeyAuthorization = "other-nonce.other-thumbprint"
 
 	tests := []struct {
 		name    string
@@ -206,13 +237,16 @@ func TestOrder_checkAttestedKeys(t *testing.T) {
 		{"ok attestation", map[string]*Authorization{"az1": {}, "az2": {Attestation: att}}, att, ""},
 		{"ok both", map[string]*Authorization{"az1": {Fingerprint: fp}, "az2": {Attestation: att}}, att, ""},
 		{"fail fingerprint", map[string]*Authorization{"az1": {Fingerprint: otherFP}, "az2": {}}, nil, "csr does not match the attested key"},
-		{"fail attestation", map[string]*Authorization{"az1": {}, "az2": {Attestation: otherAtt}}, nil, "csr does not match the attested key"},
-		{"fail attestation without digest", map[string]*Authorization{"az1": {Attestation: &webhook.Attestation{}}, "az2": {}}, nil,
+		{"fail attestation of another key", map[string]*Authorization{"az1": {}, "az2": {Attestation: otherKeyAtt}}, nil,
+			"csr does not match the attested key"},
+		{"fail replayed evidence", map[string]*Authorization{"az1": {}, "az2": {Attestation: replayedAtt}}, nil,
+			"csr does not match the attested key"},
+		{"fail attestation without key authorization", map[string]*Authorization{"az1": {Attestation: &webhook.Attestation{}}, "az2": {}}, nil,
 			"csr does not match the attested key"},
 		// Every attested key is checked, not only the first one found.
 		{"fail second fingerprint", map[string]*Authorization{"az1": {Fingerprint: fp}, "az2": {Fingerprint: otherFP}}, nil,
 			"csr does not match the attested key"},
-		{"fail attestation after fingerprint", map[string]*Authorization{"az1": {Fingerprint: fp}, "az2": {Attestation: otherAtt}}, nil,
+		{"fail attestation after fingerprint", map[string]*Authorization{"az1": {Fingerprint: fp}, "az2": {Attestation: otherKeyAtt}}, nil,
 			"csr does not match the attested key"},
 		{"fail db", map[string]*Authorization{"az1": nil}, nil, "error getting authorization"},
 	}
@@ -240,35 +274,48 @@ func TestOrder_checkAttestedKeys(t *testing.T) {
 }
 
 // TestOrder_Finalize_remoteAttestation finalizes an order whose only
-// identifier is remote-attestation: the CSR names nothing, and the attestation
-// reaches the template data and the bodies of the webhook requests.
+// identifier is remote-attestation: the CSR names nothing, the binding is
+// checked against the CSR's key, and the attestation, with the account and its
+// EAB key, reaches the template data and the bodies of the webhook requests.
 func TestOrder_Finalize_remoteAttestation(t *testing.T) {
 	csr, _ := mustCSR(t, "")
-	att := &webhook.Attestation{
-		Challenge: "remote-attest-01",
-		KeyDigest: remoteAttestationKeyDigest(csr),
-		Result:    &attestation.Result{Format: attestation.FormatTDX, TDX: &attestation.TDX{MRTD: "aa"}},
+	newAtt := func() *webhook.Attestation {
+		return &webhook.Attestation{
+			Challenge:        "remote-attest-01",
+			KeyAuthorization: "nonce.thumbprint",
+			BindingDigest:    hex.EncodeToString(testBinding("nonce.thumbprint", csr)),
+			ClaimNonce:       "claim",
+			Result:           &attestation.Result{Format: attestation.FormatTDX, TDX: &attestation.TDX{MRTD: "aa"}},
+		}
 	}
 
 	newOrder := func() *Order {
 		return &Order{
 			ID:               "orderID",
 			AccountID:        "accID",
+			ProvisionerID:    "provID",
 			Status:           StatusReady,
 			ExpiresAt:        time.Now().Add(time.Hour),
 			Identifiers:      []Identifier{{Type: RemoteAttestation}},
 			AuthorizationIDs: []string{"azID"},
 		}
 	}
-	db := &MockDB{
-		MockGetAuthorization: func(_ context.Context, id string) (*Authorization, error) {
-			return &Authorization{ID: id, Status: StatusValid, Attestation: att}, nil
-		},
-		MockCreateCertificate: func(_ context.Context, cert *Certificate) error {
-			cert.ID = "certID"
-			return nil
-		},
-		MockUpdateOrder: func(context.Context, *Order) error { return nil },
+	newDB := func(eak *ExternalAccountKey, eakErr error) *MockDB {
+		return &MockDB{
+			MockGetAuthorization: func(_ context.Context, id string) (*Authorization, error) {
+				return &Authorization{ID: id, Status: StatusValid, Attestation: newAtt()}, nil
+			},
+			MockGetExternalAccountKeyByAccountID: func(_ context.Context, provisionerID, accountID string) (*ExternalAccountKey, error) {
+				assert.Equal(t, "provID", provisionerID)
+				assert.Equal(t, "accID", accountID)
+				return eak, eakErr
+			},
+			MockCreateCertificate: func(_ context.Context, cert *Certificate) error {
+				cert.ID = "certID"
+				return nil
+			},
+			MockUpdateOrder: func(context.Context, *Order) error { return nil },
+		}
 	}
 	prov := &MockProvisioner{
 		MauthorizeSign: func(context.Context, string) ([]provisioner.SignOption, error) {
@@ -276,10 +323,9 @@ func TestOrder_Finalize_remoteAttestation(t *testing.T) {
 		},
 		MgetOptions: func() *provisioner.Options { return nil },
 	}
-
-	t.Run("ok", func(t *testing.T) {
+	signAndCheck := func(t *testing.T, wantAccount *webhook.AttestationAccount) *mockSignAuth {
 		leaf, intermediate := &x509.Certificate{Raw: []byte("leaf")}, &x509.Certificate{Raw: []byte("intermediate")}
-		ca := &mockSignAuth{
+		return &mockSignAuth{
 			signWithContext: func(ctx context.Context, _ *x509.CertificateRequest, _ provisioner.SignOptions, opts ...provisioner.SignOption) ([]*x509.Certificate, error) {
 				var wc *provisioner.WebhookController
 				for _, o := range opts {
@@ -288,33 +334,52 @@ func TestOrder_Finalize_remoteAttestation(t *testing.T) {
 					}
 				}
 				require.NotNil(t, wc)
+				want := newAtt()
+				want.Account = wantAccount
 				data, ok := wc.TemplateData.(x509util.TemplateData)
 				require.True(t, ok)
-				assert.Equal(t, att, data["Attestation"])
+				assert.Equal(t, want, data["Attestation"])
 				assert.Empty(t, data[x509util.SANsKey])
 
 				req := &webhook.RequestBody{}
 				require.NoError(t, wc.Enrich(ctx, req))
-				assert.Equal(t, att, req.Attestation)
+				assert.Equal(t, want, req.Attestation)
 				return []*x509.Certificate{leaf, intermediate}, nil
 			},
 		}
+	}
+
+	t.Run("ok without eab", func(t *testing.T) {
 		o := newOrder()
-		require.NoError(t, o.Finalize(context.Background(), db, csr, ca, prov))
+		require.NoError(t, o.Finalize(context.Background(), newDB(nil, nil), csr, signAndCheck(t, &webhook.AttestationAccount{ID: "accID"}), prov))
 		assert.Equal(t, StatusValid, o.Status)
 		assert.Equal(t, "certID", o.CertificateID)
 	})
 
+	t.Run("ok with eab", func(t *testing.T) {
+		eak := &ExternalAccountKey{ID: "eakID", Reference: "machine-1", AccountID: "accID"}
+		o := newOrder()
+		require.NoError(t, o.Finalize(context.Background(), newDB(eak, nil), csr, signAndCheck(t, &webhook.AttestationAccount{
+			ID: "accID", ExternalAccountKeyID: "eakID", Reference: "machine-1",
+		}), prov))
+		assert.Equal(t, StatusValid, o.Status)
+	})
+
+	t.Run("fail eab lookup", func(t *testing.T) {
+		err := newOrder().Finalize(context.Background(), newDB(nil, errors.New("force")), csr, &mockSignAuth{}, prov)
+		assert.ErrorContains(t, err, "error getting the external account key")
+	})
+
 	t.Run("fail other key", func(t *testing.T) {
 		other, _ := mustCSR(t, "")
-		err := newOrder().Finalize(context.Background(), db, other, &mockSignAuth{}, prov)
+		err := newOrder().Finalize(context.Background(), newDB(nil, nil), other, &mockSignAuth{}, prov)
 		assert.ErrorContains(t, err, "csr does not match the attested key")
 	})
 
 	t.Run("fail common name", func(t *testing.T) {
 		// The order names nothing, so the CSR cannot name anything either.
 		named := mustCSRWithKeyOf(t, csr, "workload.example.com")
-		err := newOrder().Finalize(context.Background(), db, named, &mockSignAuth{}, prov)
+		err := newOrder().Finalize(context.Background(), newDB(nil, nil), named, &mockSignAuth{}, prov)
 		var acmeErr *Error
 		require.ErrorAs(t, err, &acmeErr)
 		assert.Equal(t, "urn:ietf:params:acme:error:badCSR", acmeErr.Type)

+ 46 - 3
acme/db/nosql/challenge_remote_attestation_test.go

@@ -2,6 +2,7 @@ package nosql
 
 import (
 	"context"
+	"encoding/json"
 	"testing"
 
 	"github.com/stretchr/testify/assert"
@@ -67,9 +68,11 @@ func TestDB_Authorization_remoteAttestation(t *testing.T) {
 		},
 	}}
 	att := &webhook.Attestation{
-		Challenge:      "remote-attest-01",
-		FreshnessNonce: "nonce",
-		KeyDigest:      "01",
+		Challenge:        "remote-attest-01",
+		FreshnessNonce:   "nonce",
+		KeyAuthorization: "nonce.thumbprint",
+		BindingDigest:    "01",
+		ClaimNonce:       "claim",
 		Result: &attestation.Result{
 			Format:   attestation.FormatSEVSNP,
 			SEVSNP:   &attestation.SEVSNP{Measurement: "aa", GuestSVN: 2},
@@ -93,3 +96,43 @@ func TestDB_Authorization_remoteAttestation(t *testing.T) {
 	require.NoError(t, err)
 	assert.Equal(t, att, got.Attestation)
 }
+
+// TestDB_GetExternalAccountKeyByAccountID checks that the EAB key an account
+// was created with is found among its provisioner's keys, as a remote-attest-01
+// order's webhooks receive it.
+func TestDB_GetExternalAccountKeyByAccountID(t *testing.T) {
+	keys := map[string]dbExternalAccountKey{
+		"eak-1": {ID: "eak-1", ProvisionerID: "acme", Reference: "machine-1", AccountID: "account-1"},
+		"eak-2": {ID: "eak-2", ProvisionerID: "acme", Reference: "machine-2"},
+	}
+	d := DB{db: &db.MockNoSQLDB{
+		MGet: func(bucket, key []byte) ([]byte, error) {
+			switch string(bucket) {
+			case string(externalAccountKeyIDsByProvisionerIDTable):
+				assert.Equal(t, "acme", string(key))
+				return json.Marshal([]string{"eak-1", "eak-2"})
+			case string(externalAccountKeyTable):
+				eak, ok := keys[string(key)]
+				require.True(t, ok)
+				return json.Marshal(eak)
+			default:
+				t.Fatalf("unexpected bucket %s", bucket)
+				return nil, nil
+			}
+		},
+	}}
+
+	got, err := d.GetExternalAccountKeyByAccountID(context.Background(), "acme", "account-1")
+	require.NoError(t, err)
+	require.NotNil(t, got)
+	assert.Equal(t, "eak-1", got.ID)
+	assert.Equal(t, "machine-1", got.Reference)
+
+	got, err = d.GetExternalAccountKeyByAccountID(context.Background(), "acme", "account-without-eab")
+	require.NoError(t, err)
+	assert.Nil(t, got)
+
+	got, err = d.GetExternalAccountKeyByAccountID(context.Background(), "acme", "")
+	require.NoError(t, err)
+	assert.Nil(t, got)
+}

+ 18 - 3
acme/db/nosql/eab.go

@@ -230,9 +230,24 @@ func (db *DB) GetExternalAccountKeyByReference(ctx context.Context, provisionerI
 	return db.GetExternalAccountKey(ctx, provisionerID, dbExternalAccountKeyReference.ExternalAccountKeyID)
 }
 
-func (db *DB) GetExternalAccountKeyByAccountID(context.Context, string, string) (*acme.ExternalAccountKey, error) {
-	//nolint:nilnil // legacy
-	return nil, nil
+// GetExternalAccountKeyByAccountID returns the EAB key the account was created
+// with, or nil if there is none. Open source keeps no index from accounts to
+// keys, so it reads the provisioner's keys, which is fine for the few EAB keys
+// an open source CA holds.
+func (db *DB) GetExternalAccountKeyByAccountID(ctx context.Context, provisionerID, accountID string) (*acme.ExternalAccountKey, error) {
+	if accountID == "" {
+		return nil, nil //nolint:nilnil // no account, no key
+	}
+	keys, _, err := db.GetExternalAccountKeys(ctx, provisionerID, "", 0)
+	if err != nil {
+		return nil, err
+	}
+	for _, eak := range keys {
+		if eak.AccountID == accountID {
+			return eak, nil
+		}
+	}
+	return nil, nil //nolint:nilnil // the account has no key
 }
 
 func (db *DB) UpdateExternalAccountKey(ctx context.Context, provisionerID string, eak *acme.ExternalAccountKey) error {

+ 29 - 7
acme/order.go

@@ -147,14 +147,14 @@ func (o *Order) UpdateStatus(ctx context.Context, db DB) error {
 
 // checkAttestedKeys checks the CSR's key against every key an authorization of
 // the order attested: the fingerprint of the key a device-attest-01 challenge
-// verified, and the digest of the key the evidence of a remote-attest-01
-// challenge bound. It returns the attestation of the order's remote-attest-01
-// challenge, if there is one.
+// verified, and the binding the evidence of a remote-attest-01 challenge
+// carries, SHA-256 of the challenge's key authorization followed by the key. It
+// returns the attestation of the order's remote-attest-01 challenge, if there
+// is one.
 func (o *Order) checkAttestedKeys(ctx context.Context, db DB, csr *x509.CertificateRequest) (*webhook.Attestation, error) {
 	var (
 		att         *webhook.Attestation
 		fingerprint string
-		keyDigest   string
 	)
 	for _, azID := range o.AuthorizationIDs {
 		az, err := db.GetAuthorization(ctx, azID)
@@ -172,10 +172,11 @@ func (o *Order) checkAttestedKeys(ctx context.Context, db DB, csr *x509.Certific
 			}
 		}
 		if az.Attestation != nil {
-			if keyDigest == "" {
-				keyDigest = remoteAttestationKeyDigest(csr)
+			if az.Attestation.KeyAuthorization == "" {
+				return nil, NewError(ErrorUnauthorizedType, "order %s csr does not match the attested key", o.ID)
 			}
-			if subtle.ConstantTimeCompare([]byte(az.Attestation.KeyDigest), []byte(keyDigest)) == 0 {
+			binding := RemoteAttestationBinding(az.Attestation.KeyAuthorization, csr)
+			if subtle.ConstantTimeCompare([]byte(az.Attestation.BindingDigest), []byte(binding)) == 0 {
 				return nil, NewError(ErrorUnauthorizedType, "order %s csr does not match the attested key", o.ID)
 			}
 			att = az.Attestation
@@ -184,6 +185,22 @@ func (o *Order) checkAttestedKeys(ctx context.Context, db DB, csr *x509.Certific
 	return att, nil
 }
 
+// attestationAccount returns the order's ACME account for the webhooks of a
+// remote-attest-01 order, with the external account binding key the account
+// was created with, if any.
+func (o *Order) attestationAccount(ctx context.Context, db DB) (*webhook.AttestationAccount, error) {
+	account := &webhook.AttestationAccount{ID: o.AccountID}
+	eak, err := db.GetExternalAccountKeyByAccountID(ctx, o.ProvisionerID, o.AccountID)
+	if err != nil {
+		return nil, WrapErrorISE(err, "error getting the external account key of account %q", o.AccountID)
+	}
+	if eak != nil {
+		account.ExternalAccountKeyID = eak.ID
+		account.Reference = eak.Reference
+	}
+	return account, nil
+}
+
 // Finalize signs a certificate if the necessary conditions for Order completion
 // have been met.
 //
@@ -215,6 +232,11 @@ func (o *Order) Finalize(ctx context.Context, db DB, csr *x509.CertificateReques
 	if err != nil {
 		return err
 	}
+	if att != nil {
+		if att.Account, err = o.attestationAccount(ctx, db); err != nil {
+			return err
+		}
+	}
 
 	// canonicalize the CSR to allow for comparison
 	csr = canonicalize(csr)

+ 39 - 29
authority/provisioner/acme_remote_attestation.go

@@ -20,11 +20,16 @@ import (
 	"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
+// RemoteAttestationBindingSize is the size of the binding the evidence of a
+// remote-attest-01 challenge carries first: SHA-256 of the challenge's key
+// authorization followed by the DER SubjectPublicKeyInfo of the key to be
+// certified.
+const RemoteAttestationBindingSize = sha256.Size
+
+// RemoteAttestationClaimNonceSize is the size of the relying party's nonce a
+// TDX quote or an SEV-SNP report carries after the binding, in the second half
+// of its report data.
+const RemoteAttestationClaimNonceSize = 32
 
 // remoteAttestationTimeout bounds the verification of the evidence of a
 // remote-attest-01 challenge, which may fetch collateral from Intel's and AMD's
@@ -57,8 +62,8 @@ type ACMERemoteAttestation struct {
 // 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 is a PEM bundle that replaces the root of Google Cloud
+	// Attestation's PKI, which step-ca embeds.
 	Roots []byte `json:"roots,omitempty"`
 	// Audience is the audience the token must have been requested for. It
 	// defaults to the ACME directory URL.
@@ -160,12 +165,15 @@ func (p *ACME) initializeRemoteAttestation() error {
 }
 
 func (v *remoteAttestationVerifier) initializeConfidentialSpace(o *ACMEConfidentialSpace) error {
-	if o == nil || len(o.Roots) == 0 {
-		return errors.New("confidentialSpace.roots is required")
+	if o == nil {
+		o = &ACMEConfidentialSpace{}
 	}
-	v.csRoots = x509.NewCertPool()
-	if !v.csRoots.AppendCertsFromPEM(o.Roots) {
-		return errors.New("no certificates found in confidentialSpace.roots")
+	v.csRoots = confidentialspace.Roots()
+	if len(o.Roots) > 0 {
+		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 {
@@ -187,17 +195,20 @@ func (p *ACME) GetRemoteAttestation() *ACMERemoteAttestation {
 }
 
 // VerifyRemoteAttestation verifies the evidence of a remote-attest-01
-// challenge, a CMW record, and returns it with the RemoteAttestationBoundSize
-// bytes it binds:
+// challenge, a CMW record, and returns it with the data it binds: first the
+// RemoteAttestationBindingSize bytes of the binding, then, for a TDX quote or an
+// SEV-SNP report, the relying party's RemoteAttestationClaimNonceSize bytes.
 //
 //   - 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.
+//     (application/vnd.veraison.tsm-report+json or +cbor), its 64 bytes of
+//     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.
+//     its first eat_nonce value, the base64url encoding, without padding, of 32
+//     bytes. Its other nonces are the relying party's and stay in the claims.
+//     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
+// The caller checks what the binding 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
@@ -210,21 +221,24 @@ func (p *ACME) VerifyRemoteAttestation(ctx context.Context, r *cmw.Record, defau
 	var (
 		res   *attestation.Result
 		bound []byte
+		size  int
 		err   error
 	)
 	switch {
 	case tsm.IsMediaType(r.MediaType):
 		res, bound, err = v.verifyTSMReport(ctx, r)
+		size = RemoteAttestationBindingSize + RemoteAttestationClaimNonceSize
 	case isJWTMediaType(r.MediaType):
 		res, bound, err = v.verifyConfidentialSpace(r, defaultAudience)
+		size = RemoteAttestationBindingSize
 	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)
+	if len(bound) != size {
+		return nil, nil, attestation.Invalidf("evidence binds %d bytes, not %d", len(bound), size)
 	}
 	res.MediaType = r.MediaType
 	res.Evidence = r.Value
@@ -289,7 +303,7 @@ func (v *remoteAttestationVerifier) verifyConfidentialSpace(r *cmw.Record, defau
 		Roots:       v.csRoots,
 		Audience:    audience,
 		MaxTokenAge: v.csMaxAge,
-		MinNonces:   2,
+		MinNonces:   1,
 		Now:         v.now(),
 	})
 	if err != nil {
@@ -299,13 +313,9 @@ func (v *remoteAttestationVerifier) verifyConfidentialSpace(r *cmw.Record, defau
 		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...)
+	bound, err := base64.RawURLEncoding.DecodeString(tok.Claims.EATNonce[0])
+	if err != nil || len(bound) != RemoteAttestationBindingSize {
+		return nil, nil, attestation.Invalidf("eat_nonce[0] is not the base64url encoding of %d bytes", RemoteAttestationBindingSize)
 	}
 	return &attestation.Result{
 		Format:            attestation.FormatConfidentialSpace,

+ 31 - 13
authority/provisioner/acme_remote_attestation_test.go

@@ -102,9 +102,10 @@ func TestACME_Init_remoteAttestation(t *testing.T) {
 			&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"},
+		// Google's root is pinned, so the format needs no configuration.
+		{"ok confidential space with the pinned root", []ACMEChallenge{REMOTE_ATTEST_01},
+			&ACMERemoteAttestation{Formats: []attestation.Format{attestation.FormatConfidentialSpace}},
+			[]attestation.Format{attestation.FormatConfidentialSpace}, ""},
 		{"fail confidential space roots", []ACMEChallenge{REMOTE_ATTEST_01},
 			&ACMERemoteAttestation{ConfidentialSpace: &ACMEConfidentialSpace{Roots: []byte("not pem")}}, nil,
 			"no certificates found in confidentialSpace.roots"},
@@ -170,11 +171,11 @@ func TestACME_AuthorizeOrderIdentifier_remoteAttestation(t *testing.T) {
 func TestACME_VerifyRemoteAttestation_confidentialSpace(t *testing.T) {
 	pki := cstest.New(t)
 	now := time.Now()
-	bound := testBound()
+	// The binding first, then the relying party's own nonces.
+	bound := testBound()[:RemoteAttestationBindingSize]
 	nonces := []string{
-		base64.RawURLEncoding.EncodeToString(bound[:32]),
-		base64.RawURLEncoding.EncodeToString(bound[32:]),
-		"extra-nonce",
+		base64.RawURLEncoding.EncodeToString(bound),
+		"relying-party-nonce",
 	}
 	newProv := func(cs *ACMEConfidentialSpace) *ACME {
 		cs.Roots = pki.RootPEM()
@@ -206,6 +207,23 @@ func TestACME_VerifyRemoteAttestation_confidentialSpace(t *testing.T) {
 		assert.Equal(t, bound, gotBound)
 	})
 
+	t.Run("ok binding alone", func(t *testing.T) {
+		_, gotBound, err := newProv(&ACMEConfidentialSpace{}).VerifyRemoteAttestation(context.Background(),
+			jsonCMW("application/eat+jwt", mint(testRemoteAttestationAudience, nonces[0]), 0), testRemoteAttestationAudience)
+		require.NoError(t, err)
+		assert.Equal(t, bound, gotBound)
+	})
+
+	t.Run("fail token under another root than Google's", func(t *testing.T) {
+		// Without configured roots the provisioner trusts only Google Cloud
+		// Attestation's pinned root, so the test PKI's token is refused.
+		p := newRemoteAttestationACME(t, &ACMERemoteAttestation{ConfidentialSpace: &ACMEConfidentialSpace{}}, staticHTTPClient{})
+		_, _, err := p.VerifyRemoteAttestation(context.Background(),
+			jsonCMW("application/eat+jwt", mint(testRemoteAttestationAudience, nonces...), 0), testRemoteAttestationAudience)
+		assert.ErrorContains(t, err, "attestation token x5c is not valid")
+		assert.ErrorIs(t, err, attestation.ErrInvalidEvidence)
+	})
+
 	tests := []struct {
 		name    string
 		cs      *ACMEConfidentialSpace
@@ -217,12 +235,12 @@ func TestACME_VerifyRemoteAttestation_confidentialSpace(t *testing.T) {
 			"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{},
+		{"fail no nonce", &ACMEConfidentialSpace{},
+			jsonCMW("application/eat+jwt", mint(testRemoteAttestationAudience), 0), "between 1 and 6 nonces"},
+		{"fail binding encoding", &ACMEConfidentialSpace{},
+			jsonCMW("application/eat+jwt", mint(testRemoteAttestationAudience, "SHA256:"+nonces[0], nonces[1]), 0),
+			"eat_nonce[0] is not the base64url encoding of 32 bytes"},
+		{"fail binding 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{

+ 13 - 6
test/integration/remote_attestation_test.go

@@ -184,18 +184,19 @@ func TestRemoteAttestation(t *testing.T) {
 	require.NotEmpty(t, ch.FreshnessNonce)
 	assert.Equal(t, []string{"hwmodel", "submods"}, ch.AttestClaimsHint)
 
-	// The workload's key, and the two digests its evidence binds.
+	// The workload's key, and the binding its evidence carries first:
+	// SHA-256 of the key authorization followed by the key's DER
+	// SubjectPublicKeyInfo. The relying party's own nonce follows.
 	certKey, err := keyutil.GenerateDefaultSigner()
 	require.NoError(t, err)
 	keyAuth, err := acme.KeyAuthorization(ch.FreshnessNonce, client.Key)
 	require.NoError(t, err)
-	keyAuthDigest := sha256.Sum256([]byte(keyAuth))
 	spki, err := x509.MarshalPKIXPublicKey(certKey.Public())
 	require.NoError(t, err)
-	keyDigest := sha256.Sum256(spki)
+	binding := sha256.Sum256(append([]byte(keyAuth), spki...))
 	token := attestor.Mint(t, cstest.Claims(time.Now(), directory,
-		base64.RawURLEncoding.EncodeToString(keyAuthDigest[:]),
-		base64.RawURLEncoding.EncodeToString(keyDigest[:]),
+		base64.RawURLEncoding.EncodeToString(binding[:]),
+		"relying-party-nonce",
 	))
 	payload, err := json.Marshal([]any{"application/eat+jwt", base64.RawURLEncoding.EncodeToString([]byte(token)), 8})
 	require.NoError(t, err)
@@ -241,7 +242,13 @@ func TestRemoteAttestation(t *testing.T) {
 	assert.Equal(t, "remote-attest-01", got.Challenge)
 	assert.Equal(t, "measured_boot", got.Hint)
 	assert.Equal(t, ch.FreshnessNonce, got.FreshnessNonce)
-	assert.Equal(t, fmt.Sprintf("%x", keyDigest), got.KeyDigest)
+	assert.Equal(t, keyAuth, got.KeyAuthorization)
+	assert.Equal(t, fmt.Sprintf("%x", binding), got.BindingDigest)
+	assert.Empty(t, got.ClaimNonce)
+	require.NotNil(t, got.Account)
+	assert.NotEmpty(t, got.Account.ID)
+	assert.Empty(t, got.Account.Reference)
+	assert.Equal(t, []any{base64.RawURLEncoding.EncodeToString(binding[:]), "relying-party-nonce"}, got.ConfidentialSpace.Claims["eat_nonce"])
 	assert.Equal(t, attestation.FormatConfidentialSpace, got.Format)
 	assert.Equal(t, []byte(token), got.Evidence)
 	require.NotNil(t, got.ConfidentialSpace)

+ 11 - 7
webhook/attestation_test.go

@@ -12,11 +12,13 @@ import (
 
 func TestWithAttestation(t *testing.T) {
 	a := &Attestation{
-		Challenge:              "remote-attest-01",
-		Hint:                   "measured_boot",
-		FreshnessNonce:         "nonce",
-		KeyAuthorizationDigest: "00",
-		KeyDigest:              "01",
+		Challenge:        "remote-attest-01",
+		Hint:             "measured_boot",
+		FreshnessNonce:   "nonce",
+		KeyAuthorization: "nonce.thumbprint",
+		BindingDigest:    "00",
+		ClaimNonce:       "claim",
+		Account:          &AttestationAccount{ID: "account", ExternalAccountKeyID: "eak", Reference: "machine-1"},
 		Result: &attestation.Result{
 			Format:    attestation.FormatTDX,
 			MediaType: "application/vnd.veraison.tsm-report+json",
@@ -38,8 +40,10 @@ func TestWithAttestation(t *testing.T) {
 	assert.Equal(t, "remote-attest-01", att["challenge"])
 	assert.Equal(t, "measured_boot", att["hint"])
 	assert.Equal(t, "nonce", att["freshnessNonce"])
-	assert.Equal(t, "00", att["keyAuthorizationDigest"])
-	assert.Equal(t, "01", att["keyDigest"])
+	assert.Equal(t, "nonce.thumbprint", att["keyAuthorization"])
+	assert.Equal(t, "00", att["bindingDigest"])
+	assert.Equal(t, "claim", att["claimNonce"])
+	assert.Equal(t, map[string]any{"id": "account", "externalAccountKeyID": "eak", "reference": "machine-1"}, att["account"])
 	assert.Equal(t, "tdx", att["format"])
 	assert.Equal(t, "application/vnd.veraison.tsm-report+json", att["mediaType"])
 	assert.Equal(t, "cXVvdGU=", att["evidence"])

+ 30 - 11
webhook/types.go

@@ -75,11 +75,15 @@ type AttestationData struct {
 // verified (draft-ietf-acme-rats), sent to webhook servers when the order is
 // finalized and given to certificate templates as .Attestation.
 //
-// The evidence binds two SHA-256 digests: of the challenge's key authorization,
-// and of the DER SubjectPublicKeyInfo of the certificate's key. The CA has
-// checked both, so the certificate's key is the attested one. Binary values are
-// hex encoded. The fields of the embedded attestation.Result, the format and the
-// verified measurements or claims, are at the top level.
+// The evidence binds BindingDigest, SHA-256 of the challenge's key
+// authorization followed by the DER SubjectPublicKeyInfo of the certificate's
+// key. The CA has checked it against the certificate request, so the evidence is
+// fresh, is the account's, and attests the certificate's key. A TDX quote or an
+// SEV-SNP report also carries the relying party's ClaimNonce, which the CA does
+// not interpret; a Confidential Space token carries the relying party's nonces
+// after the binding in its eat_nonce claim. Binary values are hex encoded,
+// except the nonces. The fields of the embedded attestation.Result, the format
+// and the verified measurements or claims, are at the top level.
 type Attestation struct {
 	// Challenge is the challenge type that verified the evidence,
 	// remote-attest-01.
@@ -88,15 +92,30 @@ type Attestation struct {
 	Hint string `json:"hint"`
 	// FreshnessNonce is the challenge's freshness nonce.
 	FreshnessNonce string `json:"freshnessNonce"`
-	// KeyAuthorizationDigest is the SHA-256 digest of the challenge's key
-	// authorization, which the evidence binds.
-	KeyAuthorizationDigest string `json:"keyAuthorizationDigest"`
-	// KeyDigest is the SHA-256 digest of the DER SubjectPublicKeyInfo of the
-	// certificate's key, which the evidence binds.
-	KeyDigest string `json:"keyDigest"`
+	// KeyAuthorization is the challenge's key authorization: the freshness
+	// nonce, a period, and the account key's thumbprint.
+	KeyAuthorization string `json:"keyAuthorization"`
+	// BindingDigest is SHA-256 of the key authorization followed by the DER
+	// SubjectPublicKeyInfo of the certificate's key, which the evidence binds.
+	BindingDigest string `json:"bindingDigest"`
+	// ClaimNonce is the second half of a TDX quote's or SEV-SNP report's
+	// report data, base64url encoded without padding.
+	ClaimNonce string `json:"claimNonce,omitempty"`
+	// Account is the ACME account that ordered the certificate.
+	Account *AttestationAccount `json:"account,omitempty"`
 	*attestation.Result
 }
 
+// AttestationAccount is the ACME account of an attested order, and the external
+// account binding key it was created with, if any.
+type AttestationAccount struct {
+	ID string `json:"id"`
+	// ExternalAccountKeyID and Reference identify the EAB key the account was
+	// created with.
+	ExternalAccountKeyID string `json:"externalAccountKeyID,omitempty"`
+	Reference            string `json:"reference,omitempty"`
+}
+
 // X5CCertificate is the authorization certificate sent to webhook servers for
 // enriching or authorizing webhooks when signing X509 or SSH certificates using
 // the X5C provisioner.