The default Java certificate checks are pretty strict, and have apparently gotten stricter. One workaround is to initialize an SSLContext
with a custom X509TrustManager
. A trust manager that does nothing, i.e. is completely insecure, that I once wrote for testing looks like this:
TrustManager[] trustAllCerts = new TrustManager[]{
new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers()
{
return null;
}
public void checkClientTrusted(
java.security.cert.X509Certificate[] certs,
String authType )
{
}
public void checkServerTrusted(
java.security.cert.X509Certificate[] certs,
String authType )
{
}
}
};
Obviously you would want to actually check the certificate chain in a real program. You could then try to initialize an SSLContext
with it and call SSLContext.setDefault()
if your API has no other way of configuring SSL. If the API uses the default SSL context then this should work.
Key usage does not appear to be the issue in this case as the certificate chain is not self-signed. Testing the URL appears to show that the leaf certificate is not self-signed and (2) the other two certificates in the chain appear to have certificate signing enabled. An alternative possibility is that Java 6 and Java 7 have separate trust stores and the root certificate is not in the Java 7 store. You may want to double-check that. If you have access to OpenSSL, you can get the certificate chain from the server with:
openssl s_client -host www.example.com -port 443 -showcerts
Apparently updating the trust store was the key (pun intended). The OP reports:
I downloaded OpenSSL for Windows 64 and then used this command to download the certificate chain:
openssl s_client -host www.webserviceurl.com -port 443 -showcerts > c:empcertchain_output.crt
Then I want to import it into my browser's keystore like so (from the JDK's home directory/jre/lib/security):
keytool -import -alias ca -file certchain_output.crt -keystore cacerts -storepass changeit
I believe using X509TrustManager could provide an effective solution as well.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…