Harden the app
This commit is contained in:
1 parent
d92c4b50cf
commit
e3a2b348d6
5 files changed
+38
-12
No files matched your search
+10
-7
@@ -258,21 +258,24 @@ function randomBinary(length: number) {
|
||||
|
||||
const CODE_CHARS = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
|
||||
// 8 of 62 characters. Bytes from 248 on are dropped, so every character is equally likely.
|
||||
// 10 of 62 characters. Bytes from 248 on are dropped, so every character is equally likely.
|
||||
function randomCode() {
|
||||
let code = '';
|
||||
while (code.length < 8)
|
||||
for (const byte of crypto.getRandomValues(new Uint8Array(8)))
|
||||
if (byte < 248 && code.length < 8) code += CODE_CHARS[byte % 62];
|
||||
while (code.length < 10)
|
||||
for (const byte of crypto.getRandomValues(new Uint8Array(10)))
|
||||
if (byte < 248 && code.length < 10) code += CODE_CHARS[byte % 62];
|
||||
return code;
|
||||
}
|
||||
|
||||
// The code is all both sides share. It gives the tracker swarm, identified by a 20 byte info_hash,
|
||||
// and the key that proves the connection, see prove. 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. HKDF splits the result, the public
|
||||
// info_hash tells nothing about the keys: one seals the signaling, see seal, one proves the connection.
|
||||
// what a share pays once (~50 ms). The salt is fixed, both sides only know the code, so the guesses
|
||||
// can also be made ahead of time, once for every share: a table from info_hash to code would let a
|
||||
// tracker take over any share as it happens. Only the code's length prices that: for 62¹⁰ codes
|
||||
// it's over a million GPU years. Any length derives the same way, an older client takes a longer
|
||||
// code. HKDF splits the result, the public info_hash tells nothing about the keys: one seals the
|
||||
// signaling, see seal, one proves the connection.
|
||||
async function secrets(code: string) {
|
||||
const text = new TextEncoder();
|
||||
const password = await crypto.subtle.importKey('raw', text.encode(code), 'PBKDF2', false, ['deriveBits']);
|
||||
|
||||
Reference in new issue
Block a user