AtlatestRepositorysigil-quic

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

1// Remote-only mutation sensitivity for certificate-policy tests.
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-certificate-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 certificate guard');
12 source = source.replace(before, () => after);
14replaceOnce(` (unless (and (bytes=? (tls-certificate-context certificate) #u8()) (pair? entries)
15 (let loop ((rest entries))
16 (or (null? rest) (and (null? (cdar rest)) (loop (cdr rest))))))
17 (error "TLS: missing server certificate or unsolicited certificate extension"))`, ' #t');
18replaceOnce(` (when (tls-handshake-request? engine)
19 (emit! engine 'handshake (encode-certificate #u8() '())))`, ' #t');
20writeFileSync(output, ';;; TEST ONLY: certificate guard and empty response removed for sensitivity.\n' + source);