DEV Community

Zero Heartbeat
Zero Heartbeat

Posted on Originally published at delta1labs.com

Bind a license to the host application

A Keyright license is portable by design. It is a signed blob of claims, and your application trusts it because a signature verifies against a public key the app carries — no server in the path, nothing to phone. That portability is the feature. It is also a gap.

Consider what a license plus an SDK integration actually is on disk: a license key file and a verification routine that accepts it. Lift both out of the product they were sold for and drop them into a different application — a fork, an unrelated tool, a second product from the same shop — and verification still passes. The signature is valid, the claims are intact, the public key is the same. Nothing about the check knows or cares which application is running it. A license issued for InvoicePro will happily unlock anything that calls the verifier with it.

For a vendor who sells per-product licenses, that is a real leak. The question this post answers is: how do you make a license refuse to work anywhere except the one application it was issued for — without a server round-trip, and without inventing anything the signature does not already cover?

The claim that names the consumer

The standard trio of bindings answers "who or where." Node-locking ties a key to a machine fingerprint; named-user binding ties it to an identity; site binding ties it to a domain. None of them answers "which application." For that you need a claim that names the consumer, and it has to be inside the signed payload — otherwise the attacker just edits it.

That claim is the audience. The issuing side writes an aud value into the payload before signing:

{
  "sub": "cust_8f21",
  "tier": "Pro",
  "seats": 5,
  "exp": "2027-03-01T00:00:00Z",
  "aud": "pkt:3b1e5f9a2c4d6e80"
}
Enter fullscreen mode Exit fullscreen mode

Because aud is covered by the signature, it is immutable in the field: change it and the signature no longer verifies. The only party who can issue a license for a given audience is the one holding the private key — you. So the audience is a promise, signed by you, about which application is allowed to consume this key.

The value pkt:3b1e5f9a2c4d6e80 is not arbitrary. It is the strong-name public key token of the one assembly permitted to use the license.

Reading the host's identity

Every strong-named .NET assembly carries a public key, and its 8-byte token — the low 64 bits of the SHA-1 of that public key — is how the runtime refers to the assembly's identity in references and binding. It is public, stable across your builds, and — the property that matters — unforgeable, because reproducing it means reproducing a public key whose matching private key you keep.

At verification time the SDK reads the identity of the assembly that is hosting it:

static class HostIdentity
{
    // Token of the assembly that is allowed to consume the license —
    // typically the product's main assembly, captured where the SDK is wired up.
    public static string PublicKeyToken(Assembly host)
    {
        byte[]? token = host.GetName().GetPublicKeyToken();
        if (token is null || token.Length == 0)
            throw new SecurityException("Host assembly is not strong-named; audience cannot be bound.");
        return "pkt:" + Convert.ToHexStringLower(token);
    }
}
Enter fullscreen mode Exit fullscreen mode

The token lives in metadata, not in your code, and you can see it without running anything. In the manifest of the consuming assembly it is the .publickey of the .assembly row; everywhere that assembly is referenced, the short token appears directly:

.assembly extern InvoicePro.Core
{
  .publickeytoken = (3B 1E 5F 9A 2C 4D 6E 80 )   // ← the aud claim commits to exactly this
  .ver 4:2:0:0
}
Enter fullscreen mode Exit fullscreen mode

That eight-byte range is what the aud claim names. Note what it is not: it is not the module version id (ModuleVersionId), which changes on every compile and would invalidate every license the instant you shipped a patch; and it is not a file hash, which breaks under any post-build step. The public key token is the only identity that is both stable across your releases and anchored to a key only you hold.

The fail-closed check

With the expected audience in the signed payload and the host's real identity in hand, the check is a comparison — run after the signature verifies, and fail-closed if anything is missing:

