Skip to content

feat(macos): add mTLS client certificate and CA pinning support#1707

Open
ShaunMurphy wants to merge 1 commit into
tauri-apps:devfrom
ShaunMurphy:feat/mtls-client-certificate
Open

feat(macos): add mTLS client certificate and CA pinning support#1707
ShaunMurphy wants to merge 1 commit into
tauri-apps:devfrom
ShaunMurphy:feat/mtls-client-certificate

Conversation

@ShaunMurphy
Copy link
Copy Markdown

Summary

  • Add with_client_certificate(p12_data, password) builder method for mTLS client authentication
  • Add with_trusted_ca(der_data) builder method for custom CA server trust pinning
  • Implement didReceiveAuthenticationChallenge in WryNavigationDelegate on macOS

Motivation

WKWebView on macOS does not auto-present client certificates during TLS handshakes. Unlike Safari or Windows WebView2, a WKNavigationDelegate must explicitly handle didReceiveAuthenticationChallenge and provide an NSURLCredential with a SecIdentityRef.

There is currently no wry API to provide client certificates or pin custom CA certificates, making mTLS connections impossible without bypassing wry.

Implementation

Client certificate: SecPKCS12Import extracts the SecIdentityRef from the PKCS#12 data in memory. No keychain access or user prompts needed.

CA pinning: SecTrustSetAnchorCertificates pins the custom CA during server trust evaluation. No system trust store import or Touch ID prompts needed.

Both operations are in-memory only, producing zero user-facing prompts.

Files changed:

  • src/lib.rs: New WebViewAttributes fields and WebViewBuilder methods
  • src/wkwebview/class/wry_navigation_delegate.rs: New ivars and didReceiveAuthenticationChallenge delegate method
  • src/wkwebview/navigation_auth.rs: Authentication challenge handler implementation
  • src/wkwebview/mod.rs: Module declaration, pass cert data to delegate
  • Cargo.toml: Enable NSURLAuthenticationChallenge, NSURLCredential, NSURLProtectionSpace features

Platform support

  • macOS/iOS: Fully implemented
  • Windows/Linux/Android: Data stored for future use, not yet functional

Test plan

  • cargo check passes with zero warnings
  • cargo test passes (7 passed, 0 failed)
  • winit example runs without crash on macOS 26.3.1
  • multiwebview example runs without crash
  • Manual mTLS test with self-signed CA and client cert

@ShaunMurphy ShaunMurphy requested a review from a team as a code owner March 28, 2026 21:55
Add two new WebViewBuilder methods for mutual TLS authentication:

- `with_client_certificate(p12_data, password)`: provide a PKCS#12
  client certificate for TLS client authentication. Uses SecPKCS12Import
  to extract the identity in memory without keychain access.

- `with_trusted_ca(der_data)`: pin a custom CA certificate for server
  trust evaluation. Uses SecTrustSetAnchorCertificates to trust the CA
  without importing it into the system trust store.

Both methods avoid keychain operations and user prompts (Touch ID,
password dialogs). The certificate data is stored in memory and used
directly during WKNavigationDelegate authentication challenges.

Security:
- CF objects from SecCertificateCreateWithData and SecPKCS12Import are
  properly released via CFRelease
- Server trust fallback uses PerformDefaultHandling (not UseCredential)
  to preserve default WKWebView security behavior
- Failed CA pinning evaluation cancels the challenge rather than
  falling through to accept untrusted servers

Currently implemented for macOS/iOS. Windows/Linux/Android store the
data for future use.

Closes tauri-apps#1706
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants