views:

4501

answers:

5

We are setting up a new SharePoint for which we don't have a valid SSL certificate yet. I would like to call the Lists web service on it to retrieve some meta data about the setup. However, when I try to do this, I get the exception:

The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.

The nested exception contains the error message:

The remote certificate is invalid according to the validation procedure.

This is correct since we are using a temporary certificate.

My question is: how can I tell the .Net web service client (SoapHttpClientProtocol) to ignore these errors?

+4  A: 

The approach I used when faced with this problem was to add the signer of the temporary certificate to the trusted authorities list on the computer in question.

I normally do testing with certificates created with CACERT, and adding them to my trusted authorities list worked swimmingly.

Doing it this way means you don't have to add any custom code to your application and it properly simulates what will happen when your application is deployed. As such, I think this is a superior solution to turning off the check programmatically.

Simon Johnson
That was my first idea as well. Unfortunately the certificate is expired as well, so it is impossible to get it trusted.
jan.vdbergh
Is there any reason you can't use someone like CA cert? If it's a test cert then you could just go ahead with that.I'm not sure if there is a way to turn these checks off!
Simon Johnson
+10  A: 

Alternatively you can register a call back delegate which ignores the certification error:

...
ServicePointManager.ServerCertificateValidationCallback = MyCertHandler;
...

static bool MyCertHandler(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors error)
{
// Ignore errors
return true;
}
Thank you, this was exactly what I need right now. I was on the verge of writing my own question when I found your answer. I love SO!
Eyvind
+5  A: 

Like Jason S's answer:

ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };

I put this in my Main and look to my app.config and test if (ConfigurationManager.AppSettings["IgnoreSSLCertificates"] == "True") before calling that line of code.

Keith

Keith Sirmons
A: 

Interesting artcle on how to resolve the error: "The remote certificate is invalid according to the validation procedure" http://dzeee.net/sharepoint/post/2010/03/24/The-remote-certificate-is-invalid-according-to-the-validation-procedure.aspx

Dzeee
A: 

i solved it this way

call the following just before calling your ssl webservice that cause that error

  using System.Net;
  using System.Net.Security;
  using System.Security.Cryptography.X509Certificates;

        /// <summary>
        /// solution for exception
        /// System.Net.WebException: 
        /// The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel. ---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.
        /// </summary>
        public static void BypassCertificateError()
        {
            ServicePointManager.ServerCertificateValidationCallback +=

                delegate(
                    Object sender1,
                    X509Certificate certificate,
                    X509Chain chain,
                    SslPolicyErrors sslPolicyErrors)
                {
                    return true;
                };
        }
imanabidi