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
+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