DEV Community

Zero Heartbeat
Zero Heartbeat

Posted on Originally published at delta1labs.com

Catching a trial reset by a VM snapshot

Give away a 14-day trial and someone will try to make it last forever. The cheap attack is not cracking your signature — it is time travel. A user installs the trial inside a virtual machine, takes a snapshot, uses the software for two weeks, then restores the snapshot. The disk reverts to the instant after install. Every file is back, including whatever anti-tamper state your SDK carefully wrote. As far as the trial can tell, it was installed thirty seconds ago. Repeat forever.

This is the uncomfortable cousin of the signed-license replay. The license is genuine and unexpired — it is a 14-day trial, after all. Nothing was forged. What moved was time, and the client owns both the clock and the disk the trial counts on.

The real question

A trial is enforced by elapsed time: start plus fourteen days. To know whether the window has closed, the SDK has to remember when the window opened and how much of it has been spent. Both facts live on the client, and both are exactly what a rollback rewinds.

So the question is not "is this license valid?" — it plainly is. It is: has the client's sense of time or usage moved backward since the last time I looked? Two rollbacks produce that symptom. The first is a clock reset: the user sets the system clock back so now lands inside the original window. The second is harder — a VM snapshot restore, which reverts not just the clock but every byte of local state, including a tamper-evident store, to a point where they were mutually consistent.

The first attack a local witness can catch. The second it cannot, and being honest about why is the whole point of this post.

A monotonic time-and-usage witness

Start with the case a client can win: the clock reset. Keyright keeps a small durable witness next to the license — not inside it, because the license is fixed at issue and this value must keep moving.

public sealed record TrialWitness
{
    public required string LicenseId { get; init; }
    public required DateTimeOffset HighWaterUtc { get; init; }  // newest wall-clock time ever observed
    public required TimeSpan Consumed { get; init; }            // trial time counted so far, monotonic
    public required long ServerTick { get; init; }              // last authoritative counter from the service
}
Enter fullscreen mode Exit fullscreen mode

HighWaterUtc is the latest moment the SDK has ever seen the clock read. It only ever rises. On each verification the SDK compares the current clock to it. A clock that now reads earlier than a time the client already observed is, by construction, a clock that went backward.

public TrialStatus Evaluate(SignedLicense signed, TrialWitness prior)
{
    var now = _clock.GetUtcNow();

    // a reading well below the newest time we have ever seen is a rollback
    if (now + _leeway < prior.HighWaterUtc)
        return TrialStatus.ClockRolledBack;

    // accumulate only the forward motion of the clock as spent trial time
    var step = now - prior.HighWaterUtc;
    if (step < TimeSpan.Zero) step = TimeSpan.Zero;
    var consumed = prior.Consumed + step;

    if (consumed >= signed.Payload.TrialBudget)
        return TrialStatus.TrialExhausted;

    _store.Write(prior with { HighWaterUtc = now, Consumed = consumed });
    return TrialStatus.Active;
}
Enter fullscreen mode Exit fullscreen mode

Two properties matter. Consumed is accumulated from forward clock motion only, so a user who jumps the clock far forward and back does not gain trial — they only burn it faster. And HighWaterUtc is a floor, not a timestamp to compare trial length against, so the defense does not trust the clock's absolute value, only that it does not retreat. The store itself is authenticated with a machine-bound HMAC, exactly like Keyright's epoch watermark: a hand-edited Consumed of zero fails its MAC and is treated as missing, not trusted.

That closes the clock-reset attack. It does nothing for the snapshot.

Why the snapshot wins locally

A VM snapshot restore is not an edit of the witness. It is a restore of the entire disk to a point when the witness was legitimately day zero. The MAC still verifies — the SDK wrote that row itself, two weeks ago in wall-clock terms but thirty seconds ago from the disk's point of view. HighWaterUtc really was that value then. There is no inconsistency for a local check to find. Any state the client can write, the client can snapshot, and anything inside the snapshot boundary reverts together, coherently.

The only way out is a witness the client cannot snapshot. That means state held somewhere the restore does not reach: the issuing service.

