Showing posts with label ssl. Show all posts
Showing posts with label ssl. Show all posts

Saturday, July 12, 2014

Android - SSL errors even after installing custom CA certificate

I followed these steps to install my custom CA cert on an Android device

  1. adb push mycert.cer /sdcard/
  2. Go to Settings->Security->Credential storage->Install from device storage
  3. Select the certificate and install
  4. Confirm that the certificate is installed in Settings->Security->Trusted credentials->User

However, the certificate was still not trusted and I was seeing SSL errors on trying to reach an SSL endpoint using the CA cert.

The issue turned out to be that the Date and time was not set correctly on the device. I fixed the Date and time and the SSL errors went away. Yay!

Friday, January 6, 2012

Could not establish trust relationship for the SSL/TLS secure channel

This is a common problem in the testing world where you deploy a service on a HTTPS endpoint by using a self-signed certificate.
When you try to send a request to this service using HTTPWebRequest/WebClient, you see the error:
The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.
The solution to this problem is to ignore the trust by using the following code:

using System.Net;
using System.Net.Security;

           
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return true; });

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://www.mysite.com");

HttpWebResponse response = (HttpWebResponse)request.GetResponse();

Stream stream = response.GetResponseStream();

StreamReader sr = new StreamReader(stream);

string resp = sr.ReadToEnd();