Java Web Start & OpenSSL


G

Giovanni

Hi there,

I'm trying to get a openssl server (SSL v2) to talk to a java web
start application using JSSE on JDK 1.4 (1.4.2.03). The code above is
a piece of this application that WORKS if executed as a simple java
application BUT fails if executed inside a Java Web Start Application.
The JWS application is signed but when I run my code I get the error:

java.net.ConnectException: Connection refused: connect

at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at sun.net.www.protocol.https.HttpsClient$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.net.www.protocol.https.HttpsClient.doConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.protocol.https.HttpsClient.<init>(Unknown Source)
at sun.net.www.protocol.https.HttpsClient.a(Unknown Source)
at sun.net.www.protocol.https.HttpsClient.a(Unknown Source)
at sun.net.www.protocol.https.HttpsClient.a(Unknown Source)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.plainConnect(Unknown
Source)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown
Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown
Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(Unknown
Source)


Any help/advice greatly appreciated!

Thanks
Gio


import java.io.DataOutputStream;
import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.cert.X509Certificate;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

class MyNameVerifier implements HostnameVerifier {
public boolean verify(String hostname, SSLSession session) {
return true;
}
}

class MyTrustManager implements X509TrustManager {

MyTrustManager() {
}

public void checkClientTrusted(
X509Certificate ax509certificate[],
String authType) {
return;
}

public void checkServerTrusted(
X509Certificate ax509certificate[],
String authType) {
return;
}

public boolean isClientTrusted(X509Certificate[] cert) {
return true;
}

public boolean isServerTrusted(X509Certificate[] cert) {
return true;
}

public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}

}

public class HTTPSClient {

public static void main(String[] args) {

String hostName = "https://my.httpsserver.it";
int port = 611;
String strUrl = hostName + ":" + port;

URL url = null;
try {
url = new URL(strUrl);
} catch (MalformedURLException e) {
e.printStackTrace();
}
HttpsURLConnection con = null;
//System.setProperty("javax.net.debug", "all");
try {
SSLContext ctx = SSLContext.getInstance("SSL");
ctx.init(null, null, new java.security.SecureRandom());

X509TrustManager oTrustMngr = new MyTrustManager();
TrustManager trustManagersList[] = { oTrustMngr };
ctx.init(null, trustManagersList, null);

con = (HttpsURLConnection) url.openConnection();
con.setInstanceFollowRedirects(true);
con.setDoInput(true);
con.setDoOutput(true);
con.setSSLSocketFactory(ctx.getSocketFactory());
con.setHostnameVerifier(new MyNameVerifier());

DataOutputStream m_out =
new DataOutputStream(con.getOutputStream());
m_out.writeBytes("1234");
m_out.flush();

} catch (Exception e) {
System.out.println(e.toString());
e.printStackTrace();
}

System.out.println("End");
}
}
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top