One seat per computer, not per format
Activation ties a license key to one device. A device limit, 3 by default, decides how many can be active at once. A producer who installs your VST3, AU and standalone app on one laptop should use one seat, not three. That works when all formats send the same fingerprint and read the same license file from the validation guide: activating again with a fingerprint already active returns that seat, with its name updated.
This code was compiled and run against JUCE 9.0.6 juce_core and juce_cryptography on macOS, with a local mock of the documented responses. The button wiring at the end needs the GUI modules and was not compiled.
The device id, hashed
SystemStats::getUniqueDeviceID() returns a machine ID unaffected by storage or peripheral changes. The documentation lists its limits: motherboard and CPU changes invalidate it on non-mobile platforms, a system restore invalidates it on Android, and on iOS it is scoped to the vendor part of the bundle identifier and can be an empty string, for example right after a restart, until the user first gets past the lock screen. Send a hash, not the raw value. If it is empty, send no fingerprint and accept that a reinstall then uses a new seat.
inline juce::String fingerprint()
{
const auto id = juce::SystemStats::getUniqueDeviceID();
if (id.isEmpty())
return {};
const auto text = "com.example.inkwell:" + id; // your prefix; never change it after shipping
return juce::SHA256 (text.toRawUTF8(), text.getNumBytesAsUTF8()).toHexString(); // 64 characters
}
On my Mac the hash was the same across six runs of the test, which the mock confirmed by logging the first characters of each request’s fingerprint.
Activate and deactivate
post and save are on the client from the validation guide. Both functions block, so call them from a background thread.
inline juce::Result activate (LicenseClient& client, const juce::String& rawKey)
{
const auto key = rawKey.trim();
std::vector<std::pair<juce::String, juce::String>> fields { { "license_key", key },
{ "instance_name", juce::SystemStats::getComputerName() } };
if (const auto fp = fingerprint(); fp.isNotEmpty())
fields.push_back ({ "fingerprint", fp });
const auto reply = client.post ("activate", fields);
if (reply.status == 0)
return juce::Result::fail ("Could not reach the license server. Check the connection and try again.");
if (! (bool) reply.body["activated"])
{
const auto limit = reply.body["license_key"]["activation_limit"]; // void when unlimited
if (reply.status == 400 && ! limit.isVoid() && (int) reply.body["license_key"]["activation_usage"] >= (int) limit)
return juce::Result::fail ("All " + limit.toString() + " devices for this key are in use. Free one on the device page, then try again.");
const auto error = reply.body["error"].toString();
return juce::Result::fail (error.isNotEmpty() ? error : "Activation failed (HTTP " + juce::String (reply.status) + ").");
}
auto saved = new juce::DynamicObject();
saved->setProperty ("key", key);
saved->setProperty ("instance_id", reply.body["instance"]["id"]);
saved->setProperty ("token", reply.body["token"]);
saved->setProperty ("last_checked", juce::Time::currentTimeMillis() / 1000);
client.save (juce::var (saved));
return juce::Result::ok();
}
inline juce::Result deactivate (LicenseClient& client)
{
const auto saved = client.loadSaved();
if (! saved.isObject())
return juce::Result::ok();
const auto reply = client.post ("deactivate", { { "license_key", saved["key"].toString() },
{ "instance_id", saved["instance_id"].toString() } });
if (reply.status == 0)
return juce::Result::fail ("Could not reach the license server, so this seat is still in use.");
if (reply.status == 200 || reply.status == 404) // 404: the instance is already gone
{
client.licenseFile().deleteFile();
return juce::Result::ok();
}
return juce::Result::fail ("Deactivation failed (HTTP " + juce::String (reply.status) + ").");
}
Wire the button
void ActivationPanel::activateClicked()
{
activateButton.setEnabled (false);
juce::Component::SafePointer<ActivationPanel> safe (this);
auto key = keyEditor.getText();
juce::Thread::launch ([safe, key]
{
auto result = activate (*sharedClient, key); // blocks: fine on this thread
juce::MessageManager::callAsync ([safe, result]
{
if (safe != nullptr)
safe->showResult (result);
});
});
}
SafePointer is the right guard here: the editor can be closed while the request is in flight, and a plain this would dangle.
What the run showed
The mock logged every request as application/x-www-form-urlencoded with the fields license_key, instance_name and fingerprint, which is what withParameter plus inPostData produces.
| Case | Result |
|---|---|
Activate with a padded key (GOOD) |
ok, key trimmed, instance id stored |
400, activation_limit 3, activation_usage 3 |
“All 3 devices for this key are in use. Free one on the device page, then try again.” |
| 404 | “license_key not found.” |
| Nothing listening | “Could not reach the license server.” |
| Deactivate, 200 | ok, license file deleted |
Deactivate, 404 instance_id not found. |
ok, license file deleted |
JUCE specifics
- Never deactivate from a destructor or
releaseResources. Hosts create and destroy instances constantly. Offer a “Deactivate this computer” button. - A studio computer with no internet cannot activate: the call needs one online connection. Validation afterwards runs from the stored token.
- Cloned drives copy the license file. Whether the device ID changes on the clone depends on the platform, so test a clone before you promise buyers anything. The 3-device default leaves room for a laptop and a studio machine.
- Point buyers to
/licenses/managein the limit message. They remove a computer there with the key alone, no account.
Doing this with Clavem
The activate and deactivate endpoints, their errors and the fingerprint rule are in the API reference. Each product sets a default device limit, and a single license can override it.
Questions
Can a plugin deactivate itself when it is deleted or the project closes?
It should not. A plugin instance is destroyed every time a project closes, so a deactivate call in a destructor would free the seat on every session. Put it behind a button.
What does getUniqueDeviceID return on a new motherboard?
A different value. The JUCE documentation says the ID is unaffected by storage or peripheral changes but is invalidated by changes to the motherboard and CPU on non-mobile platforms. The old seat then has to be freed by the buyer.