Yikes! This morning I found out our main application server ssl certificate expired. We have to request a new ssl
cert from the Army and it may take a few weeks. The warnings the users get aren't too bad. Everyone ignores
warnings anyways. Some web services are failing though.
So I need to add some code to make the web applications trust invalid ssl certificates.
So in java I put in:
public static void installAllTrustingAuthority()
{
// Create a trust manager that does not validate certificate chains
TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager()
{
public X509Certificate[] getAcceptedIssuers() { return null; }
public void checkClientTrusted(X509Certificate[] certs, String authType) {}
public void checkServerTrusted(X509Certificate[] certs, String authType) {}
} };
try
{
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, null);
sc.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
}
catch (Exception e) { e.printStackTrace(); }
}
In .NET we are getting this error "AuthenticationException : The remote certificate is invalid according to the validation procedure."
So I found this website: http://saftsack.fs.uni-bayreuth.de/~dun3/archives/ignoring-https-related-authenticationexception-when-using-a-webclient/307.html
and added:
public static void SetBypassSslCertificateValidation()
{
ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(BypassSslCertificateValidation);
}
private static bool BypassSslCertificateValidation(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors error)
{ return true; }