Stapled freshness proofs for offline licenses
A long-lived license proves what a customer bought, but it cannot prove it is still valid today — the moment you sign a key good for a year, you have promised a year, revocation or not. Keyright solves this the way TLS solved certificate revocation: a short-lived, separately signed validity staple attached to the long-lived key, verified entirely offline, refreshed in the background. Revoking a license becomes flipping one row, with no ever-growing blocklist to distribute and no per-launch call home. This post builds the two-token scheme, the two-key split that keeps it safe, the FixedTimeEquals binding that stops staple replay, and the grace window that keeps offline laptops working.
A signed license key is a promise frozen in bytes: this customer, this product, this edition, valid until this date. The signature makes it unforgeable, and that is exactly the problem. The day you sign a key good for a year, you have promised a year. If the customer charges back, breaches the contract, or you simply issued the wrong tier, the bytes in the field keep verifying perfectly until the expiry you wrote into them. A signature that cannot be forged also cannot be un-signed.
The usual answer is a revocation list: the client downloads a set of revoked key IDs and refuses any match. It works, but it has the shape every certificate-revocation-list deployment eventually regrets. The list only grows. Every client has to fetch it, and a client that cannot reach the list has to decide between failing open (revoked keys keep working) and failing closed (a network blip locks out paying customers). You are distributing a blacklist of your own mistakes, forever, to every install.
The real question
TLS hit this wall a decade ago and the answer that stuck was OCSP stapling: instead of every client asking “is this certificate revoked?”, the server periodically fetches a short-lived, signed “still good” assertion and staples it to the certificate it already serves. The client verifies the staple offline. Revocation is just the server declining to re-staple.
Licensing has the identical shape. A Keyright license can carry two signed objects instead of one: a long-lived entitlement token that proves what was bought, and a short-lived validity staple that proves it has not been revoked recently. The client verifies both with pinned public keys, entirely offline. Revoking a license stops being a list you distribute and becomes a row you flip.
Two tokens, two keys
The entitlement token is the license you already issue. Keep it as it is — signed over its canonical bytes, good for however long the customer paid for.
public sealed record LicenseToken
{
public required string Id { get; init; } // stable, unique per issued license
public required string Sub { get; init; } // customer id
public required string Product { get; init; }
public required string Edition { get; init; } // "pro", "team", ...
public required DateTimeOffset Exp { get; init; } // the real purchased term
}
The staple is new and deliberately tiny. It says nothing about entitlements — only that this specific license was not revoked as of a very recent moment.
public sealed record ValidityStaple
{
public required string LicenseId { get; init; } // which license this vouches for
public required byte[] LicenseHash { get; init; } // SHA-256 of the license's signed bytes
public required DateTimeOffset IssuedAt { get; init; }
public required DateTimeOffset NotAfter { get; init; } // IssuedAt + a day or so
}
The two objects are signed by different keys, and that split is the heart of the design. Ke, the entitlement key, proves what was bought; it signs rarely — once per issued license — so it can live offline, in cold storage, rotated on a multi-year cadence. Ks, the staple key, signs constantly, every few hours per active install, so it must be online and hot. Keeping them separate means the hot key is not the valuable one. If Ks leaks, an attacker can forge “still valid” assertions but cannot mint a single entitlement — they can keep an already-issued license alive, not conjure a Pro tier from nothing — and you rotate Ks aggressively without ever touching the long-lived key your entire installed base has pinned.
Verifying both, offline
The client holds two pinned public keys and runs four checks. Verify each signature over the raw bytes it was signed over; never re-serialize and verify the round-trip. (The canonical-serialization post covers why that distinction is not optional.)
public static LicenseState Verify(
ReadOnlySpan<byte> licenseBytes, ReadOnlySpan<byte> licenseSig,
ReadOnlySpan<byte> stapleBytes, ReadOnlySpan<byte> stapleSig,
EntitlementKey ke, StapleKey ks, TimeProvider clock, TimeSpan grace)
{
// 1. The license proves entitlement.
if (!ke.Verify(licenseBytes, licenseSig))
return LicenseState.Community(Reason.BadSignature);
var license = Canonical.Read<LicenseToken>(licenseBytes);
// 2. The staple proves freshness — signed by a different key.
if (!ks.Verify(stapleBytes, stapleSig))
return LicenseState.Community(Reason.BadStapleSignature);
var staple = Canonical.Read<ValidityStaple>(stapleBytes);
// 3. Bind the staple to THIS license. Constant-time: the hash is attacker-influenced.
var actualHash = SHA256.HashData(licenseBytes);
if (!CryptographicOperations.FixedTimeEquals(actualHash, staple.LicenseHash)
|| !string.Equals(staple.LicenseId, license.Id, StringComparison.Ordinal))
return LicenseState.Community(Reason.StapleMismatch);
// 4. Freshness. The staple's own TTL, plus the offline grace you chose.
var now = clock.GetUtcNow();
if (now > staple.NotAfter + grace)
return LicenseState.Community(Reason.StapleStale);
// The license's real term still applies on top of all this.
if (now > license.Exp)
return LicenseState.Community(Reason.Expired);
return LicenseState.Paid(license.Edition, license);
}
Step 3 is the one people skip. Without binding the staple to the license, a valid staple from any active license would satisfy the freshness check on a revoked one — lift a staple off your own live install, paste it onto a cancelled key, and the cancelled key reads fresh. Binding by the license’s content hash closes that, and CryptographicOperations.FixedTimeEquals does the comparison in constant time because the stored hash is an attacker-controlled input and a byte-by-byte == leaks how far it matched.
Note what step 4 does not require: a network. Every check runs against bytes already on disk. A machine that has been offline for less than the staple TTL plus the grace window verifies exactly as it would online.
Minting and refreshing
On the server, minting a staple is a status check and a signature. This is the only place revocation lives — there is no list, just the question “is this license still active right now?”
public StapleResponse Mint(string licenseId, TimeProvider clock)
{
var lic = _store.Find(licenseId)
?? throw new NotFoundException(licenseId);
// The entire revocation mechanism is this one line.
if (lic.Status is not LicenseStatus.Active)
throw new RevokedException(licenseId, lic.Status);
var now = clock.GetUtcNow();
var staple = new ValidityStaple
{
LicenseId = lic.Id,
LicenseHash = lic.SignedHash, // computed when the license was issued
IssuedAt = now,
NotAfter = now + _options.StapleTtl, // e.g. 24 hours
};
var bytes = Canonical.Write(staple);
return new StapleResponse(bytes, _stapleKey.Sign(bytes));
}
On the client, a background service keeps the staple fresh while the app runs and the network is up. It refreshes well before expiry so a brief outage never costs the user access, and a 410 Gone tells it the license is revoked — at which point it discards the stored staple and lets the next verification fall through to Community Edition.
protected override async Task ExecuteAsync(CancellationToken ct)
{
// Refresh at a third of the TTL, so two consecutive failures still leave headroom.
using var timer = new PeriodicTimer(_options.StapleTtl / 3);
do
{
try
{
var res = await _client.RefreshStapleAsync(_license.Id, ct);
await _cache.StoreStapleAsync(res.Bytes, res.Signature, ct);
}
catch (RevokedException)
{
await _cache.DropStapleAsync(ct); // next Verify() → Community
return;
}
catch (HttpRequestException) { /* transient: keep the current staple, retry next tick */ }
} while (await timer.WaitForNextTickAsync(ct));
}
Revocation latency is now bounded and tunable: the maximum time a revoked license keeps working is one staple TTL plus the grace window, regardless of how many licenses you have ever revoked. A 24-hour TTL with a 7-day grace means a cancelled license dies within eight days even on a laptop that never reconnects, and within hours on one that is online. You never ship a growing blacklist, and the common case — an honest, connected customer — makes no revocation call at all, because the background refresh they already run is the check.
Where it breaks, and the honest limits
Stapling moves the problem, it does not delete it. The staple TTL is a straight trade between revocation latency and offline tolerance, and there is no setting that is good at both — a 30-day staple that a disconnected build farm loves is a 30-day window in which a charged-back license keeps running. Pick the TTL for the worst revocation you actually need to act on, not the average.
The scheme also assumes the client’s clock is not wildly wrong, because freshness is a time comparison. A machine with its clock rolled back a week will accept a staple that should be stale. That is the same exposure every expiry-based check has, and it is handled the same way — anchor against a monotonic timer and the server’s IssuedAt, as the anti-rollback post describes — not something stapling makes worse, but not something it fixes either.
And Ks being online is a real surface. The mitigation is precisely that it signs nothing of value on its own: a forged staple extends a license that must already exist and already be signed by the offline Ke. Rotate Ks on a short cycle, keep the previous public key pinned for an overlap window so in-flight staples still verify, and the blast radius of a staple-key compromise stays measured in hours.
Takeaway
A license signature proves what a customer bought; it was never meant to prove the purchase still stands. Split those two facts into two signed objects — a long-lived entitlement token under a cold key, a short-lived validity staple under a hot one — bind the staple to its license with a constant-time hash check, and refresh it in the background. Revoking a license collapses to flipping a status row and declining to re-staple. No blocklist leaves your server, no honest customer calls home on a cold launch, and the time a revoked key keeps working is a number you set on purpose rather than one you hope the network delivers.
Try Nebula.NET
Harden your .NET code in minutes — start with the free edition.