@claw-link/gateway-host 0.2.3 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/machine.js +46 -17
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@claw-link/gateway-host",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "ClawLink Host Gateway — a secure, outbound-only worker that bridges a local agent CLI (OpenClaw, Hermes, Claude, Codex, Cursor) to your ClawLink agents. No inbound ports; authenticated per-agent by a Host Token.",
5
5
  "homepage": "https://claw-link.co",
6
6
  "bin": {
package/src/machine.js CHANGED
@@ -1,29 +1,58 @@
1
1
  'use strict';
2
- // Stable machine fingerprint for host binding. Derived from the host's physical
3
- // MAC address(es) + hostname, then hashed we send only the HASH to ClawLink, so
4
- // raw MACs never leave the machine. Supabase binds this on first connect; after
5
- // that, only this machine may act for the agent (a stolen token from elsewhere
6
- // fails the binding check).
2
+ // Stable machine fingerprint for host binding. We bind an agent's token to ONE
3
+ // machine so a stolen token can't be used elsewhere. The fingerprint MUST be
4
+ // stable across reboots and network changes earlier versions hashed MAC
5
+ // addresses, which rotate (Tailscale/Docker/VPN/private-WiFi) and caused false
6
+ // "host binding mismatch" errors. We now use the OS hardware machine id, with a
7
+ // persisted random id as a fallback, and send only the HASH.
7
8
 
8
9
  const os = require('os');
10
+ const fs = require('fs');
11
+ const path = require('path');
9
12
  const crypto = require('crypto');
13
+ const { execSync } = require('child_process');
14
+ const { enrichedEnv } = require('./paths');
10
15
 
11
- function macAddresses() {
12
- const macs = [];
13
- const ifaces = os.networkInterfaces();
14
- for (const name of Object.keys(ifaces)) {
15
- for (const ni of ifaces[name] || []) {
16
- if (ni.internal) continue;
17
- if (!ni.mac || ni.mac === '00:00:00:00:00:00') continue;
18
- macs.push(ni.mac.toLowerCase());
16
+ const HOME_DIR = path.join(os.homedir(), '.clawlink-host');
17
+
18
+ function execSafe(cmd) {
19
+ try { return execSync(cmd, { stdio: ['ignore', 'pipe', 'ignore'], timeout: 4000, env: enrichedEnv() }).toString(); }
20
+ catch { return ''; }
21
+ }
22
+
23
+ // Stable, hardware-tied id where available.
24
+ function hardwareId() {
25
+ try {
26
+ if (process.platform === 'darwin') {
27
+ const m = execSafe('ioreg -rd1 -c IOPlatformExpertDevice').match(/IOPlatformUUID"\s*=\s*"([^"]+)"/);
28
+ if (m) return 'hw:' + m[1];
29
+ } else if (process.platform === 'linux') {
30
+ for (const p of ['/etc/machine-id', '/var/lib/dbus/machine-id']) {
31
+ try { const id = fs.readFileSync(p, 'utf8').trim(); if (id) return 'hw:' + id; } catch { /* next */ }
32
+ }
33
+ } else if (process.platform === 'win32') {
34
+ const m = execSafe('reg query "HKLM\\SOFTWARE\\Microsoft\\Cryptography" /v MachineGuid').match(/MachineGuid\s+REG_SZ\s+([\w-]+)/i);
35
+ if (m) return 'hw:' + m[1];
19
36
  }
20
- }
21
- return [...new Set(macs)].sort();
37
+ } catch { /* fall through */ }
38
+ return null;
39
+ }
40
+
41
+ // Stable random id persisted under the home dir (fallback when no hardware id).
42
+ function persistedId() {
43
+ const idPath = path.join(HOME_DIR, 'machine-id');
44
+ try { const id = fs.readFileSync(idPath, 'utf8').trim(); if (id) return 'id:' + id; } catch { /* create below */ }
45
+ try {
46
+ fs.mkdirSync(HOME_DIR, { recursive: true });
47
+ const id = crypto.randomBytes(32).toString('hex');
48
+ fs.writeFileSync(idPath, id, { mode: 0o600 });
49
+ try { fs.chmodSync(idPath, 0o600); } catch { /* best effort */ }
50
+ return 'id:' + id;
51
+ } catch { return null; }
22
52
  }
23
53
 
24
54
  function machineId() {
25
- const macs = macAddresses();
26
- const basis = (macs.length ? macs.join(',') : 'no-mac') + '|' + os.hostname();
55
+ const basis = hardwareId() || persistedId() || ('host:' + os.hostname());
27
56
  return crypto.createHash('sha256').update(basis).digest('hex');
28
57
  }
29
58