https -- connects fine on windows / error on unix

Recently I had been struggling with some code to get a https connection to work. It was coming up with an error that no trusted certificates could be found. I resolved that thanks to some feedback and sites but i've encountered a new problem -- I'm working on the program on Windows and putting into a unix server to be run. This worked fine initially with no problems, then the server changed from http to https, so I had to implement some changes to deal with this (as mentioned above) -- now however, even though it works fine on windows when put on unix, it throws up this error

java.net.ConnectException: Connection refused

here's the code..

java.security.Security.insertProviderAt(new sun.security.provider.Sun(),2);

java.security.Security.addProvider(new sun.security.provider.Sun());

java.security.Security.insertProviderAt(new com.sun.net.ssl.internal.ssl.Provider(),1);

// set protocol to java.protocol.handler.pkgs property to 'HTTP'

// -- to do with if report server site is HTTPS

System.setProperty("java.protocol.handler.pkgs","HTTP");

// Trustmanager -- set to trust any certificate for a secure server

TrustManager[] trustAllCerts =new TrustManager[]{new X509TrustManager(){

public java.security.cert.X509Certificate[] getAcceptedIssuers(){

returnnull;

}

publicvoid checkClientTrusted(

java.security.cert.X509Certificate[] certs, String authType){

}

publicvoid checkServerTrusted(

java.security.cert.X509Certificate[] certs, String authType){

}

}};

try{

SSLContext sc = SSLContext.getInstance("SSL");

sc.init(null, trustAllCerts,new java.security.SecureRandom());

HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());

}catch (Exception e){

e.printStackTrace();

}

URL url =null;

try{

url =new URL( rptUrl );//rptUrl contains url to use

}catch (MalformedURLException mue){

mue.printStackTrace();

}

//HttpsURLConnection c;

try{

URLConnection c = url.openConnection();

//set cache and request method settings

c.setUseCaches(false);

//set other headers

c.setRequestProperty ("Content-Type","application/pdf");

//connect to the server..

c.connect();

////some code about what to do with file etc etc....

Any ideas why unix isnt liking this? Thanks a lot

[4099 byte] By [uninvitedma] at [2007-11-27 7:03:23]
# 1
Just bumping.
uninvitedma at 2007-7-12 18:54:35 > top of Java-index,Java Essentials,Java Programming...
# 2

> java.net.ConnectException: Connection refused

'Connection refused' means there is nothing listening at that host:port. Simple as that. Fix the URL to point to the HTTPS server. HTTP uses port 80, HTTPS tends to use port 443.

However there are other problems here:

> java.security.Security.insertProviderAt(new sun.security.provider.Sun(),2);

> java.security.Security.addProvider(new sun.security.provider.Sun());

> java.security.Security.insertProviderAt(new com.sun.net.ssl.internal.ssl.Provider(),1);

> // set protocol to java.protocol.handler.pkgs property to 'HTTP'

> // -- to do with if report server site is HTTPS

>

> System.setProperty("java.protocol.handler.pkgs","HTTP");

Get rid of all that. It is obsolete as well as being largely redundant.

> TrustManager[] trustAllCerts = new TrustManager[] {

> { new X509TrustManager() {

> public java.security.cert.X509Certificate[] getAcceptedIssuers() {

> return null;

> }

That implementation violates the specification of the method. Get rid of this TrustManager implementation altogether. It is not secure. Solve the problem with the server certificate not being trusted by the client's truststore instead.

> SSLContext sc = SSLContext.getInstance("SSL");

> sc.init(null, trustAllCerts, newew java.security.SecureRandom());

> HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());

Get rid of that too, it's part of the same problem.

ejpa at 2007-7-12 18:54:35 > top of Java-index,Java Essentials,Java Programming...