// The TLS material for the test nginx (#66, DESIGN 11.1 / TESTING 11.1) and the `serve` playtest // stack (M4 #80). A self-signed certificate is GENERATED at run time, never committed: browsers // only negotiate HTTP/2 over TLS, and the session cookie is `Secure`, so the browser e2e, the // harnesses and a phone on the LAN have to speak https. // // One directory per run (`run/tls`, gitignored) is shared by every harness file in the run: the // certificate is a trust anchor for the Node side through NODE_EXTRA_CA_CERTS (set by tools/test.sh // and client/e2e/run.sh), and nginx loads the same pair. For `devbox run serve` the same helper // writes a PERSISTENT pair under the state dir with the LAN IP in the SANs, so the phone trusts it // once and keeps trusting it across restarts. import { spawnSync } from 'node:child_process' import fs from 'node:fs' import path from 'node:path' const SUBJECT = '/CN=fff-vtt test nginx' const SAN = 'DNS:localhost,IP:127.0.0.1' const DAYS = 3 function generate(dir, { subject, sans, days }) { fs.mkdirSync(dir, { recursive: true }) const certPath = path.join(dir, 'cert.pem') const keyPath = path.join(dir, 'key.pem') const r = spawnSync('openssl', [ 'req', '-x509', '-newkey', 'ec', '-pkeyopt', 'ec_paramgen_curve:prime256v1', '-nodes', '-sha256', '-days', String(days), '-keyout', keyPath, '-out', certPath, '-subj', subject, // CA:TRUE so the pair is usable as a trust anchor (NODE_EXTRA_CA_CERTS, Android's user CA // store) as well as a leaf; serverAuth + digitalSignature so a browser/h2 client accepts it // as a TLS server certificate. '-addext', `subjectAltName=${sans}`, '-addext', 'basicConstraints=critical,CA:TRUE', '-addext', 'keyUsage=critical,digitalSignature,keyCertSign', '-addext', 'extendedKeyUsage=serverAuth', ], { encoding: 'utf8' }) if (r.status !== 0) { throw new Error(`openssl could not generate the certificate (is the openssl devbox ` + `package installed?):\n${r.stdout}\n${r.stderr}`) } return { certPath, keyPath } } // Ensures