Returning a license seat with a signed receipt
Every seat-based license eventually has to answer a deceptively simple request: "I bought a new laptop — move my license to it." The honest version is a seat transfer: release the seat on the old machine, claim one on the new machine. The dishonest version looks identical from the client's side — deactivate the old one in name only, keep it running, and now one purchased seat is doing the work of two. The difference between the two is invisible to anyone who trusts the client's word.
So the design question is not "how does a client deactivate." It is: who is allowed to say a seat is free, and what proof does the honest user get that they did the right thing? If the answer to the first is "the client," the system is already broken. The answer has to be the issuing service — and the honest user, who did release their seat, deserves a verifiable artifact that says so, for the day the move goes wrong and they are standing in front of a seat limit reached error insisting they deactivated the old machine.
A seat is a row the service owns
A Keyright device seat is a row on the issuing service. The two fields that make deactivation safe are the device key the seat is bound to and a generation counter:
public sealed record Seat( Guid SeatId, Guid LicenseId, string DeviceFingerprint, byte[] DevicePublicKey, // the key this device proved possession of at activation long Generation, // monotonic; retiring a seat bumps it DateTimeOffset ActivatedAt); The client never deletes this row and never flips a flag the service reads as truth. The client asks, and the service is the only thing that frees the seat. That single rule is what separates a seat return from a promise.
The online deactivation, and the receipt it returns
When the user clicks deactivate this device, the SDK calls the service. The service deletes the seat (or marks it returned and bumps its generation), then mints a deactivation receipt — a small, signed statement that this seat was returned:
public sealed record DeactivationReceipt( Guid SeatId, Guid LicenseId, string DeviceFingerprint, long RetiredGeneration, DateTimeOffset ReturnedAt, // service clock, authoritative string Nonce) // single-use, ties this receipt to this request { public byte[] Signature { get; init; } = Array.Empty<byte>(); } // Service-side. The seat deletion and the receipt are one transaction. public async Task<DeactivationReceipt> DeactivateAsync( Guid licenseId, Guid seatId, string nonce, CancellationToken ct) { await using var tx = await _store.BeginSerializableTransactionAsync(ct); // Idempotency: a retried deactivation returns the SAME receipt, frees nothing twice. if (await _nonces.TryGetReceiptAsync(licenseId, nonce, ct) is { } prior) { await tx.CommitAsync(ct); return prior; } var seat = await _store.FindSeatForUpdateAsync(licenseId, seatId, ct); if (seat is null) throw new SeatNotFoundException(seatId); // already returned, or never existed await _store.RetireSeatAsync(seat, ct); // row gone; generation retired var receipt = new DeactivationReceipt( seat.SeatId, seat.LicenseId, seat.DeviceFingerprint, RetiredGeneration: seat.Generation, ReturnedAt: _clock.UtcNow, Nonce: nonce) { Signature = _signer.Sign(CanonicalBytes(seat, nonce, _clock.UtcNow)) }; await _nonces.StoreReceiptAsync(licenseId, nonce, receipt, ct); // consume the nonce await tx.CommitAsync(ct); return receipt; } Two properties are doing the work. The seat deletion and the receipt live in one serializable transaction, so there is no state in which the seat is freed but no receipt was issued, or a receipt exists for a seat still held. And the request's nonce is consumed and bound to the receipt, so a retried call — the user's flaky Wi‑Fi dropped the first response — returns the identical receipt rather than attempting a second return. Deactivation is idempotent by construction.
The client's job is to verify the signature against the pinned service key, stop using the license locally, and persist the receipt:
var receipt = await _seats.DeactivateAsync(_seatId, ct); if (!_verifier.Verify(receipt, CanonicalBytes(receipt))) throw new InvalidReceiptException(); // fail closed: an unverifiable receipt is no receipt _licenseState.MarkDeactivated(); // this device stops here, not on the server's say-so await _receiptStore.SaveAsync(receipt, ct); // kept as proof Reactivation checks the seat is genuinely free
When the user activates on the new machine, the receipt plays no part in the decision. The service runs its ordinary admit path and counts live seats — the retired seat is gone, so there is room, and activation grants a brand-new seat at a new generation:
// New device activates. The returned seat no longer counts; a fresh seat is minted. public async Task<Seat> ActivateAsync( Guid licenseId, string fingerprint, byte[] devicePublicKey, int seatCap, CancellationToken ct) { await using var tx = await _store.BeginSerializableTransactionAsync(ct); var live = await _store.CountLiveSeatsForUpdateAsync(licenseId, ct); if (live >= seatCap) throw new SeatCapReachedException(live, seatCap); // genuinely full; no ghost from the return var seat = await _store.InsertSeatAsync( licenseId, fingerprint, devicePublicKey, generation: await _store.NextGenerationAsync(licenseId, ct), // monotonic, never reused _clock.UtcNow, ct); await tx.CommitAsync(ct); return seat; } The generation is what defeats replay. Suppose an attacker captured the old device's activation response or its seat token. Replaying it later tries to assert seat S at generation 7 — but generation 7 was retired on return, and NextGenerationAsync never hands out 7 again. The replayed token matches no live row, and every verification keyed on (SeatId, Generation) fails closed. A returned seat cannot be resurrected by a message anyone recorded while it was alive.
The offline case: a locally-signed intent
The hardest version is a user who wants to move the license while the old machine has no network — on a plane, or a machine being decommissioned. The old machine cannot reach the service to free the seat, but it can do the one thing that matters for honesty: stop using the license right now.
It records a deactivation intent, signed with the device key the seat was bound to at activation, and fails closed locally:
public sealed record DeactivationIntent( Guid SeatId, Guid LicenseId, long Generation, DateTimeOffset RequestedAt, string Nonce) { public byte[] DeviceSignature { get; init; } = Array.Empty<byte>(); } // Offline path on the old device. public async Task DeactivateOfflineAsync(CancellationToken ct) { var intent = new DeactivationIntent(_seatId, _licenseId, _generation, _clock.UtcNow, Nonce.New()); intent = intent with { DeviceSignature = _deviceKey.Sign(CanonicalBytes(intent)) }; _licenseState.MarkDeactivated(); // STOP using the license immediately await _pending.EnqueueAsync(intent, ct); // reconcile when a path to the service opens } Because the device signs the intent with the key it proved possession of at activation (see proof-of-possession device binding), the intent is unforgeable evidence that this device asked to release this seat. The seat is not free on the service yet — honesty on the client does not change server state — but the intent can reach the service by either route: the old machine reconnects and submits it, or the user carries the signed intent to the new machine, which uploads it on the old device's behalf. The service verifies the device signature, retires the seat, consumes the nonce, and issues the real receipt:
// Service-side reconciliation of an offline intent. public async Task<DeactivationReceipt> ReconcileAsync(DeactivationIntent intent, CancellationToken ct) { var seat = await _store.FindSeatAsync(intent.LicenseId, intent.SeatId, ct); if (seat is null || seat.Generation != intent.Generation) throw new StaleIntentException(); // already returned, or a replay of an old generation if (!Ed25519.Verify(intent.DeviceSignature, CanonicalBytes(intent), seat.DevicePublicKey)) throw new InvalidIntentException(); // only the bound device can release its seat return await DeactivateAsync(intent.LicenseId, intent.SeatId, intent.Nonce, ct); } This is the honest shape of offline transfer: the decision to stop is instant and local, but the seat is only freed once the signed intent reaches the service. Until then the new machine may hit seat cap reached — which is correct, not a bug. The seat was never double-counted; it was just not yet returned.
How you wire it
- Pin the service key and verify every receipt before trusting it; an unverifiable receipt is treated as no receipt. Reuse the pinning you already do for license verification (pinning the verification key).
- Persist receipts next to the license cache and surface them in the UI — "this device was deactivated on 12 March; receipt #…". That string is what a support agent cross-checks against the service record.
- Always carry a fresh nonce on deactivation so retries are idempotent and replays are inert.
- Device-sign offline intents with the activation key, never a shared secret, so reconciliation can attribute the release to exactly one device.
When this breaks, honestly
Offline deactivation is not an instant seat. If the old machine never reconnects and the user never transfers the signed intent, the seat stays held until it is reclaimed some other way — a stale-seat eviction or an admin action. The intent frees nothing on its own; it only frees the seat once it reaches the service. Set expectations in the UI accordingly.
The receipt is proof, not a bearer token. It cannot be redeemed for a seat and must never be accepted as one. If a future feature lets a receipt "pre-authorize" an activation, it becomes a replayable credential — exactly the thing the generation counter exists to prevent. Keep the receipt on the proof side of the line.
A compromised device key forges intents for its own seat only. The device signature proves which seat is being released, not that the human meant to release it; malware on the old machine could sign a release. That is contained — it can only return that device's seat, which it already controlled — but it is the reason the device key must live in the platform key store, not a file next to the app.
Takeaway
A seat return cannot rest on the client's word, because the honest and dishonest clients say the same words. Make the issuing service the only authority that frees a seat; have it return a signed receipt — seat id, server timestamp, single-use nonce — so the honest user holds verifiable proof when a transfer goes sideways. Bump a monotonic generation on every return so a captured token can never be replayed into a retired seat, and let an offline device fail closed locally while a device-signed intent reconciles the server state on reconnect. The user moves their license to the new laptop, the old seat is genuinely free, and the receipt in their settings pane is the difference between a two-minute support call and an argument nobody can win. See the seat-management options in the Keyright docs and the licensing model on the Keyright product page.
原文:https://www.a8q9.cn/en/article/returning-a-license-seat-with-a-signed-receipt-fc3bf4.html