1

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?

dolmen
  • 8,126
  • 5
  • 40
  • 42

1 Answers1

-1

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");
Jcs
  • 13,279
  • 5
  • 53
  • 70
  • SSLEngine is needed to work with NIO, and this is mentionned in my question. Without SSLEngine we have to use a [dirty hack](http://rox-xmlrpc.sourceforge.net/niotut/index.html#NIO) that use blocking reads with 1ms timeout. – dolmen Nov 15 '13 at 11:04
  • I'm sorry, I read your question too quickly. Unfortunately I'm not aware of any other NIO-compatible Oracle independent TLS implementation. – Jcs Nov 15 '13 at 11:27