Skip to content

feat: emit select-client-certificate for net module requests - #52162

Merged
jkleinsc merged 13 commits into
electron:mainfrom
dannycochran:wip/net-select-client-certificate-full
Jul 20, 2026
Merged

jkleinsc merged 13 commits into
electron:mainfrom
dannycochran:wip/net-select-client-certificate-full

Conversation

@dannycochran

@dannycochran dannycochran commented Jun 27, 2026 •

Copy link
Copy Markdown
Contributor

Description of Change

Companion to #52160 (the minimal decline-only fix). This is the full implementation that also wires the select-client-certificate event for net.request / net.fetch / utility-process requests, so applications can choose a client certificate rather than always declining.

SimpleURLLoaderWrapper::OnCertificateRequested and URLLoaderNetworkObserver::OnCertificateRequested are implemented to fetch client identities via ElectronBrowserClient::CreateClientCertStore() and route through the existing App::SelectClientCertificate path with webContents as null (matching the existing app 'login' event behavior for net module requests). When no matching identities exist, the request proceeds without a certificate. A shared ClientCertificateResponderDelegate adapter bridges network::mojom::ClientCertificateResponder ↔ content::ClientCertificateDelegate, and an SSLPrivateKeyImpl (mirroring content::SSLPrivateKeyImpl) handles the key wrapping.

Refs #29984.

Posting both this and #52160 as drafts so reviewers can compare the minimal fix vs. the full event wiring; happy to consolidate to whichever direction is preferred (or to a session.setClientCertificateSelectHandler() shape if that's a better fit — see #29984 discussion).

Checklist

Release Notes

Notes: Added select-client-certificate event support for net.request and net.fetch; requests to servers requesting a client certificate no longer fail with ERR_SSL_CLIENT_AUTH_CERT_NEEDED, and applications can now select a certificate to present.

@welcome

welcome Bot commented Jun 27, 2026

Copy link
Copy Markdown

💖 Thanks for opening this pull request! 💖

Semantic PR titles

We use semantic commit messages to streamline the release process. Before your pull request can be merged, you should update your pull request title to start with a semantic prefix.

Examples of commit messages with semantic prefixes:

  • fix: don't overwrite prevent_default if default wasn't prevented
  • feat: add app.isPackaged() method
  • docs: app.isDefaultProtocolClient is now available on Linux

Commit signing

This repo enforces commit signatures for all incoming PRs.
To sign your commits, see GitHub's documentation on Telling Git about your signing key.

PR tips

Things that will help get your PR across the finish line:

  • Follow the JavaScript, C++, and Python coding style.
  • Run npm run lint locally to catch formatting errors earlier.
  • Document any user-facing changes you've made following the documentation styleguide.
  • Include tests when adding/changing behavior.
  • Include screenshots and animated GIFs whenever possible.

We get a lot of pull requests on this repo, so please be patient and we will get back to you as soon as we can.

@electron-cation electron-cation Bot added the new-pr 🌱 PR opened recently label Jun 27, 2026
@MarshallOfSound
MarshallOfSound marked this pull request as ready for review June 29, 2026 19:38
@MarshallOfSound
MarshallOfSound requested a review from a team as a code owner June 29, 2026 19:38
@MarshallOfSound MarshallOfSound added target/42-x-y PR should also be added to the "42-x-y" branch. target/43-x-y PR should also be added to the "43-x-y" branch. labels Jun 29, 2026
@github-actions github-actions Bot added the target/44-x-y PR should also be added to the "44-x-y" branch. label Jul 1, 2026
@electron-cation electron-cation Bot removed the new-pr 🌱 PR opened recently label Jul 6, 2026
net.request and net.fetch requests to servers that send a TLS
CertificateRequest currently abort with ERR_SSL_CLIENT_AUTH_CERT_NEEDED
because SimpleURLLoaderWrapper::OnCertificateRequested and
URLLoaderNetworkObserver::OnCertificateRequested are empty stubs;
dropping the ClientCertificateResponder pipe causes the network service
to cancel the request. The select-client-certificate event only fired
for BrowserWindow page loads.

