Name for people, fingerprint for machines
instance_name is what the customer sees on their device page, up to 120 characters. fingerprint is for the server, up to 200 characters. Send a hash, never a raw hardware id. Activating again with a fingerprint already active on the license returns that seat instead of taking another.
Where the id comes from on each platform
| Platform | Source in device_info_plus | Notes |
|---|---|---|
| macOS | macOsInfo.systemGUID |
Nullable. Handle null. |
| Windows | windowsInfo.deviceId |
The MachineId registry value that Windows Settings shows as Device ID. |
| Linux | linuxInfo.machineId |
Set at install or boot. Nullable. Cloned VM images share it. |
| Android | none | androidInfo.id is the OS build label, the same on many phones. |
| iOS | identifierForVendor |
Can change after a reinstall. Treat as best effort. |
| Web | none | There is no stable browser id. Send no fingerprint. |
When there is no usable id, make one: a random UUID created on first launch and kept in secure storage. It does the same job. Uninstalling the app loses it, which takes a second seat until the customer frees the first.
The code
// pubspec.yaml: device_info_plus, crypto, flutter_secure_storage, http
// clavemPost() is on the validation page.
import 'dart:convert';
import 'dart:io' show Platform;
import 'dart:math' show Random;
import 'package:crypto/crypto.dart';
import 'package:device_info_plus/device_info_plus.dart';
import 'package:flutter/foundation.dart' show kIsWeb;
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
const _store = FlutterSecureStorage();
Future<({String name, String? fingerprint})> describeDevice() async {
if (kIsWeb) return (name: 'Web browser', fingerprint: null);
final info = DeviceInfoPlugin();
String name = Platform.localHostname;
String? raw;
if (Platform.isMacOS) {
final m = await info.macOsInfo;
name = m.computerName;
raw = m.systemGUID;
} else if (Platform.isWindows) {
final w = await info.windowsInfo;
name = w.computerName;
raw = w.deviceId;
} else if (Platform.isLinux) {
raw = (await info.linuxInfo).machineId;
}
// Mobile, or a desktop that returned null: a random id this install keeps.
raw ??= await _installId();
// The salt makes the value useless for tracking across your other apps.
return (name: name, fingerprint: sha256.convert(utf8.encode('inkwell|$raw')).toString());
}
Future<String> _installId() async {
var id = await _store.read(key: 'clavem.install_id');
if (id == null) {
final random = Random.secure();
id = List.generate(16, (_) => random.nextInt(256).toRadixString(16).padLeft(2, '0')).join();
await _store.write(key: 'clavem.install_id', value: id);
}
return id;
}
/// Returns null on success, or a sentence to show the customer.
Future<String?> activate(String licenseKey) async {
final d = await describeDevice();
final r = await clavemPost('activate', {
'license_key': licenseKey.trim(),
'instance_name': d.name,
if (d.fingerprint != null) 'fingerprint': d.fingerprint!,
});
if (r.status == 200 && r.body['activated'] == true) {
await _store.write(
key: 'clavem.license',
value: jsonEncode({
'key': licenseKey.trim(),
'instance': (r.body['instance'] as Map)['id'],
'token': r.body['token'],
}),
);
return null;
}
if (r.status == 400) {
final lk = r.body['license_key'];
// Expired and disabled licenses also answer 400 with this block, so check the status first.
if (lk is Map &&
lk['status'] == 'active' &&
lk['activation_limit'] != null &&
lk['activation_usage'] == lk['activation_limit']) {
return 'This license is already used on ${lk['activation_usage']} of ${lk['activation_limit']} devices. '
'Remove one at clavem.io/licenses/manage, then try again.';
}
return r.body['error'] as String? ?? 'Activation failed.';
}
if (r.status == 404) return 'That key was not found. Check it for typos.';
return 'Could not reach the license server. Try again in a minute.';
}
When the limit is reached
The limit is a 400 with This license key has reached the activation limit. and a license_key block holding activation_limit and activation_usage. Show those numbers and send the buyer to the device page at clavem.io/licenses/manage. They enter their key, see each machine by instance_name, and remove one. That is why a readable name matters.
Expired and disabled licenses are refused with 400 before the limit is checked, and their response carries the same license_key block. That is why the code looks at status first, then shows error as it comes.
Moving to another computer
/// True when the seat is free: removed now, or already gone.
Future<bool> deactivate() async {
final text = await _store.read(key: 'clavem.license');
if (text == null) return true;
final saved = jsonDecode(text) as Map<String, dynamic>;
final r = await clavemPost('deactivate', {
'license_key': saved['key'] as String,
'instance_id': saved['instance'] as String,
});
if (r.status == 200 || r.status == 404) {
await _store.delete(key: 'clavem.license');
return true;
}
return false; // no answer: keep local state and tell the customer to try again
}
Clear local state only after the server confirms, or says the instance is already gone with a 404. If you clear it after a timeout, the seat stays taken and your app no longer knows its instance.id.
Edge cases specific to desktop Flutter
- Two OS users, one machine. The fingerprint is machine-wide and secure storage is per user. The second user’s activation returns the first user’s seat, so it costs nothing. If one of them deactivates, the other’s next validate answers
404and the app asks for the key again. - A reinstalled OS or new hardware produces a new fingerprint and a second seat. The customer removes the old one on the device page.
- A cloned VM image shares its Linux machine id and Windows device id with the original, so both count as one seat.
- Never deactivate on exit. A crash, a sleep, or a closed lid would leave the app unsure, and each quit would waste a round trip. Deactivate on an explicit “Move license” action.
- Release-mode networking. If activation works in debug but not in release, check the INTERNET permission on Android and the network client entitlement on macOS, as noted on the validation page.
Doing this with Clavem
Seats, names and the buyer-facing device page come with the product; you pick the default device limit when you create it. See device limits and the API reference for every field.
Questions
What fingerprint should a Flutter app send on Android and iOS?
A random id your app creates on first launch and keeps in secure storage. The hardware ids device_info_plus exposes on mobile are either not stable or not an identifier, so a stored random id is the honest choice. It changes when the app is reinstalled.
What happens when the same machine activates twice?
If both calls send the same fingerprint, the second returns the existing seat with its name updated. Without a fingerprint, every activation takes a new seat until the limit is reached.