Skip to content

Commit 30ffa7b

Browse files
committed
Save changes.
1 parent 5e794bf commit 30ffa7b

File tree

9 files changed

+28
-25
lines changed

9 files changed

+28
-25
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public static ChannelHandler clientTlsHandler(
171171
ChannelHandler next, SslContext sslContext, String authority,
172172
ChannelLogger negotiationLogger) {
173173
return new ClientTlsHandler(next, sslContext, authority, null, negotiationLogger,
174-
Optional.absent(), null, null, sni);
174+
Optional.absent(), null, null);
175175
}
176176

177177
public static class ProtocolNegotiationHandler

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ public ChannelHandler newHandler(GrpcHttp2ConnectionHandler grpcHandler) {
609609
ChannelHandler gnh = new GrpcNegotiationHandler(grpcHandler);
610610
ChannelLogger negotiationLogger = grpcHandler.getNegotiationLogger();
611611
ChannelHandler cth = new ClientTlsHandler(gnh, sslContext, grpcHandler.getAuthority(),
612-
this.executor, negotiationLogger, handshakeCompleteRunnable, this,
612+
this.executor, negotiationLogger, handshakeCompleteRunnable,
613613
x509ExtendedTrustManager, sni);
614614
return new WaitUntilActiveHandler(cth, negotiationLogger);
615615
}
@@ -641,7 +641,6 @@ static final class ClientTlsHandler extends ProtocolNegotiationHandler {
641641
ClientTlsHandler(ChannelHandler next, SslContext sslContext, String authority,
642642
Executor executor, ChannelLogger negotiationLogger,
643643
Optional<Runnable> handshakeCompleteRunnable,
644-
ClientTlsProtocolNegotiator clientTlsProtocolNegotiator,
645644
X509TrustManager x509ExtendedTrustManager, String sni) {
646645
super(next, negotiationLogger);
647646
this.sslContext = Preconditions.checkNotNull(sslContext, "sslContext");
@@ -754,7 +753,7 @@ static HostPort parseAuthority(String authority) {
754753
* may happen immediately, even before the TLS Handshake is complete.
755754
*
756755
* @param executorPool a dedicated {@link Executor} pool for time-consuming TLS tasks
757-
* @param sni
756+
* @param sni the SNI value to use in the Tls handshake
758757
*/
759758
public static ProtocolNegotiator tls(SslContext sslContext,
760759
ObjectPool<? extends Executor> executorPool, Optional<Runnable> handshakeCompleteRunnable,

netty/src/test/java/io/grpc/netty/ProtocolNegotiatorsTest.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ public String applicationProtocol() {
918918

919919
ClientTlsHandler handler = new ClientTlsHandler(grpcHandler, sslContext,
920920
"authority", elg, noopLogger, Optional.absent(),
921-
getClientTlsProtocolNegotiator(), null, sni);
921+
null, null);
922922
pipeline.addLast(handler);
923923
pipeline.replace(SslHandler.class, null, goodSslHandler);
924924
pipeline.fireUserEventTriggered(ProtocolNegotiationEvent.DEFAULT);
@@ -957,7 +957,7 @@ public String applicationProtocol() {
957957

958958
ClientTlsHandler handler = new ClientTlsHandler(grpcHandler, sslContext,
959959
"authority", elg, noopLogger, Optional.absent(),
960-
getClientTlsProtocolNegotiator(), null, sni);
960+
null, null);
961961
pipeline.addLast(handler);
962962
pipeline.replace(SslHandler.class, null, goodSslHandler);
963963
pipeline.fireUserEventTriggered(ProtocolNegotiationEvent.DEFAULT);
@@ -982,7 +982,7 @@ public String applicationProtocol() {
982982

983983
ClientTlsHandler handler = new ClientTlsHandler(grpcHandler, sslContext,
984984
"authority", elg, noopLogger, Optional.absent(),
985-
getClientTlsProtocolNegotiator(), null, sni);
985+
null, null);
986986
pipeline.addLast(handler);
987987

988988
final AtomicReference<Throwable> error = new AtomicReference<>();
@@ -1011,7 +1011,7 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
10111011
public void clientTlsHandler_closeDuringNegotiation() throws Exception {
10121012
ClientTlsHandler handler = new ClientTlsHandler(grpcHandler, sslContext,
10131013
"authority", null, noopLogger, Optional.absent(),
1014-
getClientTlsProtocolNegotiator(), null, sni);
1014+
null, null);
10151015
pipeline.addLast(new WriteBufferingAndExceptionHandler(handler));
10161016
ChannelFuture pendingWrite = channel.writeAndFlush(NettyClientHandler.NOOP_MESSAGE);
10171017

@@ -1023,12 +1023,6 @@ public void clientTlsHandler_closeDuringNegotiation() throws Exception {
10231023
.isEqualTo(Status.Code.UNAVAILABLE);
10241024
}
10251025

1026-
private ClientTlsProtocolNegotiator getClientTlsProtocolNegotiator() throws SSLException {
1027-
return new ClientTlsProtocolNegotiator(GrpcSslContexts.forClient().trustManager(
1028-
TlsTesting.loadCert("ca.pem")).build(),
1029-
null, Optional.absent(), null, sni);
1030-
}
1031-
10321026
@Test
10331027
public void engineLog() {
10341028
ChannelHandler handler = new ServerTlsHandler(grpcHandler, sslContext, null);
@@ -1277,7 +1271,7 @@ public void clientTlsHandler_firesNegotiation() throws Exception {
12771271
}
12781272
FakeGrpcHttp2ConnectionHandler gh = FakeGrpcHttp2ConnectionHandler.newHandler();
12791273
ClientTlsProtocolNegotiator pn = new ClientTlsProtocolNegotiator(clientSslContext,
1280-
null, Optional.absent(), null, sni);
1274+
null, Optional.absent(), null, null);
12811275
WriteBufferingAndExceptionHandler clientWbaeh =
12821276
new WriteBufferingAndExceptionHandler(pn.newHandler(gh));
12831277

xds/src/main/java/io/grpc/xds/ClusterImplLoadBalancer.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
import io.grpc.xds.orca.OrcaPerRequestUtil.OrcaPerRequestReportListener;
6060
import java.util.ArrayList;
6161
import java.util.Collections;
62+
import java.util.HashMap;
6263
import java.util.List;
6364
import java.util.Locale;
6465
import java.util.Map;
@@ -208,6 +209,7 @@ private final class ClusterImplLbHelper extends ForwardingLoadBalancerHelper {
208209
private Map<String, Struct> filterMetadata = ImmutableMap.of();
209210
@Nullable
210211
private final ServerInfo lrsServerInfo;
212+
private final Map<String, SslContextProviderSupplier> sslContextProviderSupplierMap = new HashMap<>();
211213

212214
private ClusterImplLbHelper(AtomicLong inFlights, @Nullable ServerInfo lrsServerInfo) {
213215
this.inFlights = checkNotNull(inFlights, "inFlights");
@@ -294,11 +296,16 @@ private List<EquivalentAddressGroup> withAdditionalAttributes(
294296
Attributes.Builder attrBuilder = eag.getAttributes().toBuilder().set(
295297
XdsAttributes.ATTR_CLUSTER_NAME, cluster);
296298
if (tlsContext != null) {
299+
String addressNameAttr = eag.getAttributes().get(XdsAttributes.ATTR_ADDRESS_NAME);
300+
if (!sslContextProviderSupplierMap.containsKey(addressNameAttr)) {
301+
sslContextProviderSupplierMap.put(addressNameAttr,
302+
new SslContextProviderSupplier(tlsContext,
303+
(TlsContextManager) xdsClient.getSecurityConfig(),
304+
eag.getAttributes().get(XdsAttributes.ATTR_ADDRESS_NAME)));
305+
}
297306
attrBuilder.set(
298307
SecurityProtocolNegotiators.ATTR_SSL_CONTEXT_PROVIDER_SUPPLIER,
299-
new SslContextProviderSupplier(tlsContext,
300-
(TlsContextManager) xdsClient.getSecurityConfig(),
301-
eag.getAttributes().get(XdsAttributes.ATTR_ADDRESS_NAME)));
308+
sslContextProviderSupplierMap.get(addressNameAttr));
302309
}
303310
newAddresses.add(new EquivalentAddressGroup(eag.getAddresses(), attrBuilder.build()));
304311
}

xds/src/main/java/io/grpc/xds/internal/security/ClientSslContextProviderFactory.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@
2020
import io.grpc.xds.client.Bootstrapper.BootstrapInfo;
2121
import io.grpc.xds.internal.security.ReferenceCountingMap.ValueFactory;
2222
import io.grpc.xds.internal.security.certprovider.CertProviderClientSslContextProviderFactory;
23+
import java.util.AbstractMap;
2324

2425
/** Factory to create client-side SslContextProvider from UpstreamTlsContext. */
2526
final class ClientSslContextProviderFactory
26-
implements ValueFactory<UpstreamTlsContext, SslContextProvider> {
27+
implements ValueFactory<AbstractMap.SimpleImmutableEntry<UpstreamTlsContext, String>, SslContextProvider> {
2728

2829
private BootstrapInfo bootstrapInfo;
2930
private final CertProviderClientSslContextProviderFactory
@@ -41,9 +42,9 @@ final class ClientSslContextProviderFactory
4142

4243
/** Creates an SslContextProvider from the given UpstreamTlsContext. */
4344
@Override
44-
public SslContextProvider create(UpstreamTlsContext upstreamTlsContext) {
45+
public SslContextProvider create(AbstractMap.SimpleImmutableEntry<UpstreamTlsContext, String> key) {
4546
return certProviderClientSslContextProviderFactory.getProvider(
46-
upstreamTlsContext,
47+
key.getKey(), key.getValue(),
4748
bootstrapInfo.node().toEnvoyProtoNode(),
4849
bootstrapInfo.certProviders());
4950
}

xds/src/main/java/io/grpc/xds/internal/security/SslContextProvider.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
public abstract class SslContextProvider implements Closeable {
4545

4646
protected final BaseTlsContext tlsContext;
47+
private String sni;
4748

4849
@VisibleForTesting public abstract static class Callback {
4950
private final Executor executor;

xds/src/main/java/io/grpc/xds/internal/security/certprovider/CertProviderClientSslContextProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public final class CertProviderClientSslContextProvider extends CertProviderSslC
3939
CommonTlsContext.CertificateProviderInstance rootCertInstance,
4040
CertificateValidationContext staticCertValidationContext,
4141
UpstreamTlsContext upstreamTlsContext,
42-
CertificateProviderStore certificateProviderStore) {
42+
String sni, CertificateProviderStore certificateProviderStore) {
4343
super(
4444
node,
4545
certProviders,

xds/src/main/java/io/grpc/xds/internal/security/certprovider/CertProviderClientSslContextProviderFactory.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static CertProviderClientSslContextProviderFactory getInstance() {
5555
*/
5656
public SslContextProvider getProvider(
5757
UpstreamTlsContext upstreamTlsContext,
58-
Node node,
58+
String sni, Node node,
5959
@Nullable Map<String, CertificateProviderInfo> certProviders) {
6060
checkNotNull(upstreamTlsContext, "upstreamTlsContext");
6161
CommonTlsContext commonTlsContext = upstreamTlsContext.getCommonTlsContext();
@@ -74,6 +74,7 @@ public SslContextProvider getProvider(
7474
rootCertInstance,
7575
staticCertValidationContext,
7676
upstreamTlsContext,
77+
sni,
7778
certificateProviderStore);
7879
}
7980
throw new UnsupportedOperationException("Unsupported configurations in UpstreamTlsContext!");

xds/src/test/java/io/grpc/xds/internal/security/certprovider/CertProviderClientSslContextProviderTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ private CertProviderClientSslContextProvider getSslContextProvider(
8484
return (CertProviderClientSslContextProvider)
8585
certProviderClientSslContextProviderFactory.getProvider(
8686
upstreamTlsContext,
87-
bootstrapInfo.node().toEnvoyProtoNode(),
87+
key.getValue(), bootstrapInfo.node().toEnvoyProtoNode(),
8888
bootstrapInfo.certProviders());
8989
}
9090

@@ -106,7 +106,7 @@ private CertProviderClientSslContextProvider getNewSslContextProvider(
106106
return (CertProviderClientSslContextProvider)
107107
certProviderClientSslContextProviderFactory.getProvider(
108108
upstreamTlsContext,
109-
bootstrapInfo.node().toEnvoyProtoNode(),
109+
key.getValue(), bootstrapInfo.node().toEnvoyProtoNode(),
110110
bootstrapInfo.certProviders());
111111
}
112112

0 commit comments

Comments
 (0)