Repository navigation
Proxy: speak TLS 1.2 as well as 1.3 through the CONNECT tunnel - #105
Conversation
subtls speaks TLS 1.3 only, so every HTTPS site that tops out at TLS 1.2 failed on the proxy path. Of the 40 mainland China https hosts probed, 18 offer TLS 1.2 at most. Replace subtls with an Mbed TLS 4.2.0 client compiled to Wasm (@ai-ecoverse/wasm-tls-engine). It handshakes TLS 1.2 or 1.3 over the tunnel, builds the certificate chain from what the server sends and verifies it against the same Mozilla roots, checks the name and the validity dates. Wrangler compiles the .wasm at deploy time, since Workers compile no Wasm from bytes; vitest loads it the same way. Run locally in workerd against those 40 hosts directly (no proxy): 38 complete; the two that do not are a site that sends no intermediate certificate and one that closed the connection. badssl.com's expired, wrong-host, self-signed and untrusted-root certificates are refused. The tests now handshake for real with a local Node TLS server limited to TLS 1.2 or 1.3, using a test-only CA, instead of mocking the TLS layer. Co-authored-by: Amp <[email protected]> Amp-Thread-ID: https://ampcode.com/threads/T-01a19236-e961-759a-a320-167408397ed5
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
website2markdown | 685f1e1 | Nov 21 2026, 01:46 PM |
If the engine asked for more ciphertext while refusing what it already had, the handshake and read loops would await only resolved promises, so the timer behind the proxy deadline could never fire. Retry the feed once (room may have freed) and throw if it still takes nothing. Co-authored-by: Amp <[email protected]> Amp-Thread-ID: https://ampcode.com/threads/T-01a19236-e961-759a-a320-167408397ed5
… sessions From review of the TLS 1.2 change: - A tunnel that closed in the middle of a TLS record ended the response as if it were complete, so a truncated page could come back as 200. The engine reports either close the same way, so track the record framing of the ciphertext and accept a close only between records. - Mbed TLS matches the Common Name when the leaf has no subjectAltName; subtls and browsers refuse such certificates. Require the extension. - A handshake that finished after the deadline or an abort had already failed the request left its session in the shared Wasm heap. Free it. Amp-Thread-ID: https://ampcode.com/threads/T-01a19236-e961-759a-a320-167408397ed5 Co-authored-by: Amp <[email protected]>
|
@codex review |
|
Codex Review: Didn't find any major issues. You're on a roll. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Why
The proxy path did TLS with subtls, which speaks TLS 1.3 only. Every HTTPS site that tops out at TLS 1.2 failed there. Of the 40 mainland China https hosts I probed, 18 offer TLS 1.2 at most, so even with a mainland proxy exit about half of them could not be reached.
What changes
src/proxy-tls.ts(new): a TLS client over the CONNECT tunnel, using Mbed TLS 4.2.0 compiled to Wasm (@ai-ecoverse/wasm-tls-engine, Apache-2.0). It negotiates TLS 1.2 or 1.3, builds the chain from the certificates the server sends, and verifies it against the same Mozilla roots (proxy-roots.ts), the host name and the validity dates. No verification flag is relaxed.src/proxy.ts: uses it in place of subtls. The deadline, root-dot handling and CONNECT handling are unchanged; the session is freed infinally..wasmis imported as a module (Wrangler compiles it at deploy time) and handed to the Emscripten glue for its one instantiate call.vitest.config.tsloads.wasmimports the same way.subtlsis removed from the dependencies.Evidence
Run in workerd (
wrangler dev) against the 40 hosts directly, without a proxy:www.nmgacc.cn,sjt.zj.gov.cn,www.bijie.gov.cn,kjw.hlj.gov.cn, …).www.als.gov.cnis refused: it sends no intermediate certificate (OpenSSL also reports "unable to verify the first certificate").www.cec.org.cnclosed the connection; curl from the same machine fails too.expired,wrong.host,self-signedanduntrusted-root.badssl.comare all refused with the matching verification error.Tests
src/__tests__/fixtures/proxy-tls/are a test-only CA and leaf (valid until 2126); the key protects nothing.npx tsc --noEmit -p . && npx tsc --noEmit -p web/tsconfig.json;npx vitest run: 954 pass.wrangler deploy --dry-runbundles the.wasmas its own module (320 KB).