Skip to content
← All posts
· Delta1 Labs KeyrightLicensing

Step-up license checks for sensitive operations

A license verified at startup is a statement about the past: it was valid when the app launched, hours or days ago. For most features that is fine. For a narrow class of high-value, irreversible operations — a bulk export, a signed release, a batch of provisioned credentials — you want a stronger assurance that the entitlement is live right now, not merely cached. This post builds a step-up gate in Keyright: a just-in-time, nonce-bound liveness proof that the issuing service mints against a fresh random challenge, bounded by a local stopwatch so the guarantee never rests on the client's wall clock. It sits on top of the ambient entitlement check, not in place of it.

A license checked at startup tells you something true but dated: the entitlement was valid when the process launched. That might have been eight hours ago on a long-running service, or three days ago on a laptop that has been asleep. For opening a window or rendering a document, the cached answer is exactly right — re-checking would only add latency and a pointless network dependency.

But some operations are not like opening a window. Exporting the entire customer database to a file. Publishing a signed release that your downstream consumers will trust. Provisioning a batch of sub-licenses that each become billable. These are rare, expensive, and hard to undo, and for them “valid three days ago” is a weaker statement than you want standing behind the action. If the license was revoked yesterday — a chargeback, a contract breach, a compromised account — the cached state has not caught up, and the most damaging possible operation sails through on stale authority.

The real question

The pattern is familiar from authentication. A session cookie proves you logged in at some point; it is enough to browse. But before you change the account’s email or move money, a well-built app forces a step-up: re-enter your password, approve a push, satisfy a second factor. The ambient session is not revoked — it is simply held to a higher freshness bar for one sensitive action.

Licensing wants the same tiered freshness. The ambient entitlement — the signed license, optionally kept current by a background staple — carries ordinary features. For a declared set of high-value operations, the client demands a fresh, interactive proof that the license is live at this instant, and refuses the operation if it cannot get one. The question this post answers: how do you make “live at this instant” something the client can verify without trusting its own clock, and without a captured proof being replayable a minute later?

clientsensitive op requestedfeature = "export.bulk"1. nonce = GetBytes(32)32 fresh random bytes2. start monotonic stopwatchon reply, four checks:verify sig with pinned Ksnonce echoes mine (const-time)feature + licenseId scope okelapsed < MaxAge (seconds)all pass → run exportany fail → denyissuing serviceon challengestatus == Active? (revocation lives here)sign LivenessProof with Ks:licenseIdfeature = "export.bulk"nonce = (echoed)issuedAt = nowcannot be pre-minted: needs theclient's nonce; revoked → 410 Gone{licId, feature, nonce}proof + Ks signatureOrdinary features skip the round-trip entirely and read the cached, offline-tolerant ambient entitlement state.
Step-up is a challenge-response: the client's random nonce makes the signed proof impossible to pre-mint or replay, and a monotonic stopwatch — not the wall clock — bounds how recently the server vouched for the license.

Ambient versus step-up

Every feature declares the freshness it needs. Most need none beyond the ambient check; a few declare a tight budget and demand liveness.

public sealed record FreshnessPolicy(TimeSpan MaxAge, bool RequireLiveness)
{
    // Ordinary features: accept the background-refreshed ambient state.
    public static readonly FreshnessPolicy Ambient = new(TimeSpan.FromDays(7), RequireLiveness: false);

    // High-value, irreversible operations: prove the license is live, now.
    public static readonly FreshnessPolicy StepUp = new(TimeSpan.FromSeconds(30), RequireLiveness: true);
}

The gate exposes the cheap ambient state as a property and the expensive step-up as a call. The ambient state is whatever your startup verification and (optionally) background validity staple already maintain — step-up sits on top of it, never replaces it.

public interface IEntitlementGate
{
    // Cheap: the ambient, offline-tolerant entitlement state.
    LicenseState Current { get; }

