Class NettyPipelineSslUtils
java.lang.Object
io.servicetalk.transport.netty.internal.NettyPipelineSslUtils
Utilities for
ChannelPipeline and SSL/TLS.-
Method Summary
Modifier and TypeMethodDescriptionstatic io.netty.handler.ssl.SslHandlerapplicationSslHandler(io.netty.channel.ChannelPipeline pipeline) Returns the application-tierSslHandler, ornullif none is present.static SSLSessionextractSslSession(io.netty.channel.ChannelPipeline pipeline, io.netty.handler.ssl.SslHandshakeCompletionEvent sslEvent, Consumer<Throwable> failureConsumer) Extracts theSSLSessionfrom theChannelPipelineif theSslHandshakeCompletionEventis successful or propagate the failure tofailureConsumer.static SSLSessionextractSslSession(SslConfig sslConfig, io.netty.channel.ChannelPipeline pipeline) Extracts theSSLSessionfrom theChannelPipelineif the handshake is already done.static SSLSessionextractSslSessionAndReport(io.netty.channel.ChannelPipeline pipeline, io.netty.handler.ssl.SslHandshakeCompletionEvent sslEvent, Consumer<Throwable> failureConsumer, boolean shouldReport) Deprecated.static SSLSessionextractSslSessionAndReport(SslConfig sslConfig, io.netty.channel.ChannelPipeline pipeline, ConnectionObserver connectionObserver) Deprecated.UseextractSslSession(SslConfig, ChannelPipeline)instead, reporting toConnectionObserver.SecurityHandshakeObserveris handled automatically for allSslHandlers initialized bySslClientChannelInitializerorSslServerChannelInitializerstatic voidinstallProxyTlsStage(io.netty.channel.Channel channel, io.netty.handler.ssl.SslContext sslContext, ClientSslConfig sslConfig) Install the outer (proxy) TLS stage of a layered-TLS pipeline.static booleanisSslEnabled(io.netty.channel.ChannelPipeline pipeline) Deprecated.not required anymore, will be removed in the future releases, seeextractSslSessionAndReport(SslConfig, ChannelPipeline, ConnectionObserver)for an alternative approachstatic io.netty.handler.ssl.SslHandlerproxySslHandler(io.netty.channel.ChannelPipeline pipeline) Returns the proxySslHandlerinstalled byinstallProxyTlsStage(io.netty.channel.Channel, io.netty.handler.ssl.SslContext, io.servicetalk.transport.api.ClientSslConfig), ornullif none is present (a plaintext proxy hop or a non-proxy connection).
-
Method Details
-
isSslEnabled
Deprecated.not required anymore, will be removed in the future releases, seeextractSslSessionAndReport(SslConfig, ChannelPipeline, ConnectionObserver)for an alternative approachDetermine if theChannelPipelineis configured for SSL/TLS.- Parameters:
pipeline- The pipeline to check.- Returns:
trueif the pipeline is configured to use SSL/TLS.
-
extractSslSessionAndReport
@Nullable @Deprecated public static SSLSession extractSslSessionAndReport(@Nullable SslConfig sslConfig, io.netty.channel.ChannelPipeline pipeline, ConnectionObserver connectionObserver) Deprecated.UseextractSslSession(SslConfig, ChannelPipeline)instead, reporting toConnectionObserver.SecurityHandshakeObserveris handled automatically for allSslHandlers initialized bySslClientChannelInitializerorSslServerChannelInitializerExtracts theSSLSessionfrom theChannelPipelineif the handshake is already done and reports the result toConnectionObserver.SecurityHandshakeObserverif available. If it's done but failed, it rethrows the result.- Parameters:
sslConfig-SslConfigif SSL/TLS is expectedpipeline-ChannelPipelinewhich contains a handler containing theSSLSessionconnectionObserver-ConnectionObserverin case the handshake status should be reported- Returns:
- The
SSLSessionornullif none can be found - Throws:
IllegalStateException- ifSslHandlercan not be found in theChannelPipeline
-
extractSslSession
@Nullable public static SSLSession extractSslSession(@Nullable SslConfig sslConfig, io.netty.channel.ChannelPipeline pipeline) Extracts theSSLSessionfrom theChannelPipelineif the handshake is already done. If it's done but failed, it rethrows the result.- Parameters:
sslConfig-SslConfigif SSL/TLS is expectedpipeline-ChannelPipelinewhich contains a handler containing theSSLSession- Returns:
- The
SSLSessionornullif none can be found - Throws:
IllegalStateException- ifSslHandlercan not be found in theChannelPipeline
-
extractSslSessionAndReport
@Nullable @Deprecated public static SSLSession extractSslSessionAndReport(io.netty.channel.ChannelPipeline pipeline, io.netty.handler.ssl.SslHandshakeCompletionEvent sslEvent, Consumer<Throwable> failureConsumer, boolean shouldReport) Deprecated.UseextractSslSession(ChannelPipeline, SslHandshakeCompletionEvent, Consumer)instead, reporting toConnectionObserver.SecurityHandshakeObserveris handled automatically for allSslHandlers initialized bySslClientChannelInitializerorSslServerChannelInitializer.Extracts theSSLSessionfrom theChannelPipelineif theSslHandshakeCompletionEventis successful and reports the result toConnectionObserver.SecurityHandshakeObserverif available.- Parameters:
pipeline- theChannelPipelinewhich contains handler containing theSSLSession.sslEvent- the event indicating a SSL/TLS handshake completed.failureConsumer- invoked if a failure is encountered.shouldReport-trueif the handshake status should be reported toConnectionObserver.SecurityHandshakeObserver.- Returns:
- The
SSLSessionornullif none can be found.
-
extractSslSession
@Nullable public static SSLSession extractSslSession(io.netty.channel.ChannelPipeline pipeline, io.netty.handler.ssl.SslHandshakeCompletionEvent sslEvent, Consumer<Throwable> failureConsumer) Extracts theSSLSessionfrom theChannelPipelineif theSslHandshakeCompletionEventis successful or propagate the failure tofailureConsumer.- Parameters:
pipeline- theChannelPipelinewhich contains handler containing theSSLSession.sslEvent- the event indicating a SSL/TLS handshake completed.failureConsumer- invoked if a failure is encountered.- Returns:
- The
SSLSessionornullif none can be found.
-
applicationSslHandler
@Nullable public static io.netty.handler.ssl.SslHandler applicationSslHandler(io.netty.channel.ChannelPipeline pipeline) Returns the application-tierSslHandler, ornullif none is present.With layered TLS (e.g. an outer proxy TLS stage plus an inner origin TLS stage on the same
Channel) the origin handler is the one whoseSSLSessionrepresents the application-visible session. Callers that operate on the application-level session should use this helper instead ofpipeline.get(SslHandler.class), which returns the head-most handler — the wrong one for layered TLS.Iterates rather than looking up by
APPLICATION_SSL_HANDLER_NAMEbecause not everySslHandleris installed under that name (e.g. handlers installed by third-party Netty code).- Parameters:
pipeline- the pipeline to inspect for aSslHandler.- Returns:
- the application-tier (last-in-pipeline-order)
SslHandler, ornullif none is present.
-
proxySslHandler
@Nullable public static io.netty.handler.ssl.SslHandler proxySslHandler(io.netty.channel.ChannelPipeline pipeline) Returns the proxySslHandlerinstalled byinstallProxyTlsStage(io.netty.channel.Channel, io.netty.handler.ssl.SslContext, io.servicetalk.transport.api.ClientSslConfig), ornullif none is present (a plaintext proxy hop or a non-proxy connection).- Parameters:
pipeline- the pipeline to inspect for the proxySslHandler.- Returns:
- the proxy
SslHandler, ornullif none is present.
-
installProxyTlsStage
public static void installProxyTlsStage(io.netty.channel.Channel channel, io.netty.handler.ssl.SslContext sslContext, ClientSslConfig sslConfig) Install the outer (proxy) TLS stage of a layered-TLS pipeline. Adds an eager proxySslHandlernamedPROXY_SSL_HANDLER_NAMEfollowed by an internal isolator that drops outer-stageSslHandshakeCompletionEventandSslCloseCompletionEventfrom reaching handlers downstream (which expect application-level TLS events). The proxy handshake is reported to theSecurityHandshakeObserverreturned byConnectionObserver.onProxySecurityHandshake(SslConfig), separate from the application-levelConnectionObserver.onSecurityHandshake(SslConfig).- Parameters:
channel- the channel whose pipeline to install onsslContext- theSslContextfor the proxy TLS stagesslConfig- theClientSslConfigfor the proxy TLS stage
-
extractSslSession(ChannelPipeline, SslHandshakeCompletionEvent, Consumer)instead, reporting toConnectionObserver.SecurityHandshakeObserveris handled automatically for allSslHandlers initialized bySslClientChannelInitializerorSslServerChannelInitializer.