crypto: add crypto.parsePKCS12() - #65627
Merged
Merged
Conversation
Collaborator
|
Review requested:
|
panva
self-requested a review
August 28, 2026 20:57
panva
reviewed
Aug 28, 2026
panva
left a comment
Member
There was a problem hiding this comment.
The direction looks alright. I noted a few issues to work through.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #65627 +/- ##
==========================================
- Coverage 90.18% 90.16% -0.03%
==========================================
Files 771 772 +1
Lines 265487 265635 +148
Branches 50461 50497 +36
==========================================
+ Hits 239437 239517 +80
- Misses 17006 17063 +57
- Partials 9044 9055 +11
🚀 New features to boost your workflow:
|
bmuenzenmeyer
force-pushed
the
pkcs12
branch
from
September 4, 2026 10:43
2d6065c to
1bc0b49
Compare
This comment was marked as outdated.
This comment was marked as outdated.
bmuenzenmeyer
marked this pull request as draft
September 4, 2026 10:48
bmuenzenmeyer
force-pushed
the
pkcs12
branch
3 times, most recently
from
September 4, 2026 13:01
dc7a151 to
dbcba0a
Compare
bmuenzenmeyer
marked this pull request as ready for review
September 4, 2026 13:11
bmuenzenmeyer
force-pushed
the
pkcs12
branch
2 times, most recently
from
September 4, 2026 15:23
3a8e383 to
06b6a3b
Compare
jasnell
reviewed
Sep 4, 2026
bmuenzenmeyer
force-pushed
the
pkcs12
branch
from
September 4, 2026 19:42
06b6a3b to
73cd4f1
Compare
bmuenzenmeyer
force-pushed
the
pkcs12
branch
from
September 5, 2026 13:34
73cd4f1 to
391db51
Compare
panva
reviewed
Sep 11, 2026
panva
reviewed
Sep 11, 2026
panva
reviewed
Sep 11, 2026
panva
reviewed
Sep 11, 2026
bmuenzenmeyer
force-pushed
the
pkcs12
branch
from
September 11, 2026 13:31
79460ba to
92fa2ac
Compare
Return the private key, end-entity certificate, and any other non-matching certificates from a PKCS#12 (.p12/.pfx) bundle as a KeyObject and X509Certificate instances. Node.js already parses PKCS#12 in SecureContext::LoadPKCS12, which backs tls's `pfx` option, but the results are consumed directly into an SSL_CTX and never reach JavaScript. Callers who need the key or the certificates for anything other than an immediate TLS connection have to shell out to `openssl pkcs12` or take a userland dependency. SecureContext::LoadPKCS12 now uses this same parsing logic. The binding wraps d2i_PKCS12_bio() and PKCS12_parse() and follows their semantics, matching the existing TLS path: the first private key is returned, the end-entity certificate is the one associated with that key, and any remaining certificates are returned through `additionalCertificates`. A bundle containing no private key reports `certificate` as null and returns its certificates through `additionalCertificates`. Absent and empty passphrases are kept distinct, since OpenSSL treats them differently. Bundles that require OpenSSL's legacy provider throw ERR_CRYPTO_UNSUPPORTED_OPERATION, reusing the error added for the TLS path. Signed-off-by: bmuenzenmeyer <brian.muenzenmeyer@gmail.com> Co-authored-by: Filip Skokan <panva.ip@gmail.com>
bmuenzenmeyer
force-pushed
the
pkcs12
branch
from
September 11, 2026 15:35
92fa2ac to
c4391ee
Compare
This comment has been minimized.
This comment has been minimized.
Collaborator
Collaborator
|
Landed in 6fc8826 |
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.
Return the private key, end-entity certificate, and other certificates from a PKCS#12 (.p12/.pfx) bundle as a KeyObject and X509Certificate instances.
Reading a
.p12/.pfxbundle from JavaScript today means shelling out to theopenssl pkcs12CLI or taking a userland dependency such as node-forge. In talking to a colleague about this unfortunate missing method in core, I (with Claude) noticed Node.js already parses this internally.This PR exposes those internals to end users. Our use case is loading identity files supplied by our environment, to be forwarded during MCP tool calls. This allows us to use real identity instead of service account.
Note
This is my first significant contribution to core that touches the internals. I am still getting my bearings with regard to the module mechanics, bindings, and c++. I'm committed to shaping this, but learning.
SecureContext::LoadPKCS12has backed tls'spfxoption for years, but its results are loaded straight into anSSL_CTXand never reach JavaScript.Returns
{ privateKey: KeyObject|null, certificate: X509Certificate|null, additionalCertificates: X509Certificate[] }.Assisted-by: Claude Opus