    // Step-up: prove freshness for THIS operation, synchronously, now.
    ValueTask<StepUpResult> RequireFreshAsync(
        string feature, FreshnessPolicy policy, CancellationToken ct);
}

The liveness proof

The object the server signs is deliberately small and scoped to one operation class. It proves nothing about entitlements — the ambient license already does that — only that the issuing service was willing, moments ago, to vouch that this license is active for this feature.

public sealed record LivenessProof
{
    public required string LicenseId { get; init; }
    public required string Feature { get; init; }         // scoped: a proof for one op is not a proof for another
    public required byte[] Nonce { get; init; }           // echoes the client's challenge verbatim
    public required DateTimeOffset IssuedAt { get; init; } // server's view; used for logs, not for the client's decision
}

On the server, minting is a status check and a signature, signed by a dedicated step-up key Ks — the same hot/cold split the stapling design uses, so a leaked Ks can forge “still live” assertions but never an entitlement.

public LivenessResponse Prove(string licenseId, string feature, byte[] nonce, TimeProvider clock)
{
    var lic = _store.Find(licenseId) ?? throw new NotFoundException(licenseId);

    // The entire revocation mechanism is this one line; a revoked license yields 410 Gone.
    if (lic.Status is not LicenseStatus.Active)
        throw new RevokedException(licenseId, lic.Status);
    if (!lic.Grants(feature))
        throw new NotEntitledException(licenseId, feature);

    var proof = new LivenessProof
    {
        LicenseId = lic.Id,
        Feature   = feature,
        Nonce     = nonce,                 // echo the caller's bytes back, unchanged
        IssuedAt  = clock.GetUtcNow(),
    };
    var bytes = Canonical.Write(proof);
    return new LivenessResponse(bytes, _stepUpKey.Sign(bytes));
}

The client half

This is where the freshness guarantee is actually earned. The client generates the nonce, starts a monotonic stopwatch, makes the call, and holds the response to four checks. Crucially, the accept/reject decision rests on the nonce and the elapsed monotonic time, never on a wall-clock comparison the user could tamper with.

public async ValueTask<StepUpResult> RequireFreshAsync(
    string feature, FreshnessPolicy policy, CancellationToken ct)
{
    // Fast path: the ambient state may already be fresh enough, if the op didn't demand liveness.
    if (!policy.RequireLiveness
        && _clock.GetUtcNow() - Current.VerifiedAt <= policy.MaxAge
        && Current.Grants(feature))
        return StepUpResult.Satisfied(Current, fromCache: true);

    // Liveness path: challenge-response against a fresh random nonce.
    var nonce = RandomNumberGenerator.GetBytes(32);
    var started = Stopwatch.GetTimestamp();        // monotonic; immune to clock changes

    LivenessResponse res;
    try
    {
        res = await _client.ProveLivenessAsync(Current.License.Id, feature, nonce, ct);
    }
    catch (RevokedException)      { return StepUpResult.Denied(Reason.Revoked); }
    catch (NotEntitledException)  { return StepUpResult.Denied(Reason.NotEntitled); }
    catch (HttpRequestException)  { return StepUpResult.Denied(Reason.Unreachable); } // offline → no step-up

    var elapsed = Stopwatch.GetElapsedTime(started);

    // 1. Authenticity: the proof is signed by the pinned step-up key.
    if (!_stepUpKey.Verify(res.Bytes, res.Signature))
        return StepUpResult.Denied(Reason.BadSignature);
    var proof = Canonical.Read<LivenessProof>(res.Bytes);

    // 2. Liveness: the proof echoes MY nonce. Constant-time — the nonce is attacker-influenced.
    if (!CryptographicOperations.FixedTimeEquals(proof.Nonce, nonce))
        return StepUpResult.Denied(Reason.NonceMismatch);

    // 3. Scope: a proof minted for one feature/license is not valid for another.
    if (!string.Equals(proof.Feature, feature, StringComparison.Ordinal)
        || !string.Equals(proof.LicenseId, Current.License.Id, StringComparison.Ordinal))
        return StepUpResult.Denied(Reason.WrongScope);

    // 4. Recency: bounded by the monotonic stopwatch, not by any wall clock.
    if (elapsed > policy.MaxAge)
        return StepUpResult.Denied(Reason.RoundTripTooSlow);

    return StepUpResult.Satisfied(Current, fromCache: false);
}

