AtlatestRepositorysigil-quic
sigil-quic / tree / scriptsinject-retry-faults.mjs
1
// Remote-only sensitivity checks. Restore canonical TLS before full gates.2
import { readFileSync, writeFileSync } from 'node:fs';4
const [input, output] = process.argv.slice(2);5
if (!input || !output || input === output) {6
throw new Error('Usage: inject-retry-faults.mjs INPUT OUTPUT');7
}8
let source = readFileSync(input, 'utf8');9
if (source.includes('TEST ONLY')) throw new Error('Expected canonical handshake source');10
function replaceOnce(before, after) {11
if (source.split(before).length !== 2) throw new Error('Expected one canonical HRR guard');12
source = source.replace(before, () => after);13
}14
replaceOnce(` (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');19
replaceOnce(' (unless (or group cookie) (error "TLS: HelloRetryRequest makes no change"))', ' #t');20
replaceOnce(` (unless (and share (= (length shares) 1)21
(not (assoc 42 extensions))22
(psk-identities-subsequence? identities23
(client-psk-identities24
(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');28
replaceOnce(' (unless shared (error "TLS: invalid X25519 peer key"))',29
' (unless shared (set! shared (make-bytevector 32 0)))');30
writeFileSync(output, ';;; TEST ONLY: HRR and rejected-DH guards weakened for sensitivity.\n' + source);