Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7590905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:31:17+00:00 2026-05-30T20:31:17+00:00

I am now trying to set up Netty with a 2 way SSL handshake,

  • 0

I am now trying to set up Netty with a 2 way SSL handshake, where both the client and server present and verify certificates.

This does not appear to be implemented in SslHandler. Has anyone does this? I suppose it would go in the SslHandler.handshake operation and be delegated to javax.net.ssl.SSLEngine?

Any hints/tips/pre-existing implementations?

Thanks!


ANSWER (stackoverflow won’t let me post it the normal way) I found that if I set the needClientAuth flag on the SSLEngine object before setting up my SslHandler, that takes care of the problem!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T20:31:19+00:00Added an answer on May 30, 2026 at 8:31 pm

    Here is the solution, based on the HttpSnoop server example from the netty project.

    When setting up the client side pipeline, the ssl engine must be set as follows:

    public ChannelPipeline getPipeline() throws Exception {
        // Create a default pipeline implementation.
        ChannelPipeline pipeline = pipeline();
    
        // Uncomment the following line if you want HTTPS
        SSLEngine engine = SecureChatSslContextFactory.getServerContext().createSSLEngine();
        engine.setUseClientMode(false);
        engine.setNeedClientAuth(true);
        pipeline.addLast("ssl", new SslHandler(engine));
    
        pipeline.addLast("decoder", new HttpRequestDecoder());
        pipeline.addLast("logger", new RequestAuditLogger());
        // Uncomment the following line if you don't want to handle HttpChunks.
        pipeline.addLast("aggregator", new HttpChunkAggregator(1048576));
        pipeline.addLast("outputLogger", new ResponseAuditLogger());
        pipeline.addLast("encoder", new HttpResponseEncoder());
        // Remove the following line if you don't want automatic content compression.
        pipeline.addLast("deflater", new HttpContentCompressor());
        pipeline.addLast("handler", new HttpSnoopServerHandler());
        return pipeline;
    }
    }
    

    Then your SSLContext must be modified as follows to set up a trust store in addition to a keystore (SecureChatSslContextFactory):

    public final class SecureChatSslContextFactory {
    
    
    private static Logger logger = LoggerFactory.getLogger(SecureChatSslContextFactory.class);
    
    private static final String PROTOCOL = "TLS";
    private static final SSLContext SERVER_CONTEXT;
    private static final SSLContext CLIENT_CONTEXT;
    
    static {
    
        SSLContext serverContext = null;
        SSLContext clientContext = null;
    
            // get keystore and trustore locations and passwords
        String keyStoreLocation = System.getProperty("javax.net.ssl.keyStore");
        String keyStorePassword = System.getProperty("javax.net.ssl.keyStorePassword");
        String trustStoreLocation = System.getProperty("javax.net.ssl.trustStore");
        String trustStorePassword = System.getProperty("javax.net.ssl.trustStorePassword");
        try {
    
            KeyStore ks = KeyStore.getInstance("JKS");
            ks.load(KeyStoreStreamManager.asInputStream(keyStoreLocation),
                    keyStorePassword.toCharArray());
    
            // Set up key manager factory to use our key store
            KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
            kmf.init(ks, keyStorePassword.toCharArray());
    
              // truststore
            KeyStore ts = KeyStore.getInstance("JKS");
            ts.load(KeyStoreStreamManager.asInputStream(trustStoreLocation),
                    trustStorePassword.toCharArray());
    
            // set up trust manager factory to use our trust store
            TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
            tmf.init(ts);
    
            // Initialize the SSLContext to work with our key managers.
            serverContext = SSLContext.getInstance(PROTOCOL);
            serverContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
    
        } catch (Exception e) {
            throw new Error(
                    "Failed to initialize the server-side SSLContext", e);
        }
    
        try {
            clientContext = SSLContext.getInstance(PROTOCOL);
            clientContext.init(null, SecureChatTrustManagerFactory.getTrustManagers(), null);
        } catch (Exception e) {
            throw new Error(
                    "Failed to initialize the client-side SSLContext", e);
        }
    
        SERVER_CONTEXT = serverContext;
        CLIENT_CONTEXT = clientContext;
    }
    
    public static SSLContext getServerContext() {
        return SERVER_CONTEXT;
    }
    
    public static SSLContext getClientContext() {
        return CLIENT_CONTEXT;
    }
    
    private SecureChatSslContextFactory() {
        // Unused
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm now trying to create a xml-rpc server with the CodeIgniter Framework. <?php $this->load->library('xmlrpc');
I have set up an ISPconfig server and am now trying to install curl.
Right now I'm trying to set the default audio device on Windows 7 programmatically,
I asked this question earlier and am now trying to explore the idea of
I'm very new to Maven and am just now trying to set up my
I've just set up a new computer and now trying to install my app
I've installed CCNet and now I'm trying to set up a link to our
I'm trying to set a callback function in Jack. This is usually quite simple,
I am now trying to deploy my application to my ubuntu server-11.04(hostname: chicago), but
I am now trying to understand some code and I have found a pattern,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.