Skip to content

Commit 4076998

Browse files
committed
Save changes.
1 parent 9746bb4 commit 4076998

File tree

3 files changed

+64
-3
lines changed

3 files changed

+64
-3
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ public final void updateCertificate(PrivateKey key, List<X509Certificate> certCh
138138

139139
@Override
140140
public final void updateTrustedRoots(List<X509Certificate> trustedRoots) {
141+
if (isUsingSystemRootCerts) {
142+
return;
143+
}
141144
savedTrustedRoots = trustedRoots;
142145
updateSslContextWhenReady();
143146
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,6 @@ private static CommonTlsContext.Builder addCertificateValidationContext(
229229
String rootInstanceName,
230230
String rootCertName,
231231
CertificateValidationContext staticCertValidationContext) {
232-
if (staticCertValidationContext == null && rootInstanceName == null) {
233-
return builder;
234-
}
235232
CertificateValidationContext.Builder contextBuilder;
236233
if (staticCertValidationContext == null) {
237234
contextBuilder = CertificateValidationContext.newBuilder();
@@ -243,6 +240,10 @@ private static CommonTlsContext.Builder addCertificateValidationContext(
243240
.setInstanceName(rootInstanceName)
244241
.setCertificateName(rootCertName));
245242
builder.setValidationContext(contextBuilder.build());
243+
} else {
244+
builder.setValidationContext(contextBuilder.setSystemRootCerts(
245+
CertificateValidationContext.SystemRootCerts.getDefaultInstance())
246+
.build());
246247
}
247248
return builder.setCombinedValidationContext(CombinedCertificateValidationContext.newBuilder()
248249
.setDefaultValidationContext(contextBuilder));

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

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,63 @@ public void testProviderForClient_mtls() throws Exception {
173173
assertThat(testCallback1.updatedSslContext).isNotSameInstanceAs(testCallback.updatedSslContext);
174174
}
175175

176+
@Test
177+
public void testProviderForClient_systemRootCerts() throws Exception {
178+
final CertificateProvider.DistributorWatcher[] watcherCaptor =
179+
new CertificateProvider.DistributorWatcher[1];
180+
TestCertificateProvider.createAndRegisterProviderProvider(
181+
certificateProviderRegistry, watcherCaptor, "testca", 0);
182+
CertProviderClientSslContextProvider provider =
183+
getSslContextProvider(
184+
"gcp_id",
185+
null,
186+
CommonBootstrapperTestUtils.getTestBootstrapInfo(),
187+
/* alpnProtocols= */ null,
188+
/* staticCertValidationContext= */ null);
189+
190+
assertThat(provider.savedKey).isNull();
191+
assertThat(provider.savedCertChain).isNull();
192+
assertThat(provider.savedTrustedRoots).isNull();
193+
assertThat(provider.getSslContext()).isNull();
194+
195+
// now generate cert update, updates SslContext
196+
watcherCaptor[0].updateCertificate(
197+
CommonCertProviderTestUtils.getPrivateKey(CLIENT_KEY_FILE),
198+
ImmutableList.of(getCertFromResourceName(CLIENT_PEM_FILE)));
199+
assertThat(provider.savedKey).isNull();
200+
assertThat(provider.savedCertChain).isNull();
201+
assertThat(provider.getSslContext()).isNotNull();
202+
203+
TestCallback testCallback =
204+
CommonTlsContextTestsUtil.getValueThruCallback(provider);
205+
206+
doChecksOnSslContext(false, testCallback.updatedSslContext, /* expectedApnProtos= */ null);
207+
TestCallback testCallback1 =
208+
CommonTlsContextTestsUtil.getValueThruCallback(provider);
209+
assertThat(testCallback1.updatedSslContext).isSameInstanceAs(testCallback.updatedSslContext);
210+
211+
// just do root cert update: trusted roots is not updated (because of system root certs config)
212+
// and sslContext should still be the same
213+
watcherCaptor[0].updateTrustedRoots(
214+
ImmutableList.of(getCertFromResourceName(SERVER_0_PEM_FILE)));
215+
assertThat(provider.savedKey).isNull();
216+
assertThat(provider.savedCertChain).isNull();
217+
assertThat(provider.savedTrustedRoots).isNull();
218+
testCallback1 = CommonTlsContextTestsUtil.getValueThruCallback(provider);
219+
assertThat(testCallback1.updatedSslContext).isSameInstanceAs(testCallback.updatedSslContext);
220+
221+
// now update id cert: sslContext should be updated i.e.different from the previous one
222+
watcherCaptor[0].updateCertificate(
223+
CommonCertProviderTestUtils.getPrivateKey(SERVER_1_KEY_FILE),
224+
ImmutableList.of(getCertFromResourceName(SERVER_1_PEM_FILE)));
225+
assertThat(provider.savedKey).isNull();
226+
assertThat(provider.savedCertChain).isNull();
227+
assertThat(provider.savedTrustedRoots).isNull();
228+
assertThat(provider.getSslContext()).isNotNull();
229+
testCallback1 = CommonTlsContextTestsUtil.getValueThruCallback(provider);
230+
assertThat(testCallback1.updatedSslContext).isNotSameInstanceAs(testCallback.updatedSslContext);
231+
}
232+
176233
@Test
177234
public void testProviderForClient_mtls_newXds() throws Exception {
178235
final CertificateProvider.DistributorWatcher[] watcherCaptor =

0 commit comments

Comments
 (0)