Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

https using BasicHttpBinding and ignoring certificate errors

I am using BasicHttpBinding to connect a web service hosted on a secured (https) port. To get it working, I have changed the Security.Mode to TransportWithMessageCredential and Security.Message to BasicHttpMessageCredentialType.Cerificate. I am also calling

client.ClientCredentials.ClientCertificate.SetCertificate()

with localhost as the subject name.

The issue here is that for unit testing, I have an unsigned certificate from the web server and am supposed to ignore any certificate error thrown during the proxy creation; but I am unable to do so, because I keep getting an error telling me to "specify a certificate". Right now, I am clueless; I appreciate any help here.

like image 212
Venkatesh Laguduva Avatar asked Apr 21 '12 05:04

Venkatesh Laguduva


People also ask

How do I ignore an invalid certificate?

You need to pass the -k or --insecure option to the curl command. This option explicitly allows curl to perform “insecure” SSL connections and transfers. All SSL connections are attempted to be made secure by using the CA certificate bundle installed by default.


2 Answers

You can use the following code to skip certificate validation. This creates a RemoteCertificateValidationCallback that always return true for any certificate.

System.Net.ServicePointManager.ServerCertificateValidationCallback = 
    (sender, certificate, chain, errors) => true;
like image 135
David Z. Avatar answered Oct 16 '22 20:10

David Z.


For server ssl, the SecurityMode should be set to Transport.

like image 6
Tung Avatar answered Oct 16 '22 21:10

Tung