DEV Community

Zero Heartbeat
Zero Heartbeat

Posted on Originally published at delta1labs.com

Catching shared keys by fingerprint velocity

Count the seats on a shared license and you will often find nothing wrong. A three-seat key shows three machines active. The problem is that the three machines are never the same three. One drops off, another appears; over an afternoon forty different laptops have each held one of those three seats for a few minutes. Every snapshot is within the limit. The key is being passed around a Discord server, and a seat count will never say so.

This is the gap between how many machines hold a key and how the set of machines changes over time. A genuine three-person team is three fingerprints that come back every morning. A leaked key is a turnstile. The enforcement that matters is not the instantaneous count — it is the velocity.

The real question

What does a server watch, beyond the seat count, to tell a stable team from a shared key — and when it sees sharing, what does it do that does not also punish the user who bought a new laptop or logged in from an airport? The answer is a small set of signals computed over a rolling window, and an escalation ladder that climbs from observe to step-up reverify to evict only as the evidence hardens.

The signals

Every activation and heartbeat carries a machine fingerprint — a stable hash of hardware and OS identity recorded when the client first claimed the key — plus the time and a coarse geolocation derived from the request. The server keeps a short, per-key history of these claims. Three quantities fall out of that history:

Distinct fingerprints in the window. How many different machines claimed the key in the last hour. Against a seat limit, this is the pressure: at or below the limit is normal; above it means more live machines than the license allows.

Churn velocity. The rate at which new fingerprints appear. Three machines that return all day have near-zero churn. A key that produces a never-before-seen fingerprint every few minutes has high churn even if only three are "active" at any instant — the turnstile signature.

Impossible travel. Two claims from the same key, from locations too far apart to have been reached in the elapsed time. One key cannot be in Berlin and São Paulo four minutes apart. This catches sharing that stays within the seat count, because two distant people using "one seat" alternately still teleport.


Distinct machine fingerprints claiming one key over a rolling window, crossing the admit, observe and evict thresholds while an impossible-travel event triggers step-up









Distinct fingerprints on one key over a rolling window. Below the seat line, claims are admitted. Climbing past the observe line only records a signal; an impossible-travel event raises a step-up challenge; sustained growth past the evict line, above the seat limit, is where the server reclaims a seat.

The model

A claim is what the client sends; the server already has the recent ones for this key.

public readonly record struct GeoPoint(double Lat, double Lon);

public readonly record struct Claim(
    string Fingerprint,       // stable hash of the client machine
    DateTimeOffset At,        // server-stamped arrival time
    GeoPoint Where);          // coarse geo of the request

public enum SeatVerdict
{
    Admit,     // grant / renew the seat
    Observe,   // grant, but record a soft signal
    StepUp,    // challenge the client to re-prove possession
    Evict      // over the limit and churning — reclaim a seat
}
Enter fullscreen mode Exit fullscreen mode

Impossible travel is a great-circle distance divided by elapsed time. The threshold is deliberately generous — faster than any airliner — so only genuinely physically impossible jumps trip it:

static class Geo
{
    const double EarthKm = 6371.0;

    public static double GreatCircleKm(GeoPoint a, GeoPoint b)
    {
        double dLat = Deg2Rad(b.Lat - a.Lat);
        double dLon = Deg2Rad(b.Lon - a.Lon);
        double h = Math.Sin(dLat / 2) * Math.Sin(dLat / 2)
                 + Math.Cos(Deg2Rad(a.Lat)) * Math.Cos(Deg2Rad(b.Lat))
                 * Math.Sin(dLon / 2) * Math.Sin(dLon / 2);
        return EarthKm * 2 * Math.Asin(Math.Min(1.0, Math.Sqrt(h)));
    }

    public static bool ImpossibleTravel(Claim a, Claim b, double maxKmPerHour = 1000)
    {
        double hours = Math.Abs((b.At - a.At).TotalHours);
        double km = GreatCircleKm(a.Where, b.Where);
        // Guard the denominator: two claims in the same minute from far apart
        // are impossible regardless of the exact seconds between them.
        return km / Math.Max(hours, 1.0 / 60) > maxKmPerHour;
    }

    static double Deg2Rad(double d) => d * Math.PI / 180.0;
}
Enter fullscreen mode Exit fullscreen mode

The decision

The detector folds the three signals into one verdict for an incoming claim. The order of the checks is the policy: a returning machine inside the seat count is never disturbed, hard sharing is evicted, a single teleport only steps up, and rising churn below the limit is merely observed.

public sealed class SharingDetector
{
    private readonly TimeSpan _window;
    private readonly int _seatLimit;
    private readonly double _churnObserve;  // new fingerprints/hr to start watching
    private readonly double _churnEvict;    // new fingerprints/hr that means a turnstile

    public SharingDetector(
        int seatLimit,
        TimeSpan window,
        double churnObserve = 4,
        double churnEvict = 8)
    {
        _seatLimit = seatLimit;
        _window = window;
        _churnObserve = churnObserve;
        _churnEvict = churnEvict;
    }