Check 2 is the mechanism’s spine. The nonce is 32 bytes of fresh randomness the server had never seen until this call, so a signed proof that echoes it provably came into existence after the stopwatch started. A proof captured from last week’s export echoes last week’s nonce and fails here; a proof the server tried to pre-compute could not have included a nonce it had not yet received. FixedTimeEquals does the comparison in constant time because the returned nonce is attacker-controlled input and a short-circuiting == would leak how many leading bytes matched.

Check 4 then bounds how fresh with Stopwatch.GetElapsedTime — a monotonic measurement that keeps counting forward even if the system date is rolled back mid-call. The IssuedAt field rides along for the server’s own audit log, but the client never subtracts it from DateTimeOffset.UtcNow, because that difference would be exactly as trustworthy as the user’s clock.

Wiring it to an operation

At the call site, step-up is one await before the irreversible work, and a clean denial if it fails.

public async Task<IResult> ExportAsync(ExportRequest req, CancellationToken ct)
{
    var step = await _gate.RequireFreshAsync("export.bulk", FreshnessPolicy.StepUp, ct);
    if (!step.Ok)
        return Results.Problem(
            title: "This operation needs a fresh license check",
            detail: step.Reason.ToString(),
            statusCode: StatusCodes.Status402PaymentRequired);

    await _exporter.RunAsync(req, ct);           // only reached with a live, in-scope proof
    return Results.Ok();
}

Everything else in the app keeps reading _gate.Current and never touches the network. The result is tiered: ordinary work is offline-tolerant and instant, and the few operations that can cause real damage pause for a round-trip that proves, cryptographically and in real time, that the license behind them is still live.

Where it breaks, and the honest limits

Step-up is online by construction, and that is the whole trade. A revoked license is stopped at the sensitive operation within one round-trip — but so is a legitimate one whose network is simply down. That is acceptable only because the gated operations are rare and worth blocking; apply the same policy to an ordinary feature and you have rebuilt the online-every-action model, with its outages, that the ambient entitlement exists to avoid. Choose what deserves step-up as deliberately as you would choose what deserves re-authentication.

The nonce defends liveness, not confidentiality. A step-up proof is not a bearer token for the operation — it only authorizes the local decision to proceed; the operation’s own authorization (who may export, what they may export) is a separate concern and must not be collapsed into “the license was live.” And Ks being online is a real surface, mitigated exactly as in the stapling design: it signs nothing of standalone value, so rotate it on a short cycle and keep the previous public key pinned for an overlap window.

Finally, step-up tightens freshness; it does not replace the signature chain. The ambient license must still verify against its pinned entitlement key, as the canonical-serialization post insists, before any of this runs. A live proof for a forged license is worthless, and a correct implementation never reaches the step-up path for a license that failed its ordinary verification.

Takeaway

Treat freshness as a dial, not a constant. Most of your app is well served by an entitlement checked at startup and kept current in the background, offline and instant. For the handful of operations that are expensive, irreversible, or trusted downstream, demand more: a challenge-response liveness proof the issuing service mints against a fresh random nonce, verified with a pinned key, and bounded by a monotonic stopwatch so the guarantee never leans on the client’s clock. Revoke the license and the next sensitive operation is denied within a round-trip, while the ordinary ones that make up the rest of the day never notice the network exists. That is step-up: the strongest possible statement about a license, reserved for the moments that actually warrant it.

Try Nebula.NET

Harden your .NET code in minutes — start with the free edition.