Derive the swarm ID with PBKDF2 instead of SHA-1
Anyone who sees the swarm IDs could test a GPU's worth of codes against all of them at once, about 8 % of the codes within a share's 6 minutes. 600,000 iterations of PBKDF2-SHA-256 cost a share ~50 ms and make that negligible. Old and new clients no longer find each other. Also note the open decisions for the server at pagequit.net. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b6b6e7c29b
commit
707248f36b
3 files changed
+76
-5
No files matched your search
@@ -1,7 +1,67 @@
|
||||
# TODO
|
||||
|
||||
## Server at pagequit.net, to decide
|
||||
|
||||
### Review of the coturn setup (STUN only, host network)
|
||||
|
||||
- Good as it is: `stun-only`, `no-tcp`, `no-tls`, `no-software-attribute`, CPU, memory and process
|
||||
limits with swap off, and log rotation. Host networking is right for STUN, so Docker's NAT can't
|
||||
change the source address the clients get back. Listening on IPv4 only matches DNS:
|
||||
`stun.pagequit.net` has an A record and no AAAA.
|
||||
- `coturn/coturn:latest` is the only unpinned version. Pin `coturn/coturn:4.18.0` (2026-09-08).
|
||||
- Add `no-cli`. On the host network, coturn's admin CLI would otherwise listen on the host's
|
||||
127.0.0.1:5766 if it's enabled.
|
||||
- Add `no-stun-backward-compatibility`. Browsers only use the current STUN protocol, so the old
|
||||
RFC 3489 requests and their extra MAPPED-ADDRESS can go, which also makes responses smaller for
|
||||
reflection attacks.
|
||||
- Check that the logs hold no client addresses: send a STUN request, then
|
||||
`docker compose logs coturn | grep <your IP>`. Logging each request is off by default and
|
||||
`log-binding` turns it on, so it should stay empty. Otherwise up to 20 MB of addresses stay around.
|
||||
- Missing compared to the tracker draft: `cap_drop: [ALL]` and
|
||||
`security_opt: [no-new-privileges:true]`. `read_only: true` is worth trying too, but coturn may
|
||||
need a writable `/var/run` or `/var/lib/coturn` (`tmpfs`).
|
||||
- coturn doesn't rate limit STUN requests. A response is about as big as the request, so it's a weak
|
||||
amplifier. If it gets abused, an nftables `limit` on the UDP port would help.
|
||||
|
||||
### Compared to the plan so far
|
||||
|
||||
- Caddy and coturn don't share a Docker network, coturn runs on the host network. The tracker joins
|
||||
Caddy's network (its name is in Caddy's compose file), coturn stays as it is.
|
||||
- Copy coturn's limits to the tracker, with smaller values: `cpus`, `mem_limit` equal to
|
||||
`memswap_limit`, `pids_limit`, and the same `json-file` log rotation.
|
||||
- Pin every version, coturn and the tracker alike.
|
||||
|
||||
### Decisions
|
||||
|
||||
1. **Which tracker.** Stock `bittorrent-tracker@11.2.3` behind Caddy works: tested locally with a
|
||||
real transfer from Chromium to Firefox, and it logs nothing with `--quiet`. A review found it too
|
||||
open to run unchanged:
|
||||
- it forwards any data and accepts messages up to 100 MiB
|
||||
- `scrape` lists all swarms even with `--no-stats`
|
||||
- it has no rate, byte or connection limits
|
||||
- it accepts any Origin
|
||||
|
||||
The recommendation is an own tracker for the WebTorrent subset HellCon uses, so the client stays
|
||||
unchanged and the public trackers keep working as fallbacks. Node 26 and `ws`, one file of about
|
||||
250 lines, enforcing:
|
||||
- an Origin allowlist and messages of at most 16 KiB
|
||||
- only `announce`, one offer per announce, and answers only to offers it delivered, once
|
||||
- per connection: a message rate, about 64 KiB of forwarded data, and at most 7 minutes
|
||||
- connections per IP (from `X-Forwarded-For`), total connections and peers per swarm capped
|
||||
- empty swarms removed, nothing logged
|
||||
|
||||
Then decide where it lives: `tracker/` in this repo (new files, every fork gets it) or a separate
|
||||
repository.
|
||||
2. **After deploying:** put `wss://tracker.pagequit.net` first in `DEFAULT_TRACKERS` and keep the
|
||||
public trackers as fallbacks.
|
||||
|
||||
## Ideas
|
||||
|
||||
- Let the code confirm the connection instead of the user: both sides derive a second key from the
|
||||
code and send an HMAC over both DTLS fingerprints. An interposer without the code can't forge it,
|
||||
so the manual comparison and a careless confirm would no longer matter. Changes the protocol and
|
||||
the check UI, WebCrypto is enough.
|
||||
|
||||
- Resume interrupted transfers: the receiver already reports how much the download manager has
|
||||
read (`{ read }`), which is where a new connection could continue. The browser can't append to a
|
||||
finished or failed download though, so a resume would have to start a new one.
|
||||
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
import { createHash, randomBytes } from 'node:crypto';
|
||||
import { createHash, pbkdf2Sync, randomBytes } from 'node:crypto';
|
||||
import { createSocket, type Socket } from 'node:dgram';
|
||||
import { createReadStream } from 'node:fs';
|
||||
import { open as openFile, readFile, writeFile } from 'node:fs/promises';
|
||||
@@ -968,7 +968,7 @@ async function announceGarbage(code: string) {
|
||||
ws.send(
|
||||
JSON.stringify({
|
||||
action: 'announce',
|
||||
info_hash: binary(createHash('sha1').update(`hellcon:${code}`).digest()),
|
||||
info_hash: binary(pbkdf2Sync(code, 'hellcon', 600_000, 20, 'sha256')),
|
||||
peer_id: binary(randomBytes(20)),
|
||||
numwant: 1,
|
||||
uploaded: 0,
|
||||
|
||||
+14
-3
@@ -33,6 +33,8 @@ const CONNECT_TIMEOUT = 30_000;
|
||||
// else it drops them after a few minutes, but not more often than MIN_INTERVAL whatever it names.
|
||||
export const TRACKER_WAIT = 6 * 60_000;
|
||||
const MIN_INTERVAL = 30_000;
|
||||
// OWASP's recommendation for PBKDF2-SHA-256. Changing it splits old and new clients into separate swarms.
|
||||
const PBKDF2_ITERATIONS = 600_000;
|
||||
// Far beyond what a file system stores, but keeps an absurd name out of the page and the worker.
|
||||
const MAX_NAME = 1024;
|
||||
|
||||
@@ -141,10 +143,19 @@ function randomCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
// The tracker swarm is identified by a 20 byte info_hash, derived from the shared code.
|
||||
// The tracker swarm is identified by a 20 byte info_hash, derived from the shared code. Whoever sees
|
||||
// the swarms, a tracker or anyone scraping one, can test a guessed code against all of them at once.
|
||||
// PBKDF2 makes every guess cost what a share pays once (~50 ms), so a GPU gets through a vanishing
|
||||
// part of the 62⁸ codes within TRACKER_WAIT. The salt is fixed, both sides only know the code.
|
||||
async function infoHash(code: string) {
|
||||
const digest = await crypto.subtle.digest('SHA-1', new TextEncoder().encode(`hellcon:${code}`));
|
||||
return String.fromCharCode(...new Uint8Array(digest));
|
||||
const text = new TextEncoder();
|
||||
const key = await crypto.subtle.importKey('raw', text.encode(code), 'PBKDF2', false, ['deriveBits']);
|
||||
const bits = await crypto.subtle.deriveBits(
|
||||
{ name: 'PBKDF2', hash: 'SHA-256', salt: text.encode('hellcon'), iterations: PBKDF2_ITERATIONS },
|
||||
key,
|
||||
160,
|
||||
);
|
||||
return String.fromCharCode(...new Uint8Array(bits));
|
||||
}
|
||||
|
||||
function announce(ws: WebSocket, hash: string, peerId: string, params: object) {
|
||||
|
||||
Reference in new issue
Block a user