-
Notifications
You must be signed in to change notification settings - Fork 5.3k
[Android] Fix Android SSL exception propagation in certificate validation #118482
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes Android-specific SSL exception handling to ensure certificate validation exceptions are properly propagated and cause immediate handshake failure. The issue was that certificate validation failures were not being converted to AuthenticationException and SSL handshakes continued even when validation failed, leading to timeouts instead of proper error reporting.
Key changes:
- Add explicit
AuthenticationExceptioncreation when certificate validation fails - Implement early termination of SSL handshake when validation exceptions are detected
- Ensure proper exception propagation through
SecurityStatusPalto prevent timeouts
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| SslStreamPal.Android.cs | Adds validation exception checking before and after handshake attempts with proper status code handling |
| SslStream.Android.cs | Creates AuthenticationException when certificate validation fails and adds using directive for Authentication namespace |
|
|
||
| SafeSslHandle sslHandle = sslContext!.SslContext; | ||
|
|
||
| Exception? validationException = sslContext?.SslStreamProxy.ValidationException; |
Copilot
AI
Aug 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The validation exception is retrieved twice in the same method (lines 207 and 226). Consider storing the result in a variable that's updated only when needed to avoid redundant property access.
src/libraries/System.Net.Security/src/System/Net/Security/SslStream.Android.cs
Outdated
Show resolved
Hide resolved
|
Tagging subscribers to this area: @dotnet/ncl, @bartonjs, @vcsjones |
Co-authored-by: Copilot <[email protected]>
|
/azp run runtime-extra-platforms |
|
Azure Pipelines successfully started running 1 pipeline(s). |
src/libraries/System.Net.Security/src/System/Net/Security/SslStream.Android.cs
Show resolved
Hide resolved
|
This fixes the CI but is not the proper fix. Validation can return false even when there is no custom validation through ServerCertificateCustomValidationCallback. |
Summary
This fixes Android-specific SSL exception handling to explicitly propagate
AuthenticationExceptionwhen certificate validation fails. Additionally, in SSL handshake even when validation exceptions were detected, the SSL handshake continued instead of failing immediately.Changes