AtlatestRepositorysigil-quic
sigil-quic / tree / scriptsinject-secret-spy.mjs
1
// Test-only instrumentation. Run remotely with explicit input/output paths;2
// never use this file as a package hook or modify the shipped module in place.3
import { readFileSync, writeFileSync } from 'node:fs';5
const [input, output] = process.argv.slice(2);6
if (!input || !output || input === output) {7
throw new Error('Usage: inject-secret-spy.mjs INPUT OUTPUT');8
}9
let source = readFileSync(input, 'utf8');10
if (!source.includes('(define-library (sigil quic tls schedule)') ||11
source.includes('secret-spy')) {12
throw new Error('Expected an uninstrumented TLS schedule');13
}14
const imported = '(import (sigil crypto)';15
if (source.split(imported).length !== 2 ||16
[...source.matchAll(/\(hkdf-sha256-extract(?=\s)/g)].length !== 3 ||17
[...source.matchAll(/\(hmac-sha256-bytes(?=\s)/g)].length !== 1) {18
throw new Error('Schedule primitive/import sites changed');19
}20
source = source.replace(imported,21
'(import (sigil quic tests secret spy)\n (sigil crypto)');22
source = source.replace(/\(hkdf-sha256-extract(?=\s)/g, '(secret-spy-extract')23
.replace(/\(hmac-sha256-bytes(?=\s)/g, '(secret-spy-hmac');24
writeFileSync(output,25
';;; TEST ONLY: retained primitive inputs; never ship this variant.\n' + source);