Clavem

Why sign license responses: a fake server attack, run on localhost

A license check that reads a plain valid flag trusts whoever answers. Signing the response with a private key the attacker lacks means a fake server, an edited payload or a swapped product id all fail verification. Signing does not stop a patched app.

What an unsigned check trusts

Most license checks look like this. The app sends the key to a server and reads the reply:

{ "valid": true }

Nothing in that reply says who sent it. The app believes it because it came back from the hostname it called. If an attacker can make the app call somewhere else, or can sit between the app and the server, they can send {"valid": true} for any key and the app accepts it.

People answer this with “but it is HTTPS”. HTTPS stops a stranger on the same Wi-Fi from rewriting your response. The person you are worried about owns the computer. They can add their own certificate authority to the system, point the hostname at their own machine in the hosts file, or run a proxy that terminates TLS. Most apps do not pin certificates, and an app that does can be patched. Transport security protects the buyer from third parties. It does not protect you from the buyer.

The demonstration

I wrote a Node script with four parts, all on localhost.

  1. A real server that holds a private Ed25519 key. It knows the license is disabled, so it answers valid: false and includes a signed token that also says valid: false.
  2. A fake server run by the attacker. It answers valid: true to everything. It also builds a token with a made-up payload, signed with the attacker’s own key.
  3. App A, which trusts the valid flag.
  4. App B, which verifies the token with the real server’s public key, checks pid, valid and refresh_by, and ignores the flag.

Both apps called both servers. This is the output:

real server (key is disabled)    | app trusting valid: false | app verifying token: false
fake server (attacker)           | app trusting valid: true  | app verifying token: false

App A is fooled by the fake server. App B is not, because the attacker’s forged token carries a signature that does not verify under the real public key. The attacker has everything except the private key.

Tampering with a real token

The attacker has a second option: take a genuine token and edit it. I tried four edits on a token the real server had signed.

genuine token verifies: true
one character of payload changed: rejected
pid edited 1 -> 2, old signature kept: rejected
disabled token edited to valid:true: rejected
signature truncated by one byte: rejected

A signature covers the exact bytes of the first two parts of the token, so any change to a byte breaks it. The attacker cannot flip valid, extend refresh_by or change pid without a fresh signature, and a fresh signature needs the private key.

The demo runs on a key pair created for the test. The Clavem demo product’s public key is not published, so I did not use the live token for this. The checks are identical for a live token. Only the key differs.

Why Ed25519, and why a key per product

A signature scheme for this job has three requirements: the app must be able to verify without being able to sign, verification must be cheap, and every platform must have a library. Ed25519 meets all three. The public key is 32 bytes and the signature is 64 bytes, as defined in RFC 8032. It is in Web Crypto (browsers, Electron, current Node versions, Deno, Bun and Cloudflare Workers), in Apple’s CryptoKit, in libsodium and in the common Rust crates. An app can verify with a short function.

A shared secret, such as an HMAC key, fails the first requirement. The key has to live inside the app, so anyone who extracts it can sign their own responses and the fake server wins again.

A key per product limits the damage when something goes wrong. A token signed for your other product does not verify under this product’s key. I tested it:

verify with another product key -> rejected
token for product 2 checked as product 1 -> wrong product or version

The second line is the pid check. A key per product already blocks the case. Checking pid as well costs one comparison, and it protects you if you ever reuse a key pair across products by mistake.

The pid and kh checks

Two claims bind a token to its context. pid is the product id, so a token cannot be used for another product. kh is the first 16 hex characters of the SHA-256 of the normalized license key, so the app can confirm the token was issued for the key the customer typed. Without kh, one valid token copied to another installation would be accepted whatever key was typed next to it. Without pid, a buyer of your cheap product could present its token to your expensive one if both shared a key pair.

Check Attack it stops
Signature verifies Forged and edited tokens. A fake server.
pid equals your product Tokens from your other products.
kh equals the hash of the typed key One token reused with different keys.
valid is true Tokens for disabled or expired licenses. Signed tokens are issued for those too.
refresh_by in the future Tokens older than the window.

Other ways to protect the answer, compared

Signing is not the only idea people try. Here is how the alternatives fare against the fake server in the demo.

Approach Stops a fake server Weak point
Plain valid flag over HTTPS No The owner of the computer controls trust and routing
Certificate pinning Partly The pin lives in the app, so it can be patched out or bypassed with common instrumentation tools
Shared-secret signature (HMAC) Until the secret is extracted The secret has to ship inside the app, and every copy of the app has it
Obfuscated response format No Reverse engineering the format is a one-time cost, after which it is a plain flag again
Public-key signature (Ed25519, RSA, ECDSA) Yes The private key must stay on the server; replay until refresh_by

The reason public-key signatures win is a property, not a feature: verification needs only a value that is safe to publish. Everything else in the table needs something the attacker can reach. RSA and ECDSA work the same way as Ed25519 for this job. The practical differences are key and signature size and the number of ways to use the library wrongly, and Ed25519 has few knobs to get wrong.

Wiring it into an app

Moving an app from an unsigned check to a signed one changes three lines. Instead of reading body.valid, verify body.token, check pid, and read valid from the claims:

// Before: trusts whoever answered.
if (body.valid === true) enablePaidFeatures();

// After: trusts only what the product's private key signed.
const claims = verifyToken(body.token, PUBLIC_KEY);
if (claims && claims.pid === PRODUCT_ID && claims.valid && claims.refresh_by > now) {
  enablePaidFeatures();
}

Keep the HTTP valid flag for messages to the buyer, such as the error sentence. Never use it for the decision. A fake server controls it and does not control the token.

What signing does not stop

A patched app. If the attacker changes your binary so that the check always passes, nothing above matters. A signature moves the attack from a text file to a binary, which is harder, and does nothing more. See how to stop piracy without annoying customers.

Replay of an old token. My last test line was:

replay of an older valid token (license disabled since): accepted until refresh_by

A token that was true last week is still validly signed today. That is the price of an offline check. A short refresh_by window limits it. Clavem’s is 14 days.

A leaked private key. Whoever has the private key can mint anything. Clavem keeps each product’s private key encrypted at rest on the server. If you build your own, plan for storing the key and for rotating it, which means shipping a new public key with an app update.

Sharing one key. A signature proves the issuer, not the holder. A valid license key and its token can be copied to another computer. That is what device limits and iid and fp checks are for.

Doing this with Clavem

Every activate and validate response includes token, an Ed25519 signature over the payload, made with a per-product private key that stays on Clavem’s servers. You verify with the public key from the product page, which is safe to ship. The format and verification code in Swift, JavaScript, Rust, PHP and Python are in the offline docs. The code in this article uses Node’s built-in node:crypto, and the check is the same in every language.

Questions

Doesn't HTTPS already protect the license check?

HTTPS protects against someone on the network between the app and your server. It does not protect against the owner of the computer, who can add their own certificate authority, route the hostname elsewhere or patch the app. A signature protects against that fake server because the attacker lacks the private key.

Why Ed25519 and not a shared secret?

A shared secret has to be inside the app, so anyone who extracts it can mint valid responses. With Ed25519 the app holds only the public key, which can verify but cannot sign.

Can a signed token be replayed?

Yes. An old valid token still verifies until its refresh deadline. Signing proves who issued the statement, not that it is still true.

Sources

  1. RFC 8032, Edwards-Curve Digital Signature Algorithm (as of November 2026)