Two way SSL authentication in Netty

java, netty, ssl

Solution

Is two way authentication possible using Netty?

Yes

Can it be simply achievable by adding another SslHandler to the pipelinefactories of both server and client?

Yes

If the above is true, how can I grab the required SslHandler at the ChannelConnected() method to do the SslHandshake?

You need the setup the keystore and the truststore correctly when creating your `SSLContext`.

And Is it possible to invoke the second handshake at the ChannelConected() method by calling the pipeline back again?

From memory, client and server authentication is done in the 1st handshake.

On the client, install the client's private key in the keystore and the server's public key in the truststore.

On the server, install the server's private key in the keystore and the client's public key in the truststore.

Are there any examples I could refer to regarding this?

Here's an example I did for websockets. It only shows you how to setup the server keystore. You will have to add a truststore as the 2nd parameter of `serverContext.init(kmf.getKeyManagers(), null, null);`

Here's a similar example in Scala with trust store setup.

Here's a good java guide on how to setup SSLContext.

Hope this helps.

Problem

I'm working on a Server and Client based app which require two way SSL authentication. (Client authenticates server and Server authenticate client both using SSL Certificates.) I'm quite new to Netty and have few doubts regarding this. - Is two way authentication possible using Netty? - Can it be simply achievable by adding another SslHandler to the pipelinefactories of both server and client? - If the above is true, how can I grab the required SslHandler at the ChannelConnected() method to do the SslHandshake? And Is it possible to invoke the second handshake at the ChannelConected() method by calling the pipeline back again? - Are there any examples I could refer to regarding this? I really appreciate any help regarding this, answers or a push in right direction.

Original source