AtlatestRepositorysigil-quic

sigil-quic / tree / scriptsinject-retry-faults.mjs

1// Remote-only sensitivity checks. Restore canonical TLS before full gates.
2import { readFileSync, writeFileSync } from 'node:fs';
3
4const [input, output] = process.argv.slice(2);
5if (!input || !output || input === output) {
6 throw new Error('Usage: inject-retry-faults.mjs INPUT OUTPUT');
7}
8let source = readFileSync(input, 'utf8');
9if (source.includes('TEST ONLY')) throw new Error('Expected canonical handshake source');
10function replaceOnce(before, after) {
11 if (source.split(before).length !== 2) throw new Error('Expected one canonical HRR guard');
12 source = source.replace(before, () => after);
14replaceOnce(` (unless (and (= (tls-server-hello-cipher-suite hello) 4865)
15 (bytes=? (tls-server-hello-session-id hello)
16 (tls-client-hello-session-id (tls-handshake-hello engine)))
17 (bytes=? (extension extensions 43) #u8(3 4)))
18 (error "TLS: invalid ServerHello selection"))`, ' #t');
19replaceOnce(' (unless (or group cookie) (error "TLS: HelloRetryRequest makes no change"))', ' #t');
20replaceOnce(` (unless (and share (= (length shares) 1)
21 (not (assoc 42 extensions))
22 (psk-identities-subsequence? identities
23 (client-psk-identities
24 (tls-client-hello-extensions (tls-handshake-hello engine))))
25 (bytes=? (immutable-client-hello hello)
26 (immutable-client-hello (tls-handshake-hello engine))))
27 (raise-tls-alert 47 "TLS: illegal second ClientHello change"))`, ' #t');
28replaceOnce(' (unless shared (error "TLS: invalid X25519 peer key"))',
29 ' (unless shared (set! shared (make-bytevector 32 0)))');
30writeFileSync(output, ';;; TEST ONLY: HRR and rejected-DH guards weakened for sensitivity.\n' + source);