Skip to content

[release/9.0.1xx] [Foundation] Treat any exception during X509Chain.Build as a remote certificate chain error. Fixes #24739.#24758

Merged
rolfbjarne merged 1 commit intorelease/9.0.1xxfrom
dev/rolf/backport-pr-24754-release/9.0.1xx-2026-02-20
Feb 24, 2026
Merged

[release/9.0.1xx] [Foundation] Treat any exception during X509Chain.Build as a remote certificate chain error. Fixes #24739.#24758
rolfbjarne merged 1 commit intorelease/9.0.1xxfrom
dev/rolf/backport-pr-24754-release/9.0.1xx-2026-02-20

Conversation

@rolfbjarne
Copy link
Member

In iOS 26.4 beta 4, X509Chain.Build started throwing CryptographicException:

System.Security.Cryptography.Interop+AppleCrypto+AppleCommonCryptoCryptographicException: Unable to decode the provided data.
    at System.Security.Cryptography.X509Certificates.SecTrustChainPal.Execute(:0)
    at System.Security.Cryptography.X509Certificates.ChainPal.BuildChain(:0)
    at System.Security.Cryptography.X509Certificates.X509Chain.Build(:0)
    at Foundation.NSUrlSessionHandler+ServerCertificateCustomValidationCallbackHelper.EvaluateSslPolicyErrors(:0)
    at Foundation.NSUrlSessionHandler+ServerCertificateCustomValidationCallbackHelper.Invoke(:0)
    at Foundation.NSUrlSessionHandler.TryInvokeServerCertificateCustomValidationCallback(:0)
    at Foundation.NSUrlSessionHandler+NSUrlSessionHandlerDelegate.DidReceiveChallengeImpl(:0)
    at Foundation.NSUrlSessionHandler+NSUrlSessionHandlerDelegate.DidReceiveChallenge(:0)
    at InvokeStub_NSUrlSessionHandlerDelegate.DidReceiveChallenge(:0)

The underlying cause of these exceptions is handled in this issue:
dotnet/runtime#124552, this change is only
dealing with the fact that the process crashes when an unexpected
exception occurs in this code path in NSUrlSessionHandler.

The fix is to handle all exceptions in the call X509Chain.Build, and
report them as a certificate chain error in the custom server validation
callback; then the app developer can handle them as they see fit.

Fixes #24739.

See also:

Backport of #24754.

…ertificate chain error. Fixes #24739.

In iOS 26.4 beta 4, X509Chain.Build started throwing CryptographicException:

```
System.Security.Cryptography.Interop+AppleCrypto+AppleCommonCryptoCryptographicException: Unable to decode the provided data.
    at System.Security.Cryptography.X509Certificates.SecTrustChainPal.Execute(:0)
    at System.Security.Cryptography.X509Certificates.ChainPal.BuildChain(:0)
    at System.Security.Cryptography.X509Certificates.X509Chain.Build(:0)
    at Foundation.NSUrlSessionHandler+ServerCertificateCustomValidationCallbackHelper.EvaluateSslPolicyErrors(:0)
    at Foundation.NSUrlSessionHandler+ServerCertificateCustomValidationCallbackHelper.Invoke(:0)
    at Foundation.NSUrlSessionHandler.TryInvokeServerCertificateCustomValidationCallback(:0)
    at Foundation.NSUrlSessionHandler+NSUrlSessionHandlerDelegate.DidReceiveChallengeImpl(:0)
    at Foundation.NSUrlSessionHandler+NSUrlSessionHandlerDelegate.DidReceiveChallenge(:0)
    at InvokeStub_NSUrlSessionHandlerDelegate.DidReceiveChallenge(:0)
```

The underlying cause of these exceptions is handled in this issue:
dotnet/runtime#124552, this change is only dealing
with the fact that the process crashes when an unexpected exception occurs in
this code path in NSUrlSessionHandler.

The fix is to handle all exceptions in the call X509Chain.Build, and report
them as a certificate chain error in the custom server validation callback;
then the app developer can handle them as they see fit.

Fixes #24739.

See also:

* dotnet/runtime#124552
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Backport to the release/9.0.1xx branch to prevent process crashes when X509Chain.Build throws unexpectedly during TLS server certificate evaluation in NSUrlSessionHandler, so the app’s custom validation callback can still run and decide how to handle the failure.

