This approved certificate list is provided by three files in the Java certificate setup:
You need to add your root certificate to the cacerts or
the jssecacerts file or provide your own file.
Use a command like: keytool ...
I tried adding the certificate (generated originally by openssl during
the set up of my Apache/SSL web server) to the cacerts file using
the keytool utility from Sun's 1.2 JDK but it failed with an error
about an invalid signature. After mucking about I eventually settled with
my own certificate file (keystore?) by using the IBM 1.3 keytool
utility (it didn't complain, it just went ahead and worked).
or alternatively:
add to your Java source: java.security.Security.addProvider(new com.sun.net.ssl.Provider())
The first method adds the security provider statically, where the second
does it dynamically at run-time.
public class TestHttps {
// here we're using the https protocol
String updateSourceURL = "https://www.connect4.com.au/index.html";
public static void main(String argv[]) throws Exception {
Properties prop = new Properties();
// set the protocol handler
prop.put("java.protocol.handler.pkgs","com.sun.net.ssl.internal.www.protocol");
// my JRE barfs if this
is not set
prop.put("user.timezone","GMT+10:00");
// I'm using my own certificate
store
// If you have your
certificate in one of the standard places (cacerts or
// jssecacerts) then
ignore this line.
prop.put("javax.net.ssl.trustStore","/home/peterlg/certificates/myjavacerts");
// use these next two
for going through a proxy server
// prop.put("https.proxyHost","pxysvr.myorg.com");
// prop.put("https.proxyPort","80");
// or try 443
// set our properties
now
System.setProperties(prop);
// we don't need this
if we set the .../jre/lib/security/java.security file
java.security.Security.addProvider(new
com.sun.net.ssl.internal.ssl.Provider());
// do the URL thing like
normal...
URL url = new URL(updateSourceURL);
URLConnection urlConnection
= url.openConnection();
BufferedReader in =
new BufferedReader(
new InputStreamReader(urlConnection.getInputStream()));
String inputLine;
String text = "";
while ((inputLine = in.readLine())
!= null) {
text = text + inputLine + "\n";
}
System.out.println(text);
}
Unsupported ... SSL ...
...stuff...
Exception in thread "..." java.net.SocketException: SSL implementation not available
...
at java.net.SocketException.
at javax.net.ssl.DefaultSSLSocketFactory.createSocket([DashoPro-V1.2-120198])
...
at com.sun.net.ssl.internal.www.protocol.https.HttpsURLConnection.connect([DashoPro-V1.2-120198])
at com.sun.net.ssl.internal.www.protocol.https.HttpsURLConnection.getInputStream([DashoPro-V1.2-120198])
This may indicate that the URL provided is malformed. No https:? Non-existant URL?