Implement OnCertificateRequested for both observers by fetching client
identities via ElectronBrowserClient::CreateClientCertStore() and
routing through the existing ElectronBrowserClient::SelectClientCertificate
path with web_contents = nullptr. When no matching identities exist the
request continues without a certificate, so optional client-certificate
endpoints work without any app-side handler.

Closes electron#29984.

Notes: Added `select-client-certificate` event support for `net.request` and `net.fetch`; requests to servers with optional client-certificate authentication no longer fail with ERR_SSL_CLIENT_AUTH_CERT_NEEDED.
ClientCertificateResponderDelegate calls these on ElectronBrowserClient
directly to route net-module client certificate requests through the
existing app 'select-client-certificate' event path.
OnClientCertificateSelected dereferenced an empty v8::Local when the
JS callback was invoked with no arguments: args->GetNext() returned
false and val stayed empty, then val->IsNull() crashed. The
documentation for select-client-certificate says callback() with no
certificate continues without one, so this must work.

Guard for no-argument / empty / null / undefined in one place. This is
pre-existing code shared with the BrowserWindow path, so this also
fixes the same crash for the existing app 'select-client-certificate'
event when callback() is called with no argument.
…ener

Shorten the helper-class comments in client_certificate_responder_delegate
and ensure the select-client-certificate handler in api-net-spec is removed
even when the event does not fire (the empty-identity short-circuit), so it
cannot leak onto the global app object across spec files.
Mirror content/browser/ssl_private_key_impl.cc and wrap the mojo
SignCallback with WrapCallbackWithDefaultInvokeIfNotRun so a platform
key store that abandons its sign callback (https://crbug.com/40651689)
fails the client-auth handshake with ERR_FAILED instead of leaving the
net.fetch / net.request / utility-process request hung.
Extend the select-client-certificate breaking-changes entry to call out
that net.request / net.fetch now default to the first matching platform
client certificate (previously ERR_SSL_CLIENT_AUTH_CERT_NEEDED), and how
to opt out.
…tity

When a 'select-client-certificate' listener invokes the callback
synchronously without calling event.preventDefault(), the matched
ClientCertIdentity is std::moved out of shared_identities inside
OnClientCertificateSelected. The fall-through default-selection block
then dereferences (*shared_identities)[0], which is now a moved-from
unique_ptr. Guard for it.
@dannycochran
dannycochran force-pushed the wip/net-select-client-certificate-full branch from b4d5314 to 480064a Compare July 16, 2026 18:10
@jkleinsc jkleinsc added the semver/major incompatible API changes label Jul 16, 2026

@MarshallOfSound MarshallOfSound left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API LGTM

@jkleinsc jkleinsc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API LGTM

@jkleinsc
jkleinsc merged commit e852c26 into electron:main Jul 20, 2026
77 checks passed
@welcome

welcome Bot commented Jul 20, 2026

Copy link
Copy Markdown

Congrats on merging your first pull request! 🎉🎉🎉

@release-clerk

release-clerk Bot commented Jul 20, 2026

Copy link
Copy Markdown

Release Notes Persisted

Added select-client-certificate event support for net.request and net.fetch; requests to servers requesting a client certificate no longer fail with ERR_SSL_CLIENT_AUTH_CERT_NEEDED, and applications can now select a certificate to present.

@trop

trop Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

I was unable to backport this PR to "42-x-y" cleanly;
you will need to perform this backport manually.

@trop trop Bot added needs-manual-bp/42-x-y and removed target/42-x-y PR should also be added to the "42-x-y" branch. labels Jul 20, 2026
@trop

trop Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

I have automatically backported this PR to "44-x-y", please check out #52397

@trop trop Bot added in-flight/44-x-y and removed target/44-x-y PR should also be added to the "44-x-y" branch. labels Jul 20, 2026
@trop

trop Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

I have automatically backported this PR to "43-x-y", please check out #52398

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

45-x-y api-review/approved ✅ merged/44-x-y PR was merged to the "44-x-y" branch. semver/major incompatible API changes

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

4 participants