I have a Xamarin.Forms app that implements certificate pinning utilizing the ServicePointManager.ServerCertificateValidationCallback class and method. On Android and iOS, this works without issue in that it will allow connections to expected services whose certificate keys have been pinned and disallow connections for those that I have not.
However, on UWP, all connections are allowed regardless whether the certificate key has been pinned or not. I have explicitly returned false from the certificate validation method and the connection is still allowed. I am sure the check is being performed as I have debugged and stepped through the certificate validation method.
What could be causing the connection to proceed even though I am returning false from the validation check?
ServicePointManager.ServerCertificateValidationCallback = ValidateServerCertficate;
private static bool ValidateServerCertficate(
object sender,
X509Certificate certificate,
X509Chain chain,
SslPolicyErrors sslPolicyErrors
)
{
return false;
}
I was able to fix this by:
This puts the following xml into Package.appxmanifest file:
<Extensions>
<Extension Category="windows.certificates">
<Certificates>
<TrustFlags ExclusiveTrust="true" />
</Certificates>
</Extension>
</Extensions>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With