Work with certificates to connect to the server

im trying to transfer the code from the console application to uwp, in this console application the ServicePointManager is used, which uses all the certificates, in the uwp application I donโ€™t use them and I have no exception with the text - โ€œUnable to establish connection with the serverโ€.

Question: how can I replace ServicePointManager and apply all certificates in uwp (because I do not know what type of certificate is used for this server).

ServicePointManager code is below:

ServicePointManager.ServerCertificateValidationCallback += new System.Net.Security.RemoteCertificateValidationCallback (bypassAllCertificateStuff); private static bool bypassAllCertificateStuff(object sender, X509Certificate cert, X509Chain chain, System.Net.Security.SslPolicyErrors error) { return true; } 

Thanks for the answer!

+6
source share
2 answers

I think you are trying to use HttpClient , and if it is from the Windows.Web.Http namespace, you can add a filter to it where you can avoid any certificate errors. For instance:.

 using Windows.Web.Http; using Windows.Web.Http.Filters; var filter = new HttpBaseProtocolFilter(); filter.IgnorableServerCertificateErrors.Add(ChainValidationResult.Untrusted); var httpClient = new HttpClient(filter); 
+1
source

The code you sent for ServicePointManager instructed the client to ignore server certificate verification errors. Thus, if your server certificate expires, or if it was sent to another host, or if it was signed by a certification authority that is not known to your client machine, your call code does not care and continues to communicate with this server. Depending on your requirements, this may or may not be a reasonable decision to disable this check. However, if you want to disable validation and you use System.Net.Http.HttpClient , you can check this answer in StackOverflow.

Also, keep in mind that you can use two HTTP clients in a UWP application. For a comparison between the two, see this link .

0
source

All Articles