AtlatestRepositorysigil-quic
sigil-quic / tree / scriptsinject-retention-spy.mjs
1
// Test-only owned-buffer observation. Run remotely with explicit input/output2
// paths; never install as a package hook or rewrite a 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-retention-spy.mjs INPUT OUTPUT');8
}9
let source = readFileSync(input, 'utf8');10
const imported = '(import (sigil crypto)';11
if (!source.includes('(define-library (sigil quic tls handshake)') ||12
source.includes('secret-spy') || source.split(imported).length !== 2) {13
throw new Error('Expected an uninstrumented TLS handshake');14
}15
source = source.replace(imported,16
'(import (sigil quic tests secret spy)\n (sigil crypto)');17
for (const [direction, label] of [['client', 'c'], ['server', 's']]) {18
const site = `(set-tls-handshake-${direction}-hs! engine (derive-secret secret "${label} hs traffic" hash))`;19
if (source.split(site).length !== 2) throw new Error('Handshake assignment site changed');20
const observed = `(set-tls-handshake-${direction}-hs! engine21
(secret-spy-track!22
(if (eq? (tls-role engine) 'server) 'server-${direction}-hs 'client-${direction}-hs)23
(derive-secret secret "${label} hs traffic" hash)))`;24
source = source.replace(site, () => observed);25
}26
writeFileSync(output,27
';;; TEST ONLY: observed owned handshake buffers; never ship this variant.\n' + source);