4
0
Эх сурвалжийг харах

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 сар өмнө
parent
commit
15ad7fa097

+ 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 := old.clone()
 	nu.Status = az.Status
 	nu.Status = az.Status
 	nu.Fingerprint = az.Fingerprint
 	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
 	nu.Error = az.Error
 	return db.save(ctx, old.ID, nu, old, "authz", authzTable)
 	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)
 	got, err := d.GetAuthorization(context.Background(), az.ID)
 	require.NoError(t, err)
 	require.NoError(t, err)
 	assert.Equal(t, att, got.Attestation)
 	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
 // TestDB_GetExternalAccountKeyByAccountID checks that the EAB key an account