taper / server /dms-order.js
abr00kx's picture
Upload Taper: hardened ephemeral E2EE messaging protocol (Matrix hard fork) (part 4)
b855ced verified
Raw History Blame Contribute Delete
1.97 kB
#!/usr/bin/env node
// Operator keys and signed orders for the dead man's switch. Runs offline, on
// the operator's own machine: the private key never goes to the server.
//
// node dms-order.js keygen alice writes alice.dms.pem and alice.duress.pem,
// prints alice's line for the operators file
// node dms-order.js sign KEY.pem SERVER_NAME checkin|decommission
// prints an order, valid for 10 minutes
//
// Deliver an order with `admin.js order TOKEN` on the server, or over the
// network to the switch's secret path:
// curl --data-binary TOKEN https://example.org/<TAPER_DMS_PATH>
// (through Tor: add --socks5-hostname 127.0.0.1:9050).
import { writeFileSync, readFileSync, existsSync } from 'node:fs';
import { generateOperatorKey, signOrder } from './dms.js';
const [cmd, a, b, c] = process.argv.slice(2);
const USAGE = 'usage: dms-order.js keygen NAME | sign KEY.pem SERVER_NAME checkin|decommission';
if (cmd === 'keygen' && /^[A-Za-z0-9_.-]{1,40}$/.test(a ?? '')) {
const normal = generateOperatorKey();
const duress = generateOperatorKey();
for (const [file, key] of [[`${a}.dms.pem`, normal], [`${a}.duress.pem`, duress]]) {
if (existsSync(file)) { console.error(`${file} already exists; not overwriting it.`); process.exit(1); }
writeFileSync(file, key.privatePem, { mode: 0o600, flag: 'wx' });
}
console.error(`Wrote ${a}.dms.pem (your key) and ${a}.duress.pem (use it only under coercion: it wipes the server).`);
console.error('Add this line to the server\'s operators file (TAPER_DMS_OPERATORS):');
console.log(`${a} ${normal.publicKey} ${duress.publicKey}`);
} else if (cmd === 'sign' && a && b && c) {
try {
console.log(signOrder({ privatePem: readFileSync(a, 'utf8'), server: b, action: c }));
} catch (e) { console.error(e.message); process.exit(1); }
} else {
console.error(USAGE);
process.exit(2);
}