public LicenseStatus VerifyForHost(string licenseKey, Assembly host)
{
    // 1. Verify the signature first. An unsigned/forged payload never reaches the audience check.
    if (!_verifier.TryVerify(licenseKey, out LicensePayload payload))
        return LicenseStatus.Invalid;

    // 2. A license that carries no audience is not bound to anything — reject under strict mode.
    if (string.IsNullOrEmpty(payload.Audience))
        return _options.RequireAudience ? LicenseStatus.AudienceMissing : LicenseStatus.Valid;

    // 3. The audience is a promise, signed by us, about which assembly may consume this key.
    string expected = HostIdentity.PublicKeyToken(host);
    bool ok = CryptographicOperations.FixedTimeEquals(
        Encoding.ASCII.GetBytes(payload.Audience),
        Encoding.ASCII.GetBytes(expected));

    return ok ? LicenseStatus.Valid : LicenseStatus.AudienceMismatch;
}
Enter fullscreen mode Exit fullscreen mode

Wiring it up is one option on the verifier, capturing the assembly the license is meant for:

var verifier = new LicenseVerifier(new LicenseVerifierOptions
{
    PublicKeyBase64 = LicensingConfig.PublicKeyBase64,
    ExpectedAudience = HostIdentity.PublicKeyToken(typeof(Program).Assembly),
    RequireAudience  = true,   // reject unbound licenses outright
});
Enter fullscreen mode Exit fullscreen mode

Now follow a lifted license through it. The attacker copies a valid InvoicePro key and the SDK into their own application and calls VerifyForHost. The signature verifies — the key is genuine. The payload's aud reads pkt:3b1e5f9a2c4d6e80. But HostIdentity.PublicKeyToken returns the token of their assembly, which is a different key pair, so a different token. The comparison fails, the status is AudienceMismatch, and the gate closes. The license is real; it is simply not for this application, and the signed claim says so.

How you use it

The audience is set at issue time, so the only operational change is on the minting side: when you create a license for a product, stamp it with that product's public key token. Keyright's admin API and CLI take an --audience on issue, and the SDK verifier takes the matching ExpectedAudience. Capture the token from the product's assembly, not the SDK's — typeof(Program).Assembly or whichever assembly is strong-named with your product key — so the binding names the thing you sell, not the library inside it.

Two knobs decide how strict you are. RequireAudience rejects any license that carries no aud at all, which you want once every key you mint is bound; leave it off during a migration so older unbound keys keep working until they expire. And because the token is public and stable, you can bind a single customer's key to a suite of products by listing several accepted tokens on the verifier — the mirror image of the single-audience case, for when one purchase legitimately covers more than one app.

This composes cleanly with the other bindings. Audience answers "which application"; node-locking still answers "which machine"; floating seats still answer "how many at once." A key can be bound to one product and still float across that product's seats.

When it breaks

The honest limit is the one named in the FAQ: audience binding stops a license from being lifted into a different application, not from being used inside a byte-identical copy of your application. An attacker who redistributes your actual signed assembly carries your real public key token with it, so the audience matches. That is a worse position for them — they can no longer embed your licensed integration in their own product, only re-ship yours verbatim, which is unambiguous piracy and gives them nothing to customize — but it is not nothing, and audience binding does not address it.

The second limit is that the check runs on the attacker's machine, like every client-side check. Someone who patches the verifier can delete the comparison. That is why audience binding is a layer, not a wall: it belongs with strong-naming (so the identity it reads is hard to forge), anti-tamper (so the comparison is hard to remove), and report-home (so a stripped build is visible when it runs). Nebula's passes are built to harden exactly this verification path.

And the hard requirement: the host must be strong-named. Without a public key there is no token to bind to, and the check above fails closed by design. If your product is not strong-named, audience binding is the reason to start.

Takeaway

Portability is what makes offline licensing work and what makes a license liftable. Audience binding reclaims the second half without giving up the first: one signed aud claim naming the application's own public key token, checked after the signature and failing closed. It costs one field at issue time and one comparison at verify time, and it turns "reuse this paid license anywhere" into "re-ship this exact binary" — a far narrower problem, and the one your other defenses were already built to fight.

Top comments (0)