public static SSLEngine configureHttpPipelineForSSL ( SocketChannel socketChannel , String host , int port , SSLConfig sslConfig ) throws SSLException { LOG . debug ( "adding ssl handler" ) ; SSLEngine sslEngine = null ; SslHandler sslHandler ; ChannelPipeline pipeline = socketChannel . pipeline ( ) ; SSLHandlerFactory sslHandlerFactory = new SSLHandlerFactory ( sslConfig ) ; if ( sslConfig . isOcspStaplingEnabled ( ) ) { sslHandlerFactory . createSSLContextFromKeystores ( false ) ; ReferenceCountedOpenSslContext referenceCountedOpenSslContext = sslHandlerFactory . buildClientReferenceCountedOpenSslContext ( ) ; if ( referenceCountedOpenSslContext != null ) { sslHandler = referenceCountedOpenSslContext . newHandler ( socketChannel . alloc ( ) ) ; sslEngine = sslHandler . engine ( ) ; setSslHandshakeTimeOut ( sslConfig , sslHandler ) ; socketChannel . pipeline ( ) . addLast ( sslHandler ) ; socketChannel . pipeline ( ) . addLast ( new OCSPStaplingHandler ( ( ReferenceCountedOpenSslEngine ) sslEngine ) ) ; } } else { if ( sslConfig . getTrustStore ( ) != null ) { sslHandlerFactory . createSSLContextFromKeystores ( false ) ; sslEngine = instantiateAndConfigSSL ( sslConfig , host , port , sslConfig . isHostNameVerificationEnabled ( ) , sslHandlerFactory ) ; } else { sslEngine = getSslEngineForCerts ( socketChannel , host , port , sslConfig , sslHandlerFactory ) ; } sslHandler = new SslHandler ( sslEngine ) ; setSslHandshakeTimeOut ( sslConfig , sslHandler ) ; pipeline . addLast ( Constants . SSL_HANDLER , sslHandler ) ; if ( sslConfig . isValidateCertEnabled ( ) ) { pipeline . addLast ( Constants . HTTP_CERT_VALIDATION_HANDLER , new CertificateValidationHandler ( sslEngine , sslConfig . getCacheValidityPeriod ( ) , sslConfig . getCacheSize ( ) ) ) ; } } return sslEngine ; }
Configure outbound HTTP pipeline for SSL configuration .