System.Net.WebException: Error: TrustFailure (Authentication failed, see inner exception.)

Viewed 8694

While making a request to HTTPS server, I am getting following error. Request works with HTTP.

{System.Net.WebException: Error: TrustFailure (Authentication failed, see inner exception.) ---> System.Security.Authentication.AuthenticationException: Authentication failed, see inner exception. ---> Mono.Btls.MonoBtlsException: Ssl error:1000007d:SSL routines:OPENSSL_internal:CERTIFICATE_VERIFY_FAILED

I have set HTTPClientHandler to Android and TLS/SSL Implementation to Native TLD 1.2+ in Android settings.

2 Answers

This is how I did it using WebClient and than just need add ServerCertificateValidationCallback

var uri = new UriBuilder("https://url/v3/0").Uri;
var client = new WebClient();
ServicePointManager.ServerCertificateValidationCallback = new
    RemoteCertificateValidationCallback
    (
       delegate { return true; }
    );    
var content = client.DownloadString(uri);

I solved this by adding ServerCertificateCustomValidationCallback property to HttpWebRequest object like this.

HttpWebRequest request = new HttpWebRequest(new Uri());
request.ServerCertificateCustomValidationCallback = delegate {return true;}
Related