Hi All,

I am working on an IoT project and I am using Apache MINA in Server Side Java 
application to make connections between Devices and Server.
Earlier devices were sending handshake message and other messages as plain text 
(ASCII) and it was working fine.

Now we need to implement encryption in devices. We are using "AES_256" algo to 
encrypt messages in devices and there will be a server key to decrypt the 
messages on server.
Please suggest what all changes do I need to do in my server application to 
implement handshaking and decryption?

Currently I have following code in server and it was giving following error 
after adding encryption into device.

public class TcpIpListener {
    @Value("${tcp.ip.port}")
    private int tcpIpPort;

    @Value("${read.buffer.size}")
    private int bufferSize;

    @Value("${idle.time.seconds}")
    private int idleTimeSeconds;

    @Autowired
    private ApplicationContext applicationContext;

    private AbstractIoAcceptor acceptor;

    public void startServer() throws IOException {
        acceptor = new NioSocketAcceptor();
        RequestHandler devRequestHandler = 
applicationContext.getBean(RequestHandler.class);
        acceptor.setHandler(devRequestHandler);
        acceptor.getFilterChain().addLast("logger", new LoggingFilter());
        acceptor.getSessionConfig().setReadBufferSize(bufferSize);
        acceptor.getSessionConfig().setMinReadBufferSize(bufferSize);
        acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 
idleTimeSeconds);
        if (acceptor instanceof NioDatagramAcceptor) {
            ((NioDatagramAcceptor) 
acceptor).getSessionConfig().setReuseAddress(true);
        }
        try {
            acceptor.bind(new InetSocketAddress(tcpIpPort));

        } catch (IOException io) {
            throw new RuntimeException(io);
        }
    }
}


Error:
Exception caught in RequestHandler.exceptionCaught().
java.io.IOException: An existing connection was forcibly closed by the remote 
host
                at sun.nio.ch.SocketDispatcher.read0(Native Method)
                at sun.nio.ch.SocketDispatcher.read(Unknown Source)
                at sun.nio.ch.IOUtil.readIntoNativeBuffer(Unknown Source)
                at sun.nio.ch.IOUtil.read(Unknown Source)
                at sun.nio.ch.SocketChannelImpl.read(Unknown Source)
                at 
org.apache.mina.transport.socket.nio.NioProcessor.read(NioProcessor.java:317)
                at 
org.apache.mina.transport.socket.nio.NioProcessor.read(NioProcessor.java:45)
                at 
org.apache.mina.core.polling.AbstractPollingIoProcessor.read(AbstractPollingIoProcessor.java:683)
                at 
org.apache.mina.core.polling.AbstractPollingIoProcessor.process(AbstractPollingIoProcessor.java:659)
                at 
org.apache.mina.core.polling.AbstractPollingIoProcessor.process(AbstractPollingIoProcessor.java:648)
                at 
org.apache.mina.core.polling.AbstractPollingIoProcessor.access$600(AbstractPollingIoProcessor.java:68)
                at 
org.apache.mina.core.polling.AbstractPollingIoProcessor$Processor.run(AbstractPollingIoProcessor.java:1120)
                at 
org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:64)
                at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown 
Source)
                at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown 
Source)
                at java.lang.Thread.run(Unknown Source)

Thanks & Regards,
Krishan Babbar

============================================================================================================================
 Disclaimer: This message and the information contained herein is proprietary 
and confidential and subject to the Tech Mahindra policy statement, you may 
review the policy at http://www.techmahindra.com/Disclaimer.html externally 
http://tim.techmahindra.com/tim/disclaimer.html internally within TechMahindra. 
============================================================================================================================

Reply via email to