Skip to content

Commit

Permalink
Save sslEngine and use it later after the handshake is complete, to s…
Browse files Browse the repository at this point in the history
…et the attribute for the hostname verifier.
  • Loading branch information
kannanjgithub committed Jan 24, 2025
1 parent 15c8161 commit 7941abc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
4 changes: 1 addition & 3 deletions examples/example-tls/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ application {
applicationDistribution.into('bin') {
from(helloWorldTlsServer)
from(helloWorldTlsClient)
filePermissions {
unix(0755)
}
fileMode = 0755
}
}
11 changes: 4 additions & 7 deletions netty/src/main/java/io/grpc/netty/ProtocolNegotiators.java
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,7 @@ static final class ClientTlsHandler extends ProtocolNegotiationHandler {
private Executor executor;
private final Optional<Runnable> handshakeCompleteRunnable;
private final X509TrustManager x509ExtendedTrustManager;
private SSLEngine sslEngine;

ClientTlsHandler(ChannelHandler next, SslContext sslContext, String authority,
Executor executor, ChannelLogger negotiationLogger,
Expand All @@ -661,19 +662,13 @@ static final class ClientTlsHandler extends ProtocolNegotiationHandler {
@Override
@IgnoreJRERequirement
protected void handlerAdded0(ChannelHandlerContext ctx) {
SSLEngine sslEngine = sslContext.newEngine(ctx.alloc(), host, port);
sslEngine = sslContext.newEngine(ctx.alloc(), host, port);
SSLParameters sslParams = sslEngine.getSSLParameters();
sslParams.setEndpointIdentificationAlgorithm("HTTPS");
sslEngine.setSSLParameters(sslParams);
ctx.pipeline().addBefore(ctx.name(), /* name= */ null, this.executor != null
? new SslHandler(sslEngine, false, this.executor)
: new SslHandler(sslEngine, false));
ProtocolNegotiationEvent existingPne = getProtocolNegotiationEvent();
Attributes attrs = existingPne.getAttributes().toBuilder()
.set(GrpcAttributes.ATTR_AUTHORITY_VERIFIER, new X509AuthorityVerifier(
sslEngine, x509ExtendedTrustManager))
.build();
replaceProtocolNegotiationEvent(existingPne.withAttributes(attrs));
}

@Override
Expand Down Expand Up @@ -724,6 +719,8 @@ private void propagateTlsComplete(ChannelHandlerContext ctx, SSLSession session)
Attributes attrs = existingPne.getAttributes().toBuilder()
.set(GrpcAttributes.ATTR_SECURITY_LEVEL, SecurityLevel.PRIVACY_AND_INTEGRITY)
.set(Grpc.TRANSPORT_ATTR_SSL_SESSION, session)
.set(GrpcAttributes.ATTR_AUTHORITY_VERIFIER, new X509AuthorityVerifier(
sslEngine, x509ExtendedTrustManager))
.build();
replaceProtocolNegotiationEvent(existingPne.withAttributes(attrs).withSecurity(security));
if (handshakeCompleteRunnable.isPresent()) {
Expand Down

0 comments on commit 7941abc

Please sign in to comment.