fix(node:https,http2): accept Buffer-typed key/cert PEMs (#2132) - #2184
Merged
Conversation
`https.createServer({ key, cert })` and `http2.createSecureServer`
parsed their options object via `JSON.stringify` → `serde_json` →
`.as_str()`. Node-idiomatic callers pass PEMs as Buffers
(`fs.readFileSync('key.pem')` with no encoding), which round-trip
through that path as `{"type":"Buffer","data":[...]}` — losing the
`.as_str()` extraction and falling through to the
`"no recognized PEM private key"` branch with an empty PEM buffer.
Add a shared `json_value_to_pem_bytes` helper that recognizes the
Node Buffer shape and a bare numeric array, so both helpers accept
either string- or Buffer-typed PEMs. Threads byte buffers (not
`String`) end-to-end since PEM is opaque to the TLS parsers.
This was the diff-bucket cluster surfaced by the node-core radar
for the three https tests cited in #2132 (agent-abort-controller,
agent-keylog, byteswritten); after the fix, agent-abort-controller
flips to pass, the other two move past the PEM error to surface
unrelated downstream gaps (cert version, console output).
Includes unit tests covering string PEM, Buffer-shape JSON, bare
numeric array, and the empty/unknown fallbacks.
This was referenced May 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Towards #2132.
https.createServer({ key, cert })andhttp2.createSecureServerrejected the Node-idiomatic Buffer form ofkey/cert(the shapefs.readFileSync('key.pem')returns when no encoding is supplied), printing"[node:https] no recognized PEM private key"and refusing to listen.Why
The two helpers round-trip their options object through
JSON.stringify→serde_json→.as_str(). A Buffer JSON-serializes as{"type":"Buffer","data":[...]}, so.as_str()returnsNone, the PEM buffer becomes empty, and the request bottoms out in the "no recognized PEM private key" branch. The node-core radar (#800) surfaced this as the diff-bucket cause for the three https tests cited in #2132:test-https-agent-abort-controller.jstest-https-agent-keylog.jstest-https-byteswritten.jsFix
Add a shared
json_value_to_pem_byteshelper intls.rsthat recognizes both the Node Buffer shape and a bare numeric array, and decodes them to bytes. Both option-parsers now thread byte buffers (notString) end-to-end — PEM is opaque to the TLS parsers, so there's no reason to require valid UTF-8.Verified
cargo test --release -p perry-ext-http-server --lib— 12 passed (4 new tests cover string PEM, Buffer-shape JSON, bare numeric array, empty/unknown fallbacks).cargo fmt --all -- --checkclean.test-https-agent-abort-controller.js: was diff, now pass (both runtimes silent, exit 0).test-https-agent-keylog.js: PEM step now succeeds; next blocker is rustlsUnsupportedCertVersionon the Node test fixture (unrelated, distinct follow-up).test-https-byteswritten.js: PEM step now succeeds; remaining diff is a missingconsole.log('ok')reachable code path (unrelated, distinct follow-up).Scope
This is the first cluster from #2132 — it closes the PEM-Buffer source of diffs. Remaining buckets surfaced by the radar (server method dispatch, agent
getName/addRequest, theUnsupportedCertVersioncluster) will be follow-up PRs.Test plan
cargo test --release -p perry-ext-http-server --libcargo fmt --all -- --check