@@ -131,7 +131,7 @@ public static FromChannelCredentialsResult from(ChannelCredentials creds) {
131131 trustManagers = tlsCreds .getTrustManagers ();
132132 } else if (tlsCreds .getRootCertificates () != null ) {
133133 trustManagers = Arrays .asList (CertificateUtils .createTrustManager (
134- new ByteArrayInputStream (tlsCreds .getRootCertificates ())));
134+ new ByteArrayInputStream (tlsCreds .getRootCertificates ())));
135135 } else { // else use system default
136136 TrustManagerFactory tmf = TrustManagerFactory .getInstance (
137137 TrustManagerFactory .getDefaultAlgorithm ());
@@ -142,7 +142,7 @@ public static FromChannelCredentialsResult from(ChannelCredentials creds) {
142142 TrustManager x509ExtendedTrustManager =
143143 CertificateUtils .getX509ExtendedTrustManager (trustManagers );
144144 return FromChannelCredentialsResult .negotiator (tlsClientFactory (builder .build (),
145- (X509TrustManager ) x509ExtendedTrustManager ));
145+ (X509TrustManager ) x509ExtendedTrustManager ));
146146 } catch (SSLException | GeneralSecurityException ex ) {
147147 log .log (Level .FINE , "Exception building SslContext" , ex );
148148 return FromChannelCredentialsResult .error (
@@ -458,7 +458,7 @@ public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exc
458458 }
459459 SslHandler sslHandler = ctx .pipeline ().get (SslHandler .class );
460460 if (!sslContext .applicationProtocolNegotiator ().protocols ().contains (
461- sslHandler .applicationProtocol ())) {
461+ sslHandler .applicationProtocol ())) {
462462 logSslEngineDetails (Level .FINE , ctx , "TLS negotiation failed for new client." , null );
463463 ctx .fireExceptionCaught (unavailableException (
464464 "Failed protocol negotiation: Unable to find compatible protocol" ));
@@ -618,18 +618,21 @@ static final class ClientTlsHandler extends ProtocolNegotiationHandler {
618618 private final int port ;
619619 private Executor executor ;
620620 private final Optional <Runnable > handshakeCompleteRunnable ;
621- private final X509TrustManager x509ExtendedTrustManager ;
621+ private final X509TrustManager x509TrustManager ;
622622 private SSLEngine sslEngine ;
623623
624- ClientTlsHandler (ChannelHandler next , SslContext sslContext , String sniHostPort ,
624+ ClientTlsHandler (ChannelHandler next , SslContext sslContext , String authority ,
625625 Executor executor , ChannelLogger negotiationLogger ,
626626 Optional <Runnable > handshakeCompleteRunnable ,
627627 ClientTlsProtocolNegotiator clientTlsProtocolNegotiator ,
628- X509TrustManager x509ExtendedTrustManager ) {
628+ X509TrustManager x509TrustManager ) {
629629 super (next , negotiationLogger );
630630 this .sslContext = Preconditions .checkNotNull (sslContext , "sslContext" );
631- if (!Strings .isNullOrEmpty (sniHostPort )) {
632- HostPort hostPort = parseAuthority (sniHostPort );
631+ // TODO: For empty authority and fallback flag
632+ // GRPC_USE_CHANNEL_AUTHORITY_IF_NO_SNI_APPLICABLE present, we should parse authority
633+ // but prevent it from being used for SAN validation in the TrustManager.
634+ if (authority != null && !authority .isEmpty ()) {
635+ HostPort hostPort = parseAuthority (authority );
633636 this .host = hostPort .host ;
634637 this .port = hostPort .port ;
635638 } else {
@@ -638,7 +641,7 @@ static final class ClientTlsHandler extends ProtocolNegotiationHandler {
638641 }
639642 this .executor = executor ;
640643 this .handshakeCompleteRunnable = handshakeCompleteRunnable ;
641- this .x509ExtendedTrustManager = x509ExtendedTrustManager ;
644+ this .x509TrustManager = x509TrustManager ;
642645 }
643646
644647 @ Override
@@ -706,7 +709,7 @@ private void propagateTlsComplete(ChannelHandlerContext ctx, SSLSession session)
706709 .set (GrpcAttributes .ATTR_SECURITY_LEVEL , SecurityLevel .PRIVACY_AND_INTEGRITY )
707710 .set (Grpc .TRANSPORT_ATTR_SSL_SESSION , session )
708711 .set (GrpcAttributes .ATTR_AUTHORITY_VERIFIER , new X509AuthorityVerifier (
709- sslEngine , x509ExtendedTrustManager ))
712+ sslEngine , x509TrustManager ))
710713 .build ();
711714 replaceProtocolNegotiationEvent (existingPne .withAttributes (attrs ).withSecurity (security ));
712715 if (handshakeCompleteRunnable .isPresent ()) {
@@ -1058,8 +1061,8 @@ static final class PlaintextHandler extends ProtocolNegotiationHandler {
10581061 protected void protocolNegotiationEventTriggered (ChannelHandlerContext ctx ) {
10591062 ProtocolNegotiationEvent existingPne = getProtocolNegotiationEvent ();
10601063 Attributes attrs = existingPne .getAttributes ().toBuilder ()
1061- .set (GrpcAttributes .ATTR_AUTHORITY_VERIFIER , (authority ) -> Status .OK )
1062- .build ();
1064+ .set (GrpcAttributes .ATTR_AUTHORITY_VERIFIER , (authority ) -> Status .OK )
1065+ .build ();
10631066 replaceProtocolNegotiationEvent (existingPne .withAttributes (attrs ));
10641067 fireProtocolNegotiationEvent (ctx );
10651068 }
@@ -1219,4 +1222,4 @@ public String getPeerHost() {
12191222 return peerHost ;
12201223 }
12211224 }
1222- }
1225+ }
0 commit comments