Skip to content

Commit c19a24f

Browse files
committed
Trust manager not needed on server side when invoking SslProvider.Callback.
1 parent b828098 commit c19a24f

File tree

6 files changed

+26
-20
lines changed

6 files changed

+26
-20
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,8 @@ private class RequestLimitingSubchannelPicker extends SubchannelPicker {
377377
private final Map<String, Struct> filterMetadata;
378378

379379
private RequestLimitingSubchannelPicker(SubchannelPicker delegate,
380-
List<DropOverload> dropPolicies, long maxConcurrentRequests,
380+
List<DropOverload> dropPolicies,
381+
long maxConcurrentRequests,
381382
Map<String, Struct> filterMetadata) {
382383
this.delegate = delegate;
383384
this.dropPolicies = dropPolicies;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ protected final void updateSslContext() {
9999
}
100100

101101
protected final void callPerformCallback(
102-
Callback callback, final AbstractMap.SimpleImmutableEntry<SslContext, TrustManager> sslContextAndTmCopy) {
102+
Callback callback,
103+
final AbstractMap.SimpleImmutableEntry<SslContext, TrustManager> sslContextAndTmCopy) {
103104
performCallback(
104105
new SslContextGetter() {
105106
@Override

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ public synchronized void updateSslContext(final SslContextProvider.Callback call
7272
new SslContextProvider.Callback(callback.getExecutor()) {
7373

7474
@Override
75-
public void updateSslContextAndExtendedX509TrustManager(AbstractMap.SimpleImmutableEntry<SslContext, TrustManager> sslContextAndTm) {
75+
public void updateSslContextAndExtendedX509TrustManager(
76+
AbstractMap.SimpleImmutableEntry<SslContext, TrustManager> sslContextAndTm) {
7677
callback.updateSslContextAndExtendedX509TrustManager(sslContextAndTm);
7778
releaseSslContextProvider(toRelease, sni);
7879
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,8 @@ protected final AbstractMap.SimpleImmutableEntry<SslContextBuilder, TrustManager
7575
}
7676
setClientAuthValues(sslContextBuilder, trustManagerFactory);
7777
sslContextBuilder = GrpcSslContexts.configure(sslContextBuilder);
78-
return new AbstractMap.SimpleImmutableEntry(sslContextBuilder,
79-
CertificateUtils.getX509ExtendedTrustManager(
80-
Arrays.asList(trustManagerFactory.getTrustManagers())));
78+
// TrustManager in the below return value is not used on the server side, so setting it to null
79+
return new AbstractMap.SimpleImmutableEntry(sslContextBuilder, null);
8180
}
8281

8382
}

xds/src/test/java/io/grpc/xds/internal/security/CommonTlsContextTestsUtil.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -361,14 +361,15 @@ private static CommonTlsContext.Builder addNewCertificateValidationContext(
361361
}
362362

363363
/** Perform some simple checks on sslContext. */
364-
public static void doChecksOnSslContext(boolean server, AbstractMap.SimpleImmutableEntry<SslContext, TrustManager> sslContext,
365-
List<String> expectedApnProtos) {
364+
public static void doChecksOnSslContext(boolean server,
365+
AbstractMap.SimpleImmutableEntry<SslContext, TrustManager> sslContextAndTm,
366+
List<String> expectedApnProtos) {
366367
if (server) {
367-
assertThat(sslContext.getKey().isServer()).isTrue();
368+
assertThat(sslContextAndTm.getKey().isServer()).isTrue();
368369
} else {
369-
assertThat(sslContext.getKey().isClient()).isTrue();
370+
assertThat(sslContextAndTm.getKey().isClient()).isTrue();
370371
}
371-
List<String> apnProtos = sslContext.getKey().applicationProtocolNegotiator().protocols();
372+
List<String> apnProtos = sslContextAndTm.getKey().applicationProtocolNegotiator().protocols();
372373
assertThat(apnProtos).isNotNull();
373374
if (expectedApnProtos != null) {
374375
assertThat(apnProtos).isEqualTo(expectedApnProtos);

xds/src/test/java/io/grpc/xds/internal/security/SecurityProtocolNegotiatorsTest.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,9 @@ public void clientSecurityHandler_addLast()
203203
sslContextProviderSupplier
204204
.updateSslContext(new SslContextProvider.Callback(MoreExecutors.directExecutor()) {
205205
@Override
206-
public void updateSslContextAndExtendedX509TrustManager(AbstractMap.SimpleImmutableEntry<SslContext, TrustManager> sslContext) {
207-
future.set(sslContext);
206+
public void updateSslContextAndExtendedX509TrustManager(
207+
AbstractMap.SimpleImmutableEntry<SslContext, TrustManager> sslContextAndTm) {
208+
future.set(sslContextAndTm);
208209
}
209210

210211
@Override
@@ -215,7 +216,7 @@ protected void onException(Throwable throwable) {
215216
assertThat(executor.runDueTasks()).isEqualTo(1);
216217
channel.runPendingTasks();
217218
Object fromFuture = future.get(2, TimeUnit.SECONDS);
218-
assertThat(fromFuture).isInstanceOf(SslContext.class);
219+
assertThat(fromFuture).isInstanceOf(AbstractMap.SimpleImmutableEntry.class);
219220
channel.runPendingTasks();
220221
channelHandlerCtx = pipeline.context(clientSecurityHandler);
221222
assertThat(channelHandlerCtx).isNull();
@@ -391,8 +392,9 @@ public SocketAddress remoteAddress() {
391392
sslContextProviderSupplier
392393
.updateSslContext(new SslContextProvider.Callback(MoreExecutors.directExecutor()) {
393394
@Override
394-
public void updateSslContextAndExtendedX509TrustManager(AbstractMap.SimpleImmutableEntry<SslContext, TrustManager> sslContext) {
395-
future.set(sslContext);
395+
public void updateSslContextAndExtendedX509TrustManager(
396+
AbstractMap.SimpleImmutableEntry<SslContext, TrustManager> sslContextAndTm) {
397+
future.set(sslContextAndTm);
396398
}
397399

398400
@Override
@@ -403,7 +405,7 @@ protected void onException(Throwable throwable) {
403405
channel.runPendingTasks(); // need this for tasks to execute on eventLoop
404406
assertThat(executor.runDueTasks()).isEqualTo(1);
405407
Object fromFuture = future.get(2, TimeUnit.SECONDS);
406-
assertThat(fromFuture).isInstanceOf(SslContext.class);
408+
assertThat(fromFuture).isInstanceOf(AbstractMap.SimpleImmutableEntry.class);
407409
channel.runPendingTasks();
408410
channelHandlerCtx = pipeline.context(SecurityProtocolNegotiators.ServerSecurityHandler.class);
409411
assertThat(channelHandlerCtx).isNull();
@@ -529,8 +531,9 @@ public void clientSecurityProtocolNegotiatorNewHandler_fireProtocolNegotiationEv
529531
sslContextProviderSupplier
530532
.updateSslContext(new SslContextProvider.Callback(MoreExecutors.directExecutor()) {
531533
@Override
532-
public void updateSslContextAndExtendedX509TrustManager(AbstractMap.SimpleImmutableEntry<SslContext, TrustManager> sslContext) {
533-
future.set(sslContext);
534+
public void updateSslContextAndExtendedX509TrustManager(
535+
AbstractMap.SimpleImmutableEntry<SslContext, TrustManager> sslContextAndTm) {
536+
future.set(sslContextAndTm);
534537
}
535538

536539
@Override
@@ -541,7 +544,7 @@ protected void onException(Throwable throwable) {
541544
executor.runDueTasks();
542545
channel.runPendingTasks(); // need this for tasks to execute on eventLoop
543546
Object fromFuture = future.get(5, TimeUnit.SECONDS);
544-
assertThat(fromFuture).isInstanceOf(SslContext.class);
547+
assertThat(fromFuture).isInstanceOf(AbstractMap.SimpleImmutableEntry.class);
545548
channel.runPendingTasks();
546549
channelHandlerCtx = pipeline.context(clientSecurityHandler);
547550
assertThat(channelHandlerCtx).isNull();

0 commit comments

Comments
 (0)