A snapshot restore rolls the client's own anti-tamper store back to day zero; only state the client cannot snapshot — the issuing service's monotonic record — survives to expose it.

Reconciling against the service

Keyright's trial heartbeat does two things on every online check. It carries a monotonic service tick — a per-identity counter the service increments on each contact, with no relation to wall-clock time — and it carries the trial time the service has recorded for this identity. Both live outside the client's snapshot boundary.

public TrialStatus Reconcile(TrialWitness local, HeartbeatResponse response)
{
    // the tick only ever rises; a response carrying a lower one is forged or replayed
    if (response.ServerTick < local.ServerTick)
        return TrialStatus.Tampered;

    // the service counted more trial than this client admits to having used:
    // local state was rolled back — snapshot restore, store wipe, or clock reset
    if (response.RecordedConsumed > local.Consumed + _reconcileLeeway)
    {
        _store.Write(local with
        {
            Consumed = response.RecordedConsumed,       // adopt the authoritative figure
            ServerTick = response.ServerTick,
        });
        return response.RecordedConsumed >= local.Budget
            ? TrialStatus.TrialExhausted
            : TrialStatus.Active;
    }

    _store.Write(local with { ServerTick = response.ServerTick });
    return TrialStatus.Active;
}
Enter fullscreen mode Exit fullscreen mode

The service never decreases what it has recorded for an identity. When a snapshot-restored client reconnects claiming zero days used, the service already holds twenty, and RecordedConsumed > local.Consumed is the tell. The client adopts the larger figure, the trial is correctly exhausted, and no amount of local disk gymnastics undoes it — the number the attacker needs to lower is on a machine they do not control.

How you wire it

In the trial SDK you register the witness store and the heartbeat cadence, then let verification and reconciliation run where they naturally fall:

services.AddKeyright(o =>
{
    o.Trial.Enable();
    o.Trial.ClockRollbackLeeway  = TimeSpan.FromMinutes(5);   // absorb honest skew
    o.Trial.HeartbeatInterval    = TimeSpan.FromHours(6);     // how often to reconcile online
    o.Trial.OnClockRollback      = RollbackPolicy.RevalidateThenGate;
});
Enter fullscreen mode Exit fullscreen mode

RevalidateThenGate is the humane default: a detected clock rollback forces an immediate online reconciliation rather than an instant hard-fail, so a laptop whose clock was briefly wrong recovers, while a machine that is both rolled back and offline is gated until it can prove itself. The identity used for the service record is the trial grant, scoped per machine fingerprint, so one organization evaluating on ten machines gets ten honest trials, not one.

When it breaks

Be precise about the boundary. Offline plus snapshot is unwinnable by the client alone, and no library should claim otherwise. If a trial machine never connects after the first install, the service never records usage, and a snapshot restore is indistinguishable from a fresh install. Keyright narrows this three ways: a short trial budget so the offline window is small, a required first-contact activation so a never-online trial does not start at all, and the service record that snaps the trial shut the first time the machine does connect. A determined, permanently-air-gapped evaluator defeats time-based trials — which is why high-value offline scenarios use challenge-response activation, not an elapsed-time trial.

Two narrower edges. The clock-rollback leeway must exceed your realistic skew or you will flag honest users on the heartbeat; five minutes is generous for anything NTP-adjacent. And the witness is per identity — reuse one trial identity across unrelated installs and the service conflates their usage, so bind it to the machine fingerprint, which Keyright does by default.

Takeaway

A signature proves authenticity; expiry proves a date; neither notices that the client's clock, or its whole disk, just travelled backward. Catching a reset trial takes a witness that only moves forward: a monotonic high-water clock and usage counter to stop the cheap clock reset, and — because a VM snapshot reverts every local byte coherently — a monotonic record on the issuing service, outside the snapshot boundary, to stop the expensive one. Verify the signature, verify expiry, then check that time and usage have not retreated since you last looked. Keyright's Community Edition ships the trial witness and heartbeat reconciliation; the Keyright docs cover tuning rollback policy and heartbeat cadence.

Top comments (0)