Skip to content

Commit 011a9ea

Browse files
committed
Allow trustedRootCerts to be present in static CertificateValidationContext when SystemRootCerts is also there.
1 parent 2985cc3 commit 011a9ea

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

xds/src/main/java/io/grpc/xds/internal/security/trust/XdsTrustManagerFactory.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ private XdsTrustManagerFactory(
8181
throws CertStoreException {
8282
if (validationContextIsStatic) {
8383
checkArgument(
84-
certificateValidationContext == null || !certificateValidationContext.hasTrustedCa(),
84+
certificateValidationContext == null || !certificateValidationContext.hasTrustedCa()
85+
|| certificateValidationContext.hasSystemRootCerts(),
8586
"only static certificateValidationContext expected");
8687
}
8788
xdsX509TrustManager = createX509TrustManager(certs, certificateValidationContext, sniForSanMatching);

xds/src/test/java/io/grpc/xds/internal/security/trust/XdsTrustManagerFactoryTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,19 @@ public void constructorRootCert_nonStaticContext_throwsException()
176176
}
177177
}
178178

179+
@Test
180+
public void constructorRootCert_nonStaticContext_systemRootCerts_valid()
181+
throws CertificateException, IOException, CertStoreException {
182+
X509Certificate x509Cert = TestUtils.loadX509Cert(CA_PEM_FILE);
183+
CertificateValidationContext certValidationContext = CertificateValidationContext.newBuilder()
184+
.setTrustedCa(
185+
DataSource.newBuilder().setFilename(TestUtils.loadCert(CA_PEM_FILE).getAbsolutePath()))
186+
.setSystemRootCerts(CertificateValidationContext.SystemRootCerts.getDefaultInstance())
187+
.build();
188+
new XdsTrustManagerFactory(
189+
new X509Certificate[] {x509Cert}, certValidationContext, null);
190+
}
191+
179192
@Test
180193
public void constructorRootCert_checkServerTrusted_throwsException()
181194
throws CertificateException, IOException, CertStoreException {

0 commit comments

Comments
 (0)