Implementation of SSLEngine for JDK 1.4?

1.4k Views Asked by At

I have a NIO-based application that has to work on a Java 1.4 platform (not Sun/Oracle implementation) and for which I would like to secure the network connections with SSL. But the javax.net.ssl.SSLEngine API is only available starting with Java 5.

Does an alternative, free, pure-Java, implementation of the javax.net.ssl.SSLEngine API exists?

BouncyCastle seems to provide an implementation of JCE, but I did not found javax.net.ssl.SSLEngine in their packages. Did I miss something?

1

There are 1 best solutions below

2
On

The SSLEngine engine class is only needed when you want to access to the low-level SSL features, without the socket wrapping. But if you want to secure a network connection using the SSLSocketFactory, SSLServerSocketFactory or even HttpsURLConnection classes may do the job.

An short example code snippet:

SSLContext sslContext = SSLContext.getInstance("TLS");
SSLSocketFactory sf = sslContext.getSSLSocketFactory();
Socket socket = new Socket();
Socket sslSocket = sf.createSocket(socket, "ssl.example.com", 4443, true);
OutputStream out = sslSocket.getOutputStream();
out.write(/* ... */);

Note that if you are not using the Sun JDK/JRE implementation, the "TLS" algorithm implementation may be absent and the SSLContext.getInstance may throw a NoSuchAlgorithmException. In that case you should use the BouncyCastle Security Provider.

You can add the BC provider with calling:

java.security.Security.addProvider(new BouncyCastleProvider());

And request an BC-specific SSLContext implementation:

SSLContext sslContext = SSLContext.getInstance("TLS", "BC");