4646import io .grpc .internal .GrpcUtil ;
4747import io .grpc .internal .NoopSslSession ;
4848import io .grpc .internal .ObjectPool ;
49- import io .netty .channel .Channel ;
5049import io .netty .channel .ChannelDuplexHandler ;
5150import io .netty .channel .ChannelFutureListener ;
5251import io .netty .channel .ChannelHandler ;
6160import io .netty .handler .codec .http2 .Http2ClientUpgradeCodec ;
6261import io .netty .handler .proxy .HttpProxyHandler ;
6362import io .netty .handler .proxy .ProxyConnectionEvent ;
64- import io .netty .handler .ssl .ClientAuth ;
6563import io .netty .handler .ssl .OpenSsl ;
6664import io .netty .handler .ssl .OpenSslEngine ;
6765import io .netty .handler .ssl .SslContext ;
@@ -141,7 +139,7 @@ public static FromChannelCredentialsResult from(ChannelCredentials creds) {
141139 trustManagers = tlsCreds .getTrustManagers ();
142140 } else if (tlsCreds .getRootCertificates () != null ) {
143141 trustManagers = Arrays .asList (CertificateUtils .createTrustManager (
144- new ByteArrayInputStream (tlsCreds .getRootCertificates ())));
142+ new ByteArrayInputStream (tlsCreds .getRootCertificates ())));
145143 } else { // else use system default
146144 TrustManagerFactory tmf = TrustManagerFactory .getInstance (
147145 TrustManagerFactory .getDefaultAlgorithm ());
@@ -159,7 +157,7 @@ public static FromChannelCredentialsResult from(ChannelCredentials creds) {
159157 }
160158 }
161159 return FromChannelCredentialsResult .negotiator (tlsClientFactory (builder .build (),
162- (X509TrustManager ) x509ExtendedTrustManager ));
160+ (X509TrustManager ) x509ExtendedTrustManager ));
163161 } catch (SSLException | GeneralSecurityException ex ) {
164162 log .log (Level .FINE , "Exception building SslContext" , ex );
165163 return FromChannelCredentialsResult .error (
@@ -225,15 +223,15 @@ public static FromServerCredentialsResult from(ServerCredentials creds) {
225223 } // else use system default
226224 switch (tlsCreds .getClientAuth ()) {
227225 case OPTIONAL :
228- builder .clientAuth (ClientAuth .OPTIONAL );
226+ builder .clientAuth (io . netty . handler . ssl . ClientAuth .OPTIONAL );
229227 break ;
230228
231229 case REQUIRE :
232- builder .clientAuth (ClientAuth .REQUIRE );
230+ builder .clientAuth (io . netty . handler . ssl . ClientAuth .REQUIRE );
233231 break ;
234232
235233 case NONE :
236- builder .clientAuth (ClientAuth .NONE );
234+ builder .clientAuth (io . netty . handler . ssl . ClientAuth .NONE );
237235 break ;
238236
239237 default :
@@ -281,7 +279,7 @@ public static final class FromChannelCredentialsResult {
281279 public final String error ;
282280
283281 private FromChannelCredentialsResult (ProtocolNegotiator .ClientFactory negotiator ,
284- CallCredentials creds , String error ) {
282+ CallCredentials creds , String error ) {
285283 this .negotiator = negotiator ;
286284 this .callCredentials = creds ;
287285 this .error = error ;
@@ -395,7 +393,7 @@ public ProtocolNegotiator newNegotiator(ObjectPool<? extends Executor> offloadEx
395393 * @param executorPool a dedicated {@link Executor} pool for time-consuming TLS tasks
396394 */
397395 public static ProtocolNegotiator serverTls (final SslContext sslContext ,
398- final ObjectPool <? extends Executor > executorPool ) {
396+ final ObjectPool <? extends Executor > executorPool ) {
399397 Preconditions .checkNotNull (sslContext , "sslContext" );
400398 final Executor executor ;
401399 if (executorPool != null ) {
@@ -444,8 +442,8 @@ static final class ServerTlsHandler extends ChannelInboundHandlerAdapter {
444442 private ProtocolNegotiationEvent pne = ProtocolNegotiationEvent .DEFAULT ;
445443
446444 ServerTlsHandler (ChannelHandler next ,
447- SslContext sslContext ,
448- final ObjectPool <? extends Executor > executorPool ) {
445+ SslContext sslContext ,
446+ final ObjectPool <? extends Executor > executorPool ) {
449447 this .sslContext = Preconditions .checkNotNull (sslContext , "sslContext" );
450448 this .next = Preconditions .checkNotNull (next , "next" );
451449 if (executorPool != null ) {
@@ -475,7 +473,7 @@ public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exc
475473 }
476474 SslHandler sslHandler = ctx .pipeline ().get (SslHandler .class );
477475 if (!sslContext .applicationProtocolNegotiator ().protocols ().contains (
478- sslHandler .applicationProtocol ())) {
476+ sslHandler .applicationProtocol ())) {
479477 logSslEngineDetails (Level .FINE , ctx , "TLS negotiation failed for new client." , null );
480478 ctx .fireExceptionCaught (unavailableException (
481479 "Failed protocol negotiation: Unable to find compatible protocol" ));
@@ -502,8 +500,8 @@ private void fireProtocolNegotiationEvent(ChannelHandlerContext ctx, SSLSession
502500 * Returns a {@link ProtocolNegotiator} that does HTTP CONNECT proxy negotiation.
503501 */
504502 public static ProtocolNegotiator httpProxy (final SocketAddress proxyAddress ,
505- final @ Nullable String proxyUsername , final @ Nullable String proxyPassword ,
506- final ProtocolNegotiator negotiator ) {
503+ final @ Nullable String proxyUsername , final @ Nullable String proxyPassword ,
504+ final ProtocolNegotiator negotiator ) {
507505 Preconditions .checkNotNull (negotiator , "negotiator" );
508506 Preconditions .checkNotNull (proxyAddress , "proxyAddress" );
509507 final AsciiString scheme = negotiator .scheme ();
@@ -580,8 +578,10 @@ protected void userEventTriggered0(ChannelHandlerContext ctx, Object evt) throws
580578 static final class ClientTlsProtocolNegotiator implements ProtocolNegotiator {
581579
582580 public ClientTlsProtocolNegotiator (SslContext sslContext ,
583- ObjectPool <? extends Executor > executorPool , Optional <Runnable > handshakeCompleteRunnable ,
584- X509TrustManager x509ExtendedTrustManager , String sni ) {
581+ ObjectPool <? extends Executor > executorPool ,
582+ Optional <Runnable > handshakeCompleteRunnable ,
583+ X509TrustManager x509ExtendedTrustManager ,
584+ String sni ) {
585585 this .sslContext = Preconditions .checkNotNull (sslContext , "sslContext" );
586586 this .executorPool = executorPool ;
587587 if (this .executorPool != null ) {
@@ -608,9 +608,9 @@ public AsciiString scheme() {
608608 public ChannelHandler newHandler (GrpcHttp2ConnectionHandler grpcHandler ) {
609609 ChannelHandler gnh = new GrpcNegotiationHandler (grpcHandler );
610610 ChannelLogger negotiationLogger = grpcHandler .getNegotiationLogger ();
611- ChannelHandler cth = new ClientTlsHandler (gnh , sslContext , grpcHandler . getAuthority (),
612- this . executor , negotiationLogger , handshakeCompleteRunnable ,
613- x509ExtendedTrustManager , sni );
611+ ChannelHandler cth = new ClientTlsHandler (gnh , sslContext ,
612+ sni != null ? sni : grpcHandler . getAuthority () ,
613+ this . executor , negotiationLogger , handshakeCompleteRunnable , x509ExtendedTrustManager );
614614 return new WaitUntilActiveHandler (cth , negotiationLogger );
615615 }
616616
@@ -635,17 +635,15 @@ static final class ClientTlsHandler extends ProtocolNegotiationHandler {
635635 private Executor executor ;
636636 private final Optional <Runnable > handshakeCompleteRunnable ;
637637 private final X509TrustManager x509ExtendedTrustManager ;
638- private final String sni ;
639638 private SSLEngine sslEngine ;
640639
641- ClientTlsHandler (ChannelHandler next , SslContext sslContext , String authority ,
640+ ClientTlsHandler (ChannelHandler next , SslContext sslContext , String sni ,
642641 Executor executor , ChannelLogger negotiationLogger ,
643642 Optional <Runnable > handshakeCompleteRunnable ,
644- X509TrustManager x509ExtendedTrustManager , String sni ) {
643+ X509TrustManager x509ExtendedTrustManager ) {
645644 super (next , negotiationLogger );
646645 this .sslContext = Preconditions .checkNotNull (sslContext , "sslContext" );
647- this .sni = sni ;
648- HostPort hostPort = parseAuthority (authority );
646+ HostPort hostPort = parseAuthority (sni );
649647 this .host = hostPort .host ;
650648 this .port = hostPort .port ;
651649 this .executor = executor ;
@@ -656,7 +654,7 @@ static final class ClientTlsHandler extends ProtocolNegotiationHandler {
656654 @ Override
657655 @ IgnoreJRERequirement
658656 protected void handlerAdded0 (ChannelHandlerContext ctx ) {
659- sslEngine = sslContext .newEngine (ctx .alloc (), sni != null ? sni : host , port );
657+ sslEngine = sslContext .newEngine (ctx .alloc (), host , port );
660658 SSLParameters sslParams = sslEngine .getSSLParameters ();
661659 sslParams .setEndpointIdentificationAlgorithm ("HTTPS" );
662660 sslEngine .setSSLParameters (sslParams );
@@ -749,11 +747,9 @@ static HostPort parseAuthority(String authority) {
749747
750748 /**
751749 * Returns a {@link ProtocolNegotiator} that ensures the pipeline is set up so that TLS will
752- * be negotiated, the {@code handler} is added and writes to the {@link Channel}
750+ * be negotiated, the {@code handler} is added and writes to the {@link io.netty.channel. Channel}
753751 * may happen immediately, even before the TLS Handshake is complete.
754- *
755752 * @param executorPool a dedicated {@link Executor} pool for time-consuming TLS tasks
756- * @param sni the SNI value to use in the Tls handshake
757753 */
758754 public static ProtocolNegotiator tls (SslContext sslContext ,
759755 ObjectPool <? extends Executor > executorPool , Optional <Runnable > handshakeCompleteRunnable ,
@@ -764,16 +760,16 @@ public static ProtocolNegotiator tls(SslContext sslContext,
764760
765761 /**
766762 * Returns a {@link ProtocolNegotiator} that ensures the pipeline is set up so that TLS will
767- * be negotiated, the {@code handler} is added and writes to the {@link Channel}
763+ * be negotiated, the {@code handler} is added and writes to the {@link io.netty.channel. Channel}
768764 * may happen immediately, even before the TLS Handshake is complete.
769765 */
770766 public static ProtocolNegotiator tls (SslContext sslContext ,
771- X509TrustManager x509ExtendedTrustManager ) {
767+ X509TrustManager x509ExtendedTrustManager ) {
772768 return tls (sslContext , null , Optional .absent (), x509ExtendedTrustManager , null );
773769 }
774770
775771 public static ProtocolNegotiator .ClientFactory tlsClientFactory (SslContext sslContext ,
776- X509TrustManager x509ExtendedTrustManager ) {
772+ X509TrustManager x509ExtendedTrustManager ) {
777773 return new TlsProtocolNegotiatorClientFactory (sslContext , x509ExtendedTrustManager );
778774 }
779775
@@ -911,8 +907,8 @@ public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exc
911907 }
912908
913909 /**
914- * Returns a {@link ChannelHandler} that ensures that the {@code handler} is
915- * added to the pipeline writes to the {@link Channel} may happen immediately,
910+ * Returns a {@link io.netty.channel. ChannelHandler} that ensures that the {@code handler} is
911+ * added to the pipeline writes to the {@link io.netty.channel. Channel} may happen immediately,
916912 * even before it is active.
917913 */
918914 public static ProtocolNegotiator plaintext () {
@@ -941,7 +937,7 @@ private static RuntimeException unavailableException(String msg) {
941937
942938 @ VisibleForTesting
943939 static void logSslEngineDetails (Level level , ChannelHandlerContext ctx , String msg ,
944- @ Nullable Throwable t ) {
940+ @ Nullable Throwable t ) {
945941 if (!log .isLoggable (level )) {
946942 return ;
947943 }
@@ -1067,8 +1063,8 @@ static final class PlaintextHandler extends ProtocolNegotiationHandler {
10671063 protected void protocolNegotiationEventTriggered (ChannelHandlerContext ctx ) {
10681064 ProtocolNegotiationEvent existingPne = getProtocolNegotiationEvent ();
10691065 Attributes attrs = existingPne .getAttributes ().toBuilder ()
1070- .set (GrpcAttributes .ATTR_AUTHORITY_VERIFIER , (authority ) -> Status .OK )
1071- .build ();
1066+ .set (GrpcAttributes .ATTR_AUTHORITY_VERIFIER , (authority ) -> Status .OK )
1067+ .build ();
10721068 replaceProtocolNegotiationEvent (existingPne .withAttributes (attrs ));
10731069 fireProtocolNegotiationEvent (ctx );
10741070 }
@@ -1130,7 +1126,7 @@ static class ProtocolNegotiationHandler extends ChannelDuplexHandler {
11301126 private final ChannelLogger negotiationLogger ;
11311127
11321128 protected ProtocolNegotiationHandler (ChannelHandler next , String negotiatorName ,
1133- ChannelLogger negotiationLogger ) {
1129+ ChannelLogger negotiationLogger ) {
11341130 this .next = Preconditions .checkNotNull (next , "next" );
11351131 this .negotiatorName = negotiatorName ;
11361132 this .negotiationLogger = Preconditions .checkNotNull (negotiationLogger , "negotiationLogger" );
@@ -1228,4 +1224,4 @@ public String getPeerHost() {
12281224 return peerHost ;
12291225 }
12301226 }
1231- }
1227+ }
0 commit comments