Changes:

  • Broaden exception handling around X509Chain.Build to treat any thrown exception as SslPolicyErrors.RemoteCertificateChainErrors.

@rolfbjarne rolfbjarne enabled auto-merge (squash) February 20, 2026 19:44
@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [CI Build #e40523e] Build passed (Build packages) ✅

Pipeline on Agent
Hash: e40523ec669d67f57d10e5290d24a4eae62185b4 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [PR Build #e40523e] Build passed (Detect API changes) ✅

Pipeline on Agent
Hash: e40523ec669d67f57d10e5290d24a4eae62185b4 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [CI Build #e40523e] Build passed (Build macOS tests) ✅

Pipeline on Agent
Hash: e40523ec669d67f57d10e5290d24a4eae62185b4 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ API diff for current PR / commit

NET (empty diffs)

✅ API diff vs stable

NET (empty diffs)

ℹ️ Generator diff

Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)

Pipeline on Agent
Hash: e40523ec669d67f57d10e5290d24a4eae62185b4 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build #e40523e] Tests on macOS X64 - Mac Sonoma (14) passed 💻

All tests on macOS X64 - Mac Sonoma (14) passed.

Pipeline on Agent
Hash: e40523ec669d67f57d10e5290d24a4eae62185b4 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build #e40523e] Tests on macOS M1 - Mac Monterey (12) passed 💻

All tests on macOS M1 - Mac Monterey (12) passed.

Pipeline on Agent
Hash: e40523ec669d67f57d10e5290d24a4eae62185b4 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build #e40523e] Tests on macOS arm64 - Mac Sequoia (15) passed 💻

All tests on macOS arm64 - Mac Sequoia (15) passed.

Pipeline on Agent
Hash: e40523ec669d67f57d10e5290d24a4eae62185b4 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build #e40523e] Tests on macOS M1 - Mac Ventura (13) passed 💻

All tests on macOS M1 - Mac Ventura (13) passed.

Pipeline on Agent
Hash: e40523ec669d67f57d10e5290d24a4eae62185b4 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build #e40523e] Tests on macOS arm64 - Mac Tahoe (26) passed 💻

All tests on macOS arm64 - Mac Tahoe (26) passed.

Pipeline on Agent
Hash: e40523ec669d67f57d10e5290d24a4eae62185b4 [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Collaborator

🚀 [CI Build #e40523e] Test results 🚀

Test results

✅ All tests passed on VSTS: test results.

🎉 All 115 tests passed 🎉

Tests counts

✅ cecil: All 1 tests passed. [attempt 2] Html Report (VSDrops) Download
✅ dotnettests (iOS): All 1 tests passed. [attempt 3] Html Report (VSDrops) Download
✅ dotnettests (MacCatalyst): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (macOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (Multiple platforms): All 1 tests passed. [attempt 2] Html Report (VSDrops) Download
✅ dotnettests (tvOS): All 1 tests passed. Html Report (VSDrops) Download
✅ framework: All 2 tests passed. [attempt 2] Html Report (VSDrops) Download
✅ fsharp: All 4 tests passed. [attempt 2] Html Report (VSDrops) Download
✅ generator: All 5 tests passed. Html Report (VSDrops) Download
✅ interdependent-binding-projects: All 4 tests passed. Html Report (VSDrops) Download
✅ introspection: All 4 tests passed. [attempt 2] Html Report (VSDrops) Download
✅ linker: All 44 tests passed. [attempt 2] Html Report (VSDrops) Download
✅ monotouch (iOS): All 8 tests passed. [attempt 2] Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 11 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 9 tests passed. [attempt 3] Html Report (VSDrops) Download
✅ monotouch (tvOS): All 8 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. [attempt 2] Html Report (VSDrops) Download
✅ windows: All 3 tests passed. Html Report (VSDrops) Download
✅ xcframework: All 4 tests passed. [attempt 2] Html Report (VSDrops) Download
✅ xtro: All 1 tests passed. Html Report (VSDrops) Download

Pipeline on Agent
Hash: e40523ec669d67f57d10e5290d24a4eae62185b4 [PR build]

@rolfbjarne rolfbjarne merged commit 65f27f5 into release/9.0.1xx Feb 24, 2026
50 checks passed
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.

4 participants