Java / SSL

I was getting this error when trying to write a test case using JWebUnit, which uses HtmlUnit.

8097 [main] ERROR c.g.htmlunit.html.HtmlPage - Error loading JavaScript from []. peer not authenticated
	at ~[na:1.6]
	at org.apache.http.conn.ssl.AbstractVerifier.verify( ~[httpclient-4.1.2.jar:4.1.2]
	at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket( ~[httpclient-4.1.2.jar:4.1.2]
	at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection( ~[httpclient-4.1.2.jar:4.1.2]
	at ~[httpclient-4.1.2.jar:4.1.2]
	at ~[httpclient-4.1.2.jar:4.1.2]
	at org.apache.http.impl.client.DefaultRequestDirector.tryConnect( ~[httpclient-4.1.2.jar:4.1.2]

This may occur for a number of reasons:

Enable SSL debugging

Set the system property.

For example, adding the following to setenv.bat for Tomcat:


You are using a self-signed certificate

You can import the self-signed certificate into an existing store by using the keytool -import tool.

You are not reusing the existing certificate authorities

By default, creating a new keystore will not reuse the existing list of certificate authorities. You can copy the local cacerts list of authorities and add certificates directly to this keystore; the default keystore password is changeit.

A different certificate is being provided

To export a copy of the SSL certificate provided by a particular URL, use the command openssl s_client -showcerts -connect </dev/null. You can then copy the certificate directly from here into a new certificate file.