netty support SSL, OpenSSL

io.netty.channel.Channel Import; 
Import io.netty.channel.ChannelInitializer; 
Import io.netty.handler.ssl.SslContext; 
Import io.netty.handler.ssl.SslHandler; 

Import javax.net.ssl.SSLEngine; 

public the extends ChannelInitializer SslChannelInitializer class <Channel> { 
    Private Final SSLContext context; 
    Private Final Boolean STARTTLS; 
    // context: to be used incoming SSLContext 
    // STARTTLS: If set to true, the first message writing will not be encrypted ( The client should be set to true) 
    public SslChannelInitializer (SSLContext context, Boolean STARTTLS) { 
        this.context = context; 
        this.startTls = STARTTLS; 
    } 

    @Override 
    protected void initChannel (CH Channel) throws Exception {
        // For each SslHandler instance, use ByteBufAllocator Channel acquired from a new SSLEngine SSLContext 
        SSLEngine = context.newEngine Engine (ch.alloc ()); 
        // add as the first ChannelHandler ChannelPipeline SslHandler to the 
        ch.pipeline () .addFirst ( "SSL", new new SslHandler (Engine, STARTTLS));    
    } 
}

  

 

Guess you like

Origin www.cnblogs.com/htkj/p/10932569.html