Skip to content

Commit 7941abc

Browse files
committed
Save sslEngine and use it later after the handshake is complete, to set the attribute for the hostname verifier.
1 parent 15c8161 commit 7941abc

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

examples/example-tls/build.gradle

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ application {
7171
applicationDistribution.into('bin') {
7272
from(helloWorldTlsServer)
7373
from(helloWorldTlsClient)
74-
filePermissions {
75-
unix(0755)
76-
}
74+
fileMode = 0755
7775
}
7876
}

netty/src/main/java/io/grpc/netty/ProtocolNegotiators.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)