Clavem

Activate and deactivate devices from a Unity game

Call activate once, with SystemInfo.deviceName as instance_name and a salted SHA-256 of SystemInfo.deviceUniqueIdentifier as fingerprint. Unity builds that identifier differently on every platform, so know which builds change it.

What Unity gives you as a device id

fingerprint is a stable identifier for the device, up to 200 characters, and it is optional. Activating again with one that is already active on the license returns that seat instead of using another. Unity’s documentation describes where SystemInfo.deviceUniqueIdentifier comes from:

Platform Source What changes it
Windows standalone Hash of baseboard, BIOS and OS serial numbers A board swap, and possibly an OS reinstall
macOS kIOPlatformUUIDKey Rarely
Linux standalone /etc/machine-id, then /var/lib/dbus/machine-id, then a hash of network interface addresses Cloned images share it. Containers without the files fall back to the network hash.
Android MD5 of ANDROID_ID The signing key: local and Google Play builds differ
iOS identifierForVendor Removing all of your apps from the device
Unsupported platforms SystemInfo.unsupportedIdentifier Not a real id: send no fingerprint

The Android row is the surprise. Per the same page, from Android 8 the value depends on the key that signed the build. A tester who activates a locally signed build and then the Play build uses two seats.

The code

using System;
using System.Collections;
using System.Security.Cryptography;
using System.Text;
using UnityEngine;
using UnityEngine.Networking;

[Serializable] public class InstanceInfo { public string id; public string name; }
[Serializable] public class ActivateReply { public bool activated; public string error; public string token; public InstanceInfo instance; public LicenseInfo license_key; }

public static class DeviceActivation
{
    const string Base = "https://clavem.io";

    public static string Fingerprint()
    {
        string id = SystemInfo.deviceUniqueIdentifier;
        if (string.IsNullOrEmpty(id) || id == SystemInfo.unsupportedIdentifier) return null;
        using (var sha = SHA256.Create())
        {
            byte[] hash = sha.ComputeHash(Encoding.UTF8.GetBytes("inkwell|" + id)); // your own salt
            return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
        }
    }

    // What the player sees on their device page.
    public static string DeviceName()
    {
        string n = SystemInfo.deviceName;
        if (string.IsNullOrEmpty(n) || n == "<unknown>") n = SystemInfo.deviceModel;
        return n + " (" + Application.platform + ")";
    }

    /// done(null) on success, otherwise a sentence to show the player.
    public static IEnumerator Activate(string licenseKey, Action<string> done)
    {
        var form = new WWWForm();
        form.AddField("license_key", licenseKey.Trim());
        form.AddField("instance_name", DeviceName());
        string fp = Fingerprint();
        if (fp != null) form.AddField("fingerprint", fp);

        using (var req = UnityWebRequest.Post(Base + "/v1/licenses/activate", form))
        {
            req.timeout = 8;
            yield return req.SendWebRequest();

            long status = req.responseCode;
            ActivateReply r = null;
            if (status != 0)
            {
                try { r = JsonUtility.FromJson<ActivateReply>(req.downloadHandler.text); } catch (ArgumentException) { }
            }

            if (status == 200 && r != null && r.activated)
            {
                new SavedLicense { key = licenseKey.Trim(), instance = r.instance.id, token = r.token }.Save();
                done(null);
            }
            else if (status == 400 && r != null) done(LimitMessage(r) ?? r.error ?? "Activation failed.");
            else if (status == 404) done("That key was not found. Check it for typos.");
            else done("Could not reach the license server. Try again in a minute.");
        }
    }

    static string LimitMessage(ActivateReply r)
    {
        var k = r.license_key;
        // Expired and disabled licenses also answer 400, with the same block. Check the status.
        if (k == null || k.status == "expired" || k.status == "disabled") return null;
        if (k.activation_limit <= 0 || k.activation_usage < k.activation_limit) return null; // 0 means unlimited
        return "This license is already used on " + k.activation_usage + " of " + k.activation_limit +
               " devices. Remove one at clavem.io/licenses/manage, then try again.";
    }

    /// done(true) when the seat is free, or was already gone.
    public static IEnumerator Deactivate(Action<bool> done)
    {
        var saved = SavedLicense.Load();
        if (saved == null) { done(true); yield break; }

        var form = new WWWForm();
        form.AddField("license_key", saved.key);
        form.AddField("instance_id", saved.instance);
        using (var req = UnityWebRequest.Post(Base + "/v1/licenses/deactivate", form))
        {
            req.timeout = 8;
            yield return req.SendWebRequest();
            if (req.responseCode == 200 || req.responseCode == 404) { SavedLicense.Clear(); done(true); }
            else done(false); // no answer: keep the instance id so the player can try again
        }
    }
}

LicenseInfo and SavedLicense come from the validation page. Start these with StartCoroutine(DeviceActivation.Activate(key, message => ...)) from your settings screen, and show message when it is not null.

The limit-reached screen

The response is a 400 with This license key has reached the activation limit. and a license_key block holding activation_limit and activation_usage. Show both numbers and point the player at the device page. They enter their key, see each machine by instance_name, and remove one. A name like DESKTOP-4F2K (WindowsPlayer) is what lets them pick the right one.

Edge cases that belong to Unity

  • Never activate from the Editor. Every developer machine and build agent would take a seat. Guard Activate with #if UNITY_EDITOR.
  • Containers and cloud build agents. A Linux container without a machine id file gets a hash of its network addresses, which can change per run or repeat across clones. Do not activate on CI.
  • WebGL. Per the persistent data docs, persistentDataPath is a browser IndexedDB location, which the player can clear. If deviceUniqueIdentifier is unsupported on your target, activation without a fingerprint takes a new seat each time. For browser builds, consider calling validate with the key alone and no instance_id, and accept that no device limit applies.
  • persistentDataPath moves with names. On Windows it follows company and product name. Renaming either in Player Settings changes the folder, and every existing player looks unlicensed until they activate again, using a new seat if the fingerprint differs. Keep the names fixed after release.
  • A board swap or Android re-sign gives a new fingerprint and a second seat. The player frees the old one on the device page.

Doing this with Clavem

You set the default device limit on the product, and buyers manage seats on their own device page with no account. See device limits and the activate endpoint for every field and error.

Questions

Is SystemInfo.deviceUniqueIdentifier stable?

It is stable on one build of one device, but its source differs by platform and can change. On Android it depends on the signing key of the build, and on Windows it is derived from hardware and OS serial numbers.

Should I deactivate in OnApplicationQuit?

No. The game is shutting down, so a coroutine started there does not get to finish, and a crash skips the callback altogether. Deactivate only on an explicit player action.

Sources

  1. Unity scripting API, SystemInfo.deviceUniqueIdentifier (checked November 2026)
  2. Unity scripting API, Application.persistentDataPath (checked November 2026)