Преглед изворни кода

Refuse orders from an account whose EAB key was removed

Under a provisioner that requires EAB, removing an EAB key did not stop
the account created with it: new-order read the account's key and went
on without one, and Step CA Pro's lookup even found the removed key,
whose row it only marks deleted. Removing a key was therefore no way to
stop the client that registered with it from ordering.

New-order and remote-attest-01's finalize now refuse, with unauthorized,
an account without a key under such a provisioner. This changes
behaviour: an account created before its provisioner began to require
EAB, which has no key, can no longer order there.

Found by an adversarial review.

Claude-Session: https://claude.ai/code/session_01CjfEMLGpnHQaWsmxe1zmLF
Josh Drake пре 1 месец
родитељ
комит
40634b8c92
4 измењених фајлова са 49 додато и 5 уклоњено
  1. 7 0
      acme/api/order.go
  2. 30 1
      acme/api/order_test.go
  3. 6 0
      acme/challenge_remote_attestation_test.go
  4. 6 4
      acme/order.go

+ 7 - 0
acme/api/order.go

@@ -228,12 +228,19 @@ func NewOrder(w http.ResponseWriter, r *http.Request) {
 		return
 	}
 
+	// Under a provisioner that requires EAB, an account orders only while the
+	// key it was created with exists: removing the key revokes the account.
 	var eak *acme.ExternalAccountKey
 	if acmeProv.RequireEAB {
 		if eak, err = db.GetExternalAccountKeyByAccountID(ctx, prov.GetID(), acc.ID); err != nil {
 			render.Error(w, r, acme.WrapErrorISE(err, "error retrieving external account binding key"))
 			return
 		}
+		if eak == nil {
+			render.Error(w, r, acme.NewError(acme.ErrorUnauthorizedType,
+				"account %s has no external account binding key", acc.ID))
+			return
+		}
 	}
 
 	acmePolicy, err := newACMEPolicyEngine(eak)

+ 30 - 1
acme/api/order_test.go

@@ -1221,6 +1221,34 @@ MCowBQYDK2VwAyEA5c+4NKZSNQcR1T8qN6SjwgdPZQ0Ge12Ylx/YeGAJ35k=
 				err: acme.NewErrorISE("error retrieving external account binding key: force"),
 			}
 		},
+		// Under a provisioner that requires EAB, an account whose key was
+		// removed no longer orders.
+		"fail/eab-removed": func(t *testing.T) test {
+			acmeProv := newACMEProv(t)
+			acmeProv.RequireEAB = true
+			acc := &acme.Account{ID: "accID"}
+			fr := &NewOrderRequest{
+				Identifiers: []acme.Identifier{
+					{Type: "dns", Value: "zap.internal"},
+				},
+			}
+			b, err := json.Marshal(fr)
+			assert.FatalError(t, err)
+			ctx := acme.NewProvisionerContext(context.Background(), acmeProv)
+			ctx = context.WithValue(ctx, accContextKey, acc)
+			ctx = context.WithValue(ctx, payloadContextKey, &payloadInfo{value: b})
+			return test{
+				ctx:        ctx,
+				statusCode: 401,
+				ca:         &mockCA{},
+				db: &acme.MockDB{
+					MockGetExternalAccountKeyByAccountID: func(ctx context.Context, provisionerID, accountID string) (*acme.ExternalAccountKey, error) {
+						return nil, nil
+					},
+				},
+				err: acme.NewError(acme.ErrorUnauthorizedType, "account accID has no external account binding key"),
+			}
+		},
 		"fail/newACMEPolicyEngine-error": func(t *testing.T) test {
 			acmeProv := newACMEProv(t)
 			acmeProv.RequireEAB = true
@@ -2310,7 +2338,8 @@ MCowBQYDK2VwAyEA5c+4NKZSNQcR1T8qN6SjwgdPZQ0Ge12Ylx/YeGAJ35k=
 					MockGetExternalAccountKeyByAccountID: func(ctx context.Context, provisionerID, accountID string) (*acme.ExternalAccountKey, error) {
 						assert.Equals(t, prov.GetID(), provisionerID)
 						assert.Equals(t, "accID", accountID)
-						return nil, nil
+						// The account has the EAB key it was created with.
+						return &acme.ExternalAccountKey{ID: "eakID", AccountID: "accID"}, nil
 					},
 				},
 				vr: func(t *testing.T, o *acme.Order) {

+ 6 - 0
acme/challenge_remote_attestation_test.go

@@ -398,6 +398,12 @@ func TestOrder_Finalize_remoteAttestation(t *testing.T) {
 		assert.Equal(t, StatusValid, o.Status)
 	})
 
+	// A key removed since the order was created revokes the account.
+	t.Run("fail eab removed", func(t *testing.T) {
+		err := newOrder().Finalize(context.Background(), newDB(nil, nil), csr, &mockSignAuth{}, eabProv)
+		assert.ErrorContains(t, err, "has no external account binding key")
+	})
+
 	t.Run("fail eab lookup", func(t *testing.T) {
 		err := newOrder().Finalize(context.Background(), newDB(nil, errors.New("force")), csr, &mockSignAuth{}, eabProv)
 		assert.ErrorContains(t, err, "error getting the external account key")

+ 6 - 4
acme/order.go

@@ -195,7 +195,8 @@ func (o *Order) checkAttestedKeys(ctx context.Context, db DB, csr *x509.Certific
 // remote-attest-01 order, with the external account binding key the account
 // was created with, if any. As for new orders, the key is read only if the
 // provisioner requires one: some databases report an account without a key as
-// an error.
+// an error. A key removed since the order was created revokes the account, so
+// the order does not finalize.
 func (o *Order) attestationAccount(ctx context.Context, db DB, p Provisioner) (*webhook.AttestationAccount, error) {
 	account := &webhook.AttestationAccount{ID: o.AccountID}
 	if !p.IsEABRequired() {
@@ -205,10 +206,11 @@ func (o *Order) attestationAccount(ctx context.Context, db DB, p Provisioner) (*
 	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
+	if eak == nil {
+		return nil, NewError(ErrorUnauthorizedType, "account %s has no external account binding key", o.AccountID)
 	}
+	account.ExternalAccountKeyID = eak.ID
+	account.Reference = eak.Reference
 	return account, nil
 }