    public SeatVerdict Evaluate(IReadOnlyList<Claim> recent, Claim incoming)
    {
        DateTimeOffset cutoff = incoming.At - _window;

        // Claims inside the rolling window, including the one arriving now.
        var window = recent.Where(c => c.At >= cutoff)
                           .Append(incoming)
                           .ToList();

        int distinct = window.Select(c => c.Fingerprint)
                             .Distinct(StringComparer.Ordinal)
                             .Count();

        bool returning = recent.Any(c => c.At >= cutoff
                                      && c.Fingerprint == incoming.Fingerprint);

        // Churn: distinct machines per hour over the window.
        double churnPerHour = distinct / Math.Max(_window.TotalHours, 1.0);

        // Impossible travel vs the most recent claim from a DIFFERENT machine.
        Claim? lastOther = null;
        for (int i = window.Count - 2; i >= 0; i--)
            if (window[i].Fingerprint != incoming.Fingerprint)
            {
                lastOther = window[i];
                break;
            }
        bool teleport = lastOther is { } prev && Geo.ImpossibleTravel(prev, incoming);

        // 1. A known machine still within the seat count is always fine.
        if (returning && distinct <= _seatLimit)
            return SeatVerdict.Admit;

        // 2. More live machines than seats, and they keep rotating: a turnstile.
        if (distinct > _seatLimit && churnPerHour >= _churnEvict)
            return SeatVerdict.Evict;

        // 3. One key in two places it cannot both be: challenge, don't block.
        if (teleport)
            return SeatVerdict.StepUp;

        // 4. Over seats but calm — likely a real new device replacing an old one.
        if (distinct > _seatLimit)
            return SeatVerdict.StepUp;

        // 5. Within seats but churn is climbing — watch, do not act yet.
        if (churnPerHour >= _churnObserve)
            return SeatVerdict.Observe;

        return SeatVerdict.Admit;
    }
}
Enter fullscreen mode Exit fullscreen mode

Two choices carry the honesty of the design. A returning fingerprint inside the seat count short-circuits everything — the overwhelmingly common case costs one HashSet lookup and never escalates. And crossing the seat limit calmly is a step-up, not an eviction — because the most common way to exceed the count briefly is legitimate: the user got a new laptop and the old one is still in the window. Only the combination of over the limit and high churn — more machines than seats, and a fresh one every few minutes — is treated as a leak and evicted.

Acting on the verdict

Observe grants the seat and appends a signal to the key's record. Nothing is denied; you are building a case. A key that observes once a week is noise; one that observes forty times in an afternoon is your leaked key, and the record is what lets support see it.

StepUp returns a challenge rather than a seat grant. The client must re-prove it holds the activation — a proof-of-possession signature over a server nonce using the device key bound at activation. A machine that genuinely activated answers in milliseconds; a copied license file cannot. This is the step that separates "unusual" from "fraudulent" without accusing anyone.

Evict reclaims a seat so the legitimate owner is not locked out by the people they shared with. The usual policy is to evict the stalest seat — the fingerprint whose last claim is oldest — and admit the newcomer, so a real owner rotating machines always wins and the turnstile cannot pin all seats. That eviction mechanics is its own topic; here the detector's job ends at producing the verdict.

SeatVerdict verdict = detector.Evaluate(recent, incoming);

return verdict switch
{
    SeatVerdict.Admit  => GrantSeat(incoming),
    SeatVerdict.Observe => GrantSeat(incoming, flagged: true),
    SeatVerdict.StepUp => Challenge(incoming),          // proof-of-possession nonce
    SeatVerdict.Evict  => EvictStalestThenGrant(incoming),
    _ => throw new UnreachableException()
};
Enter fullscreen mode Exit fullscreen mode

Caveats and when it breaks

Geolocation is coarse and sometimes wrong. A corporate VPN can place every office in one city or scatter one office across three. That is why impossible travel only triggers a step-up, never an eviction — a user behind a VPN re-proves possession and moves on, and the false positive costs one challenge, not a lockout. Tune maxKmPerHour high; the goal is to catch physically impossible jumps, not fast ones.

Fingerprints drift. A hardware change or OS reinstall produces a new fingerprint for the same machine, which reads as churn. If your fingerprint is brittle, a single user reinstalling looks briefly like sharing. Fuzzy, tolerant fingerprinting that rebinds across small changes keeps this noise down — and it is why the observe threshold exists, so drift is watched before it is acted on.

The window is a memory, not a ledger. These signals describe recent behavior, not lifetime totals. A key shared slowly — one new machine a day — stays under every per-hour threshold. Velocity catches the turnstile, not the patient freeloader; lifetime seat accounting and true-up billing are the backstop for the slow case.

And the honest ceiling: this is heuristic detection, not proof. It is deliberately biased toward admitting and observing, because the cost of evicting a paying customer is far higher than the cost of letting one shared seat run another hour while you build the case. The verdict feeds enforcement; it is not a verdict of guilt.

Takeaway

A seat count answers "how many machines right now"; it cannot answer "is this key being passed around." The answer lives in the motion — distinct fingerprints per window, the rate new ones appear, and claims that teleport across the planet. Compute those three over a short rolling window, and climb an escalation ladder that observes before it challenges and challenges before it evicts. The stable team never feels it; the leaked key trips every rung. See Keyright and the documentation.

Top comments (0)