Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

working with certificates for server connection

Tags:

c#

uwp

im trying to transfer code from console app to uwp, in this console app used ServicePointManager that use all certificates, in uwp app i don`t use them and have exception with text - "A connection with the server could not be established".

The question is - how can i replace ServicePointManager and apply all certifates in uwp(because i don`t know what type of certificate used for this server).

Code of ServicePointManager is listed 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 reply!

like image 914
Valery Tkachov Avatar asked Aug 15 '16 18:08

Valery Tkachov


People also ask

How do certificates work on servers?

The web server sends the browser/server a copy of its SSL certificate. The browser/server checks to see whether or not it trusts the SSL certificate. If so, it sends a message to the web server. The web server sends back a digitally signed acknowledgement to start an SSL encrypted session.

What is the purpose of a certificate on a server?

A web server certificate is basically an SSL certificate issued to a web server to authenticate its identity to the client. The web server certificate also establishes a secure communication channel with the client for more robust protection.

How do server client certificates work?

Client certificates tend to be used within private organizations to authenticate requests to remote servers. Whereas server certificates are more commonly known as TLS/SSL certificates and are used to protect servers and web domains.


1 Answers

I think you are trying to use HttpClient, and if this is from the Windows.Web.Http namespace, you can add a filter to it, where some kind of certificate errors can be bypassed. Eg.:

using Windows.Web.Http;
using Windows.Web.Http.Filters;

var filter = new HttpBaseProtocolFilter();
filter.IgnorableServerCertificateErrors.Add(ChainValidationResult.Untrusted);
var httpClient = new HttpClient(filter);
like image 88
Tóth Tibor Avatar answered Sep 23 '22 23:09

Tóth Tibor