@@ -641,6 +641,7 @@ static final class ClientTlsHandler extends ProtocolNegotiationHandler {
641641 private Executor executor ;
642642 private final Optional <Runnable > handshakeCompleteRunnable ;
643643 private final X509TrustManager x509ExtendedTrustManager ;
644+ private SSLEngine sslEngine ;
644645
645646 ClientTlsHandler (ChannelHandler next , SslContext sslContext , String authority ,
646647 Executor executor , ChannelLogger negotiationLogger ,
@@ -661,19 +662,13 @@ static final class ClientTlsHandler extends ProtocolNegotiationHandler {
661662 @ Override
662663 @ IgnoreJRERequirement
663664 protected void handlerAdded0 (ChannelHandlerContext ctx ) {
664- SSLEngine sslEngine = sslContext .newEngine (ctx .alloc (), host , port );
665+ sslEngine = sslContext .newEngine (ctx .alloc (), host , port );
665666 SSLParameters sslParams = sslEngine .getSSLParameters ();
666667 sslParams .setEndpointIdentificationAlgorithm ("HTTPS" );
667668 sslEngine .setSSLParameters (sslParams );
668669 ctx .pipeline ().addBefore (ctx .name (), /* name= */ null , this .executor != null
669670 ? new SslHandler (sslEngine , false , this .executor )
670671 : new SslHandler (sslEngine , false ));
671- ProtocolNegotiationEvent existingPne = getProtocolNegotiationEvent ();
672- Attributes attrs = existingPne .getAttributes ().toBuilder ()
673- .set (GrpcAttributes .ATTR_AUTHORITY_VERIFIER , new X509AuthorityVerifier (
674- sslEngine , x509ExtendedTrustManager ))
675- .build ();
676- replaceProtocolNegotiationEvent (existingPne .withAttributes (attrs ));
677672 }
678673
679674 @ Override
@@ -724,6 +719,8 @@ private void propagateTlsComplete(ChannelHandlerContext ctx, SSLSession session)
724719 Attributes attrs = existingPne .getAttributes ().toBuilder ()
725720 .set (GrpcAttributes .ATTR_SECURITY_LEVEL , SecurityLevel .PRIVACY_AND_INTEGRITY )
726721 .set (Grpc .TRANSPORT_ATTR_SSL_SESSION , session )
722+ .set (GrpcAttributes .ATTR_AUTHORITY_VERIFIER , new X509AuthorityVerifier (
723+ sslEngine , x509ExtendedTrustManager ))
727724 .build ();
728725 replaceProtocolNegotiationEvent (existingPne .withAttributes (attrs ).withSecurity (security ));
729726 if (handshakeCompleteRunnable .isPresent ()) {
0 commit comments