Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accepting invalid SSL certificates using WinRT

There are scenarios where you want your application to accept invalid SSL certificates (testing environment/ self signed certificates etc).

In the .NET world one would use the ServerCertificateValidationCallback class to do so. Unfortunately the class doesn't exist in a WinRT context.

I need to consume a Web API using WinRT which is hosted on a server without a valid ssl certificate.

How do you accept invalid ssl certificates in WinRT using the HttpClient class or any other appropriate class.

Any help or alternatives would much appreciated.

like image 378
Flo Avatar asked Aug 14 '12 15:08

Flo


1 Answers

The following code worked for me for the debugging scenario:

var filter = new HttpBaseProtocolFilter();
#if DEBUG
    filter.IgnorableServerCertificateErrors.Add(ChainValidationResult.Expired);
    filter.IgnorableServerCertificateErrors.Add(ChainValidationResult.Untrusted);
    filter.IgnorableServerCertificateErrors.Add(ChainValidationResult.InvalidName);
#endif
using (var httpClient = new HttpClient(filter)) {
    ...
}
like image 147
dschüsä Avatar answered Sep 23 '22 17:09

dschüsä