You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Maui -Android certificate pinning using network-security-config ignore incorrect pin #107695
Added SocketsHttpHandler with SslClientAuthenticationOptions.RemoteCertificateValidationCallback
I expect, that if I change base64 pin to incorrect, RemoteCertificateValidationCallback will be called with RemoteCertificateNameMismatch, as for IOS, but receive SslPolicyErrors.None
Hi I'm an AI powered bot that finds similar issues based off the issue title.
Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!
@QianaJiao try to prepare demo soon. Just one note:
Trying 2 httpclient options
HttpClientHandler with ServerCertificateCustomValidationCallback, any sha256 pin(even correct) throw RemoteCertificateChainErrors, for all chains(try first certificate, intermediate and CA)
SocketsHttpHandler with SslClientAuthenticationOptions.RemoteCertificateValidationCallback always returns SslPolicyErrors.None, even if pin incorrect
At the same time, ios works correctly for both cases
Could you verify, maybe I do smth wrong?
I can repro this issue on both Android and iOS. No matter which pin I comment, it will return SslPolicyErrors.None.
I'm not confident about my verification results. Could anyone help to take a look?
@QianaJiao Sorry, on ios I haven't added ssl pinning, just on android(As ios works correct for me, haven't touched in demo). On android have you checked both button clicks?
Socket Handler always works successfully, Http Handler always returns error
There is a bit of confusion on this thread, so I'm not sure I follow what the problem is. Is there a sample that displays a problem?
One note:
Using AndroidMessageHandler (default), probably no RemoteCertificateValidationCallback would ever be called. It would be using the native Android http stack in that case.
Using SocketsHttpHandler (you'd have to set UseNativeHttpHandler=false in your .csproj), RemoteCertificateValidationCallback should get called
@simonrozsival might be able to help, if we think there is a runtime issue here.
There is a bit of confusion on this thread, so I'm not sure I follow what the problem is. Is there a sample that displays a problem?
One note:
Using AndroidMessageHandler (default), probably no RemoteCertificateValidationCallback would ever be called. It would be using the native Android http stack in that case.
Using SocketsHttpHandler (you'd have to set UseNativeHttpHandler=false in your .csproj), RemoteCertificateValidationCallback should get called
@simonrozsival might be able to help, if we think there is a runtime issue here.
In demo I used HttpClient Implementation: Managed(HttpClientHandler)
Both SslClientAuthenticationOptions.RemoteCertificateValidationCallback and HttpClientHandler.ServerCertificateCustomValidationCallback called, if make a request via them
@DmitryNikiforovCoherent thanks for reporting this issue. I looked into it today and I think I have a rough idea where the problems in both the HttpClientHandler(internally implemented via AndroidMessageHandler) and SocketsHttpHandler originate.
Currently the only workaround is to manually check the certificate hash in the ServerCertificateValidationCallback/RemoteCertificateValidationCallback instead of using network_security_config.xml. I would point out that Google doesn't recommend using certificate pinning in Android apps (see https://developer.android.com/privacy-and-security/security-ssl#Pinning).
@simonrozsival We have switched from HttpClientHandler to SocketsHttpHandler in our App. After this change, we noticed that our network_security_config.xml does not seem to be respected anymore. From my (limited) understanding, the linked pull request would fix this. Is this correct?
Activity
github-actions commentedon Sep 6, 2024
Hi I'm an AI powered bot that finds similar issues based off the issue title.
Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!
Open similar issues:
Closed similar issues:
QianaJiao commentedon Sep 9, 2024
@DmitryNikiforovCoherent Could you share us a repo, I'd like to verify it.
RobTF commentedon Sep 9, 2024
We have the thumbprint in app config and use
ServerCertificateCustomValidationCallbackand that seems to work on all platforms.Is there a reason certificate pinning has been special cased into a separate config file etc.?
DmitryNikiforovCoherent commentedon Sep 9, 2024
@QianaJiao try to prepare demo soon. Just one note:
Trying 2 httpclient options
At the same time, ios works correctly for both cases
Could you verify, maybe I do smth wrong?
Base 64 pin I receive from ssllabs for my host

QianaJiao commentedon Sep 10, 2024
Thank you for your reply. I will continue to investigate after I get your demo.
In addition, have you noticed these 2 points?
Here are some documents that may also be useful to you
https://learn.microsoft.com/en-us/dotnet/maui/data-cloud/local-web-services?view=net-maui-8.0#enable-clear-text-network-traffic-for-the-localhost-domain
https://developer.android.google.cn/privacy-and-security/security-config
DmitryNikiforovCoherent commentedon Sep 10, 2024
@QianaJiao
Yes, Build action is AndroidResource, network_security_config is mentioned in AndroidManifest.
Could you check this? HttpClientService contains both cases, with HttpClientHandler and SocketsHttpHandler
network_security_config.xml contains correct and incorrect pin, please comment what you need
I use api from https://api-ninjas.com/api/exercises, receive pins from https://www.ssllabs.com/ssltest/analyze.html?d=api.api%2dninjas.com&s=3.168.86.93&latest
Archive.zip
QianaJiao commentedon Sep 11, 2024
I can repro this issue on both Android and iOS. No matter which
pinI comment, it will return SslPolicyErrors.None.I'm not confident about my verification results. Could anyone help to take a look?
DmitryNikiforovCoherent commentedon Sep 11, 2024
@QianaJiao Sorry, on ios I haven't added ssl pinning, just on android(As ios works correct for me, haven't touched in demo). On android have you checked both button clicks?

Socket Handler always works successfully, Http Handler always returns error
jfversluis commentedon Sep 11, 2024
@jonathanpeppers is this Android or even runtime?
jonathanpeppers commentedon Sep 11, 2024
There is a bit of confusion on this thread, so I'm not sure I follow what the problem is. Is there a sample that displays a problem?
One note:
AndroidMessageHandler(default), probably noRemoteCertificateValidationCallbackwould ever be called. It would be using the native Android http stack in that case.SocketsHttpHandler(you'd have to setUseNativeHttpHandler=falsein your.csproj),RemoteCertificateValidationCallbackshould get called@simonrozsival might be able to help, if we think there is a runtime issue here.
dotnet-policy-service commentedon Sep 11, 2024
Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.
4 remaining items
dotnet-policy-service commentedon Sep 11, 2024
Tagging subscribers to 'arch-android': @vitek-karas, @simonrozsival, @steveisok, @akoeplinger
See info in area-owners.md if you want to be subscribed.
dotnet-policy-service commentedon Sep 11, 2024
Tagging subscribers to this area: @dotnet/ncl, @bartonjs, @vcsjones
See info in area-owners.md if you want to be subscribed.
DmitryNikiforovCoherent commentedon Sep 12, 2024
In demo I used HttpClient Implementation: Managed(HttpClientHandler)

Both SslClientAuthenticationOptions.RemoteCertificateValidationCallback and HttpClientHandler.ServerCertificateCustomValidationCallback called, if make a request via them
Demo attached in this comment
#107695 (comment)
simonrozsival commentedon Sep 12, 2024
@DmitryNikiforovCoherent thanks for reporting this issue. I looked into it today and I think I have a rough idea where the problems in both the
HttpClientHandler(internally implemented viaAndroidMessageHandler) andSocketsHttpHandleroriginate.Currently the only workaround is to manually check the certificate hash in the
ServerCertificateValidationCallback/RemoteCertificateValidationCallbackinstead of usingnetwork_security_config.xml. I would point out that Google doesn't recommend using certificate pinning in Android apps (see https://developer.android.com/privacy-and-security/security-ssl#Pinning).[Mono.Android] use `X509TrustManagerExtensions` for `network_security…
[Android] Respect platform trust manager in SslStream
[Android] Respect platform trust manager in SslStream
[Android] Respect platform trust manager in SslStream
SidlerD123 commentedon Jul 3, 2026
@simonrozsival We have switched from HttpClientHandler to SocketsHttpHandler in our App. After this change, we noticed that our network_security_config.xml does not seem to be respected anymore. From my (limited) understanding, the linked pull request would fix this. Is this correct?
[Android] Respect platform trust manager in SslStream (dotnet#124173)
simonrozsival commentedon Jul 11, 2026
@SidlerD123 yes, this PR has been merged and it will be part of the .NET 11 release.
[Android] Respect platform trust manager in SslStream (#124173)