Note that there are some explanatory texts on larger screens.

plurals
  1. POSSL connection getting closed
    primarykey
    data
    text
    <p>I have solved the problem. You need to create an instance of SSLEngine and add it to the pipeline of handlers for each clinent request. I have done this by adding the handler in the channelConnected event and removing the ssl handler in the channel disconnected. This make sure for each channel connected it will be added new.</p> <p>Below is the code of the handler. Is this the right approach for doing persistent socket connection with SSL support?</p> <pre><code>package server; import static org.jboss.netty.buffer.ChannelBuffers.dynamicBuffer; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLEngine; import org.jboss.netty.buffer.ChannelBuffer; import org.jboss.netty.buffer.ChannelBuffers; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelFuture; import org.jboss.netty.channel.ChannelFutureListener; import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.channel.ChannelStateEvent; import org.jboss.netty.channel.ExceptionEvent; import org.jboss.netty.channel.MessageEvent; import org.jboss.netty.channel.SimpleChannelHandler; import org.jboss.netty.channel.group.ChannelGroup; import org.jboss.netty.channel.group.DefaultChannelGroup; import org.jboss.netty.handler.ssl.SslHandler; import ssl.SslContextFactory; import ssl.SslKeyStore; public class ServerHandler extends SimpleChannelHandler { private static final String ECHORES = "0057081082200000000000000400000000000000070612201399966400301"; @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { System.out.println("Inside ServerHandler.messageReceived"); ChannelBuffer buffer = (ChannelBuffer) e.getMessage(); ChannelBuffer temp = dynamicBuffer(); temp.writeBytes(buffer); if (temp.readableBytes() &gt;= 4) { byte messageLen[] = new byte[4]; temp.readBytes(messageLen); int len = Integer.parseInt(new String(messageLen)); System.out.println("Length of the message is : " + len); if (temp.readableBytes() &gt;= len) { byte[] message = new byte[len]; temp.readBytes(message); System.out.println("Input message is : " + new String(message)); Channel channel = e.getChannel(); buffer = ChannelBuffers.copiedBuffer(ECHORES.getBytes()); ChannelFuture future = channel.write(buffer); future.addListener(ChannelFutureListener.CLOSE); } } } @Override public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception { e.getCause().printStackTrace(); Channel channel = e.getChannel(); channel.close(); } @Override public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { String file = "test.jks"; SSLContext sslCtx = SslContextFactory.getServerContext(new SslKeyStore(file)); final SSLEngine sslEngine =sslCtx.createSSLEngine(); sslEngine.setNeedClientAuth(false); sslEngine.setUseClientMode(false); final SslHandler sslHandler = new SslHandler(sslEngine); ctx.getPipeline().addFirst("ssl", sslHandler); ChannelFuture handshakeFuture = sslHandler.handshake(); handshakeFuture.addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { if (future.isSuccess()) { System.out.println("SSL/TLS session established"); System.out.println("Your session is protected by "+ sslHandler.getEngine(). getSession().getCipherSuite() + " cipher suite.\n"); } else { future.getChannel().close(); } } }); } @Override public void channelDisconnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { System.out.println("Inside ServerHandler.channelDisconnected"); ctx.getPipeline().remove("ssl"); } } </code></pre> <p>I am getting the following exception while using netty with ssl. My first transaction and handshake goes fine. If I send a new message to teh server again I am getting this exception.</p> <p>"javax.net.ssl.SSLException: SSLEngine is closing/closed"</p> <p>What could be going wrong here. How to keep the esatablished TLS/SSL session? This error happens at org.jboss.netty.handler.ssl.SslHandler.handshake(SslHandler.java:358).</p> <p>Intention is to keep the server running with a persistent TLS socket connection , so that clients can send messages.</p> <p>-TK</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload