Client 1.3.0: sends one-way hashes of the device's ids at sign-in and sign-up (device.js), for the server's hardware bans; says when the server needs a newer client, and when a device is banned

This commit is contained in:
Burrowdev committed 2026-10-17 21:35:38 +03:00
1 parent 87695c3250
commit a2b70affcc
5 files changed
+212 -12

No files matched your search

+184
View File
@@ -0,0 +1,184 @@
"use strict";
const {app} = require("electron");
const {execFile} = require("child_process");
const crypto = require("crypto");
const fs = require("fs");
const os = require("os");
const path = require("path");
// what the server is told about this computer at every sign-in, for
// keeping a banned player's computer out (the server's lib/devices.js).
// nothing is sent as it is: each value is SHA-256 of
// "burrow-device:<kind>:<value>", the value in small letters.
//
// os the system's own id: MachineGuid (Windows), IOPlatformUUID
// (macOS), /etc/machine-id (Linux)
// board the board's id (Windows: the SMBIOS UUID) or the computer's
// serial number (macOS); Linux keeps both from users
// disk the disks' serial numbers
// mac the network cards' addresses, not virtual ones
// install an id of the client's own, kept in two or three places
//
// what looks wrong (the system id missing, or not shaped as it always is,
// or the client's own ids disagreeing) goes as notes. it is read once, at
// start, and takes a second or two on Windows (PowerShell).
const TIMEOUT_MS = 15000;
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
const MACHINE_ID = /^[0-9a-f]{32}$/;
const TOKEN = /^[0-9a-f]{64}$/;
// network cards that are not one: virtual machines' and containers' own.
const VIRTUAL_NAME = /^(lo|docker|veth|br-|virbr|vmnet|vboxnet|tun|tap|wg|zt|utun|awdl|llw|bridge|ham|tailscale|vEthernet)/i;
const VIRTUAL_MAC = /^(00:05:69|00:0c:29|00:1c:14|00:50:56|08:00:27|0a:00:27|52:54:00|00:15:5d|00:1c:42|00:16:3e|02:42)/;
const hash = (kind, value) => crypto.createHash("sha256").update(`burrow-device:${kind}:${String(value).trim().toLowerCase()}`).digest("hex");
const run = (file, args) => new Promise(resolve => {
execFile(file, args, {timeout: TIMEOUT_MS, windowsHide: true, maxBuffer: 1024 * 1024}, (error, stdout) => resolve(error ? "" : String(stdout)));
});
const readFile = file => {
try {
return fs.readFileSync(file, "utf8").trim();
}
catch (err) {
return "";
}
};
const writeFile = (file, text) => {
try {
fs.mkdirSync(path.dirname(file), {recursive: true});
fs.writeFileSync(file, text);
}
catch (err) {
// somewhere it cannot be kept; the others may do.
}
};
const windows = async () => {
const guid = (/MachineGuid\s+REG_SZ\s+(\S+)/i.exec(await run("reg", ["query", "HKLM\\SOFTWARE\\Microsoft\\Cryptography", "/v", "MachineGuid"])) || [])[1] || "";
const cim = await run("powershell", ["-NoProfile", "-NonInteractive", "-Command",
"(Get-CimInstance Win32_ComputerSystemProduct).UUID; '--'; Get-CimInstance Win32_DiskDrive | ForEach-Object { $_.SerialNumber }"]);
const [board, disks] = cim.split(/^--\s*$/m);
return {os: guid, osShape: UUID, board: (board || "").trim(), disks: (disks || "").split(/\r?\n/)};
};
const mac = async () => {
const ioreg = await run("ioreg", ["-rd1", "-c", "IOPlatformExpertDevice"]);
const field = name => ((new RegExp(`"${name}"\\s*=\\s*"([^"]+)"`)).exec(ioreg) || [])[1] || "";
const storage = await run("system_profiler", ["SPNVMeDataType", "SPSerialATADataType"]);
const disks = [];
const serial = /Serial Number:\s*(\S+)/g;
let found = serial.exec(storage);
while (found) {
disks.push(found[1]);
found = serial.exec(storage);
}
return {os: field("IOPlatformUUID"), osShape: UUID, board: field("IOPlatformSerialNumber"), disks};
};
const linux = async () => {
let disks = [];
try {
// the names say the model and the serial ("ata-Samsung_SSD_860_S3Z9NB0K123456X"),
// and anyone may read them; not partitions, USB sticks or their other names.
disks = fs.readdirSync("/dev/disk/by-id").filter(name => /^(ata|nvme|scsi|mmc)-/.test(name) && !/-part\d+$/.test(name)
&& !/^nvme-(eui|nvme)\./.test(name));
}
catch (err) {
// no such folder: a container, say.
}
return {os: readFile("/etc/machine-id") || readFile("/var/lib/dbus/machine-id"), osShape: MACHINE_ID, board: "", disks};
};
const macAddresses = () => {
const found = new Set();
const cards = os.networkInterfaces();
for (const name of Object.keys(cards)) {
for (const card of cards[name]) {
const address = String(card.mac || "").toLowerCase();
// the second bit of the first byte marks an address made up by the system (random, or virtual).
const madeUp = (parseInt(address.slice(0, 2), 16) & 2) === 2;
if (!card.internal && address && address !== "00:00:00:00:00:00" && !madeUp && !VIRTUAL_NAME.test(name) && !VIRTUAL_MAC.test(address)) {
found.add(address);
}
}
}
return [...found].sort();
};
// the client's own id: the same one wherever it is found, written back
// where it is missing. a new one when there is none.
const installId = async notes => {
const places = [path.join(app.getPath("userData"), "install-id")];
if (process.platform === "darwin") {
places.push(path.join(os.homedir(), "Library", "Preferences", ".moe.burrow.install"));
}
else if (process.platform !== "win32") {
places.push(path.join(os.homedir(), ".local", "share", ".burrow-install"));
}
const found = places.map(readFile).filter(text => TOKEN.test(text));
// on Windows the registry is the other place.
const registry = process.platform === "win32"
? (/Install\s+REG_SZ\s+(\S+)/i.exec(await run("reg", ["query", "HKCU\\Software\\Burrow", "/v", "Install"])) || [])[1] || "" : "";
if (TOKEN.test(registry)) {
found.push(registry);
}
if (new Set(found).size > 1) {
notes.push("install_mismatch");
}
const id = found[0] || crypto.randomBytes(32).toString("hex");
for (const place of places) {
if (readFile(place) !== id) {
writeFile(place, id);
}
}
if (process.platform === "win32" && registry !== id) {
await run("reg", ["add", "HKCU\\Software\\Burrow", "/v", "Install", "/t", "REG_SZ", "/d", id, "/f"]);
}
return id;
};
const collect = async () => {
const notes = [];
let read = {os: "", osShape: null, board: "", disks: []};
try {
read = process.platform === "win32" ? await windows() : process.platform === "darwin" ? await mac() : await linux();
}
catch (err) {
// what could be read is sent; the rest is not.
}
const system = String(read.os || "").trim().toLowerCase().replace(/^\{|\}$/g, "");
if (!system) {
notes.push("os_missing");
}
else if (read.osShape && !read.osShape.test(system)) {
notes.push("os_odd");
}
const disks = [...new Set((read.disks || []).map(serial => String(serial).trim()).filter(Boolean))].slice(0, 8);
const ids = {
install: hash("install", await installId(notes)),
disk: disks.map(serial => hash("disk", serial)),
mac: macAddresses().slice(0, 8).map(address => hash("mac", address)),
};
if (system) {
ids.os = hash("os", system);
}
if (String(read.board || "").trim()) {
ids.board = hash("board", read.board);
}
return {v: 1, ids, notes};
};
let collecting = null;
// {v: 1, ids, notes}, read once and kept.
const device = () => {
if (!collecting) {
collecting = collect().catch(() => ({v: 1, ids: {}, notes: ["failed"]}));
}
return collecting;
};
module.exports = {device};
+18 -10
View File
@@ -336,7 +336,7 @@
<label>2FA code
<input id="totp" type="text" inputmode="numeric" maxlength="20" spellcheck="false">
</label>
<label class="check"><input id="remember-device" type="checkbox"> Trust this computer for 30 days</label>
<label class="check"><input id="remember-device" type="checkbox"> Trust this device for 30 days</label>
</div>
<label class="check"><input id="remember" type="checkbox"> Remember me</label>
<button id="log-in" class="main" type="submit">Log in</button>
@@ -498,6 +498,7 @@
choose_animal: "Choose an animal first.",
too_many_registrations: "Too many accounts were created from your address. Try again in an hour.",
address_banned: "Your address is banned.",
device_banned: "This device is banned.",
agree_first: "Tick the box to agree first.",
same_name: "That is the name that was rejected.",
captcha_required: "Complete the captcha.",
@@ -646,7 +647,7 @@
remove.type = "button";
remove.className = "forget";
remove.textContent = "×";
remove.title = `Forget ${entry.username} on this computer`;
remove.title = `Forget ${entry.username} on this device`;
remove.setAttribute("aria-label", remove.title);
remove.addEventListener("click", () => {
forget(entry.server, entry.username);
@@ -783,13 +784,13 @@
let banServer = null;
// the popup of a ban: how long, why, and where to ask about it (and,
// when it is for good, where the account can be deleted).
// `ofAddress`: it is the address that is banned, not the account.
const showBan = (server, username, seconds, reason, ofAddress = false) => {
// `of`: what is banned: false the account, true its address, "device" this device.
const showBan = (server, username, seconds, reason, of = false) => {
banServer = server;
const left = Number(seconds);
$("ban-title").textContent = banTitle(left);
$("ban-name").textContent = username;
$("ban-address").textContent = ofAddress ? " · your address" : "";
$("ban-address").textContent = of === "device" ? " · this device" : of ? " · your address" : "";
$("ban-reason-part").hidden = !reason;
$("ban-facts").classList.toggle("bare", !reason);
$("ban-until").textContent = left < 0 ? "Permanent"
@@ -872,10 +873,13 @@
remember_device: !$("code-part").hidden && $("remember-device").checked,
captcha_pass: given ? given.captchaPass : passFor(server, username),
};
// which computer this is (the client's device.js): the server lets no
// sign-in in without it.
const device = await window.client.device();
const authenticate = body => getJson(`${server}/authenticate`, {
method: "POST",
headers: {"Content-Type": "application/json"},
body: JSON.stringify(body),
body: JSON.stringify({...body, device}),
});
let auth = await authenticate(request);
if (auth.body.error === "captcha_required") {
@@ -891,6 +895,9 @@
if (SIGNUP_MESSAGES[auth.body.error] && /^captcha_/.test(auth.body.error)) {
throw new Error(SIGNUP_MESSAGES[auth.body.error]);
}
if (auth.status === 426 || auth.body.error === "client_outdated") {
throw new Error("This server needs a newer Burrow client. Update it from the server's download page.");
}
if (auth.status === 401 && auth.body.error === "totp_required") {
showCodePart(true);
$("totp").focus();
@@ -904,9 +911,10 @@
// banned: for good, or for how much longer. (A saved sign-in is
// kept: it is the ban that is in the way, not the sign-in.)
// An address is banned for good, whoever signs in from it.
if (auth.status === 401 && (auth.body.error === "account_banned" || auth.body.error === "address_banned")) {
const ofAddress = auth.body.error === "address_banned";
showBan(server, username, ofAddress ? -1 : Number(auth.body.banned_seconds), String(auth.body.ban_reason || ""), ofAddress);
// A computer likewise (the server's lib/devices.js).
if (auth.status === 401 && ["account_banned", "address_banned", "device_banned"].includes(auth.body.error)) {
const of = auth.body.error === "device_banned" ? "device" : auth.body.error === "address_banned";
showBan(server, username, of ? -1 : Number(auth.body.banned_seconds), String(auth.body.ban_reason || ""), of);
throw new Error("Banned.");
}
if (auth.status === 401 && auth.body.error === "name_rejected") {
@@ -1085,7 +1093,7 @@
closeGame();
}
showBan(ended.server, ended.flashVars.username, Number(answer.body.banned_seconds), String(answer.body.ban_reason || ""),
answer.body.banned === "address");
answer.body.banned === "device" ? "device" : answer.body.banned === "address");
}
};
+7 -1
View File
@@ -3,6 +3,7 @@
const {app, BrowserWindow, ipcMain, net, session, shell, webContents} = require("electron");
const fs = require("fs");
const path = require("path");
const device = require("./device.js");
const relay = require("./relay.js");
const updater = require("./updater.js");
@@ -182,6 +183,9 @@ ipcMain.handle("setGpu", (event, on) => {
fs.writeFileSync(SETTINGS_FILE, JSON.stringify({...readSettings(), gpu: on === true}));
});
// what the server is told about this computer at sign-in (device.js).
ipcMain.handle("device", () => device.device());
ipcMain.handle("info", () => ({
// as this run was started; a change takes effect at the next start.
gpu: usesGpu,
@@ -274,7 +278,8 @@ ipcMain.handle("api", async (event, serverUrl, call, body) => {
if (!API_CALLS[call] || !/^https?:\/\//.test(String(serverUrl))) {
return {status: 0, body: {}};
}
const first = await apiRequest(serverUrl, call, body);
// a sign-up says which computer it is on, as a sign-in does (device.js).
const first = await apiRequest(serverUrl, call, call === "register" ? {...body, device: await device.device()} : body);
if (call !== "status" || first.status === 0) {
return first;
}
@@ -480,6 +485,7 @@ app.on("web-contents-created", (event, contents) => {
});
app.whenReady().then(() => {
device.device(); // read now, so the first sign-in does not wait
session.defaultSession.webRequest.onBeforeRequest((details, answer) => answer({cancel: !mayLoad(details)}));
session.fromPartition(CAPTCHA_PARTITION).webRequest.onBeforeRequest((details, answer) => {
let url = null;
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "aj-private-client",
"productName": "Burrow",
"version": "1.2.0",
"version": "1.3.0",
"description": "The client for the Burrow private server",
"main": "boot.js",
"license": "UNLICENSED"
+2
View File
@@ -8,6 +8,8 @@ contextBridge.exposeInMainWorld("client", {
useServer: (serverUrl, gamePort, gameHost) => ipcRenderer.invoke("useServer", serverUrl, gamePort, gameHost),
// one of the server's /api calls ("status", "register", "ban"): {status, body, ms}.
api: (serverUrl, call, body) => ipcRenderer.invoke("api", serverUrl, call, body),
// hashes of this computer's ids, for the server's sign-in (device.js).
device: () => ipcRenderer.invoke("device"),
// the server's captcha ("login" or "signup") in a window of its own: its answer, or "" when there is none.
captcha: (serverUrl, action) => ipcRenderer.invoke("captcha", serverUrl, action),
setGpu: on => ipcRenderer.invoke("setGpu", on),