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

Keep a stored attestation on nosql authorization updates

UpdateAuthorization copied the caller's attestation over the stored one.
GetAuthorization reads an authorization and then its challenges, not
atomically, and an order's status update writes the authorization back,
so a copy read just before the remote-attest-01 challenge validated, with
its challenge read just after, saved the authorization valid without the
attestation. Finalize now refuses such an authorization, so this only cost
the order; an attestation, once stored, is no longer cleared.

Claude-Session: https://claude.ai/code/session_01CjfEMLGpnHQaWsmxe1zmLF
Josh Drake 1 месяц назад
Родитель
Сommit
15ad7fa097
2 измененных файлов с 14 добавлено и 1 удалено
  1. 5 1
      acme/db/nosql/authz.go
  2. 9 0
      acme/db/nosql/challenge_remote_attestation_test.go

+ 5 - 1
acme/db/nosql/authz.go

@@ -121,7 +121,11 @@ func (db *DB) UpdateAuthorization(ctx context.Context, az *acme.Authorization) e
 	nu := old.clone()
 	nu.Status = az.Status
 	nu.Fingerprint = az.Fingerprint
-	nu.Attestation = az.Attestation
+	// An attestation, once stored, is never cleared: a status update from a
+	// copy read before the challenge validated would otherwise erase it.
+	if az.Attestation != nil {
+		nu.Attestation = az.Attestation
+	}
 	nu.Error = az.Error
 	return db.save(ctx, old.ID, nu, old, "authz", authzTable)
 }

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

@@ -95,6 +95,15 @@ func TestDB_Authorization_remoteAttestation(t *testing.T) {
 	got, err := d.GetAuthorization(context.Background(), az.ID)
 	require.NoError(t, err)
 	assert.Equal(t, att, got.Attestation)
+
+	// A status update from a copy read before the challenge validated, as
+	// an order's status update may write, keeps the stored attestation.
+	stale := *az
+	stale.Attestation = nil
+	require.NoError(t, d.UpdateAuthorization(context.Background(), &stale))
+	got, err = d.GetAuthorization(context.Background(), az.ID)
+	require.NoError(t, err)
+	assert.Equal(t, att, got.Attestation)
 }
 
 // TestDB_GetExternalAccountKeyByAccountID checks that the EAB key an account