[Foundation] Treat any exception during X509Chain.Build as a remote certificate chain error. Fixes #24739.#24754
Conversation
…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
There was a problem hiding this comment.
Pull request overview
This PR fixes a crash in iOS 26.4 beta 4 where X509Chain.Build throws CryptographicException during certificate validation. The fix ensures that any exception during certificate chain building is caught and reported as a certificate chain error to the ServerCertificateCustomValidationCallback, allowing application developers to handle certificate validation errors gracefully instead of the application crashing.
Changes:
- Broadened exception handling in
NSUrlSessionHandler.EvaluateSslPolicyErrorsfrom catching onlyArgumentExceptionto catching all exceptions when callingX509Chain.Build.
✅ [CI Build #060c25a] Build passed (Build packages) ✅Pipeline on Agent |
|
CC @filipnavara |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
✅ [CI Build #060c25a] Build passed (Build macOS tests) ✅Pipeline on Agent |
This comment has been minimized.
This comment has been minimized.
✅ [PR Build #060c25a] Build passed (Detect API changes) ✅Pipeline on Agent |
|
🔥 Unable to find the contents for the comment: D:\a\1\s\change-detection\results\gh-comment.md does not exist :fire Pipeline on Agent |
🚀 [CI Build #060c25a] Test results 🚀Test results✅ All tests passed on VSTS: test results. 🎉 All 156 tests passed 🎉 Tests counts✅ cecil: All 1 tests passed. Html Report (VSDrops) Download macOS tests✅ Tests on macOS Monterey (12): All 5 tests passed. Html Report (VSDrops) Download Pipeline on Agent |
|
api-diff failing is unrelated (#24756). |
…Build as a remote certificate chain error. Fixes #24739. (#24757) 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 Backport of #24754.
…uild as a remote certificate chain error. Fixes #24739. (#24758) 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 Backport of #24754.
In iOS 26.4 beta 4, X509Chain.Build started throwing CryptographicException:
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: