fix(license): bind deviceId to physical machine, not OS user

Use OS machine identifiers (Windows MachineGuid, macOS IOPlatformUUID, Linux machine-id) hashed as deviceId so all accounts on one PC share one license slot. Keep legacy userData/device.id for migration and retire it on re-activation.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Ivan Fontosh
2026-07-23 10:39:46 +08:00
parent c1c332364c
commit 32a5479086
11 changed files with 399 additions and 24 deletions
+21 -8
View File
@@ -1,18 +1,31 @@
import { randomUUID } from 'node:crypto';
import fs from 'node:fs';
import { resolveMachineFingerprint } from './machineFingerprint';
import { deviceIdPath } from './paths';
export function getOrCreateDeviceId(userData: string): string {
const p = deviceIdPath(userData);
/** Старый per-user UUID из userData/device.id (до привязки к железу). */
export function readLegacyDeviceId(userData: string): string | null {
try {
const existing = fs.readFileSync(p, 'utf8').trim();
const existing = fs.readFileSync(deviceIdPath(userData), 'utf8').trim();
if (existing.length >= 8) return existing;
} catch {
/* empty */
}
const id = randomUUID();
fs.mkdirSync(userData, { recursive: true });
fs.writeFileSync(p, `${id}\n`, 'utf8');
return id;
return null;
}
export function clearLegacyDeviceId(userData: string): void {
try {
fs.unlinkSync(deviceIdPath(userData));
} catch {
/* empty */
}
}
/**
* Идентификатор устройства для лицензии: отпечаток физической машины.
* Одинаков для всех пользователей ОС на одном ПК (Windows/macOS/Linux).
*/
export function getOrCreateDeviceId(_userData?: string): string {
return resolveMachineFingerprint();
}