Migrate many usages of TestUtils.loadCert() to the public TlsTesting

TlsTesting.loadCert() is a public API and so should be preferred over
our internal utility. It avoids creating a temp file that has to be
deleted by a shutdown hook. Usages that needed a file were not migrated.
This commit is contained in:
Eric Anderson 2023-05-07 15:26:39 -07:00
parent f229aed538
commit 74b515ecf7
19 changed files with 124 additions and 136 deletions

View File

@ -35,8 +35,8 @@ import io.grpc.TlsChannelCredentials;
import io.grpc.TlsServerCredentials; import io.grpc.TlsServerCredentials;
import io.grpc.TlsServerCredentials.ClientAuth; import io.grpc.TlsServerCredentials.ClientAuth;
import io.grpc.internal.FakeClock; import io.grpc.internal.FakeClock;
import io.grpc.internal.testing.TestUtils;
import io.grpc.stub.StreamObserver; import io.grpc.stub.StreamObserver;
import io.grpc.testing.TlsTesting;
import io.grpc.testing.protobuf.SimpleRequest; import io.grpc.testing.protobuf.SimpleRequest;
import io.grpc.testing.protobuf.SimpleResponse; import io.grpc.testing.protobuf.SimpleResponse;
import io.grpc.testing.protobuf.SimpleServiceGrpc; import io.grpc.testing.protobuf.SimpleServiceGrpc;
@ -343,11 +343,6 @@ public class AuthorizationEnd2EndTest {
@Test @Test
public void staticAuthzAllowsRpcWithPrincipalsFieldOnMtlsAuthenticatedConnectionTest() public void staticAuthzAllowsRpcWithPrincipalsFieldOnMtlsAuthenticatedConnectionTest()
throws Exception { throws Exception {
File caCertFile = TestUtils.loadCert(CA_PEM_FILE);
File serverKey0File = TestUtils.loadCert(SERVER_0_KEY_FILE);
File serverCert0File = TestUtils.loadCert(SERVER_0_PEM_FILE);
File clientKey0File = TestUtils.loadCert(CLIENT_0_KEY_FILE);
File clientCert0File = TestUtils.loadCert(CLIENT_0_PEM_FILE);
String policy = "{" String policy = "{"
+ " \"name\" : \"authz\" ," + " \"name\" : \"authz\" ,"
+ " \"allow_rules\": [" + " \"allow_rules\": ["
@ -361,14 +356,14 @@ public class AuthorizationEnd2EndTest {
+ "}"; + "}";
AuthorizationServerInterceptor interceptor = createStaticAuthorizationInterceptor(policy); AuthorizationServerInterceptor interceptor = createStaticAuthorizationInterceptor(policy);
ServerCredentials serverCredentials = TlsServerCredentials.newBuilder() ServerCredentials serverCredentials = TlsServerCredentials.newBuilder()
.keyManager(serverCert0File, serverKey0File) .keyManager(TlsTesting.loadCert(SERVER_0_PEM_FILE), TlsTesting.loadCert(SERVER_0_KEY_FILE))
.trustManager(caCertFile) .trustManager(TlsTesting.loadCert(CA_PEM_FILE))
.clientAuth(ClientAuth.REQUIRE) .clientAuth(ClientAuth.REQUIRE)
.build(); .build();
initServerWithAuthzInterceptor(interceptor, serverCredentials); initServerWithAuthzInterceptor(interceptor, serverCredentials);
ChannelCredentials channelCredentials = TlsChannelCredentials.newBuilder() ChannelCredentials channelCredentials = TlsChannelCredentials.newBuilder()
.keyManager(clientCert0File, clientKey0File) .keyManager(TlsTesting.loadCert(CLIENT_0_PEM_FILE), TlsTesting.loadCert(CLIENT_0_KEY_FILE))
.trustManager(caCertFile) .trustManager(TlsTesting.loadCert(CA_PEM_FILE))
.build(); .build();
getStub(channelCredentials).unaryRpc(SimpleRequest.getDefaultInstance()); getStub(channelCredentials).unaryRpc(SimpleRequest.getDefaultInstance());
} }
@ -376,9 +371,6 @@ public class AuthorizationEnd2EndTest {
@Test @Test
public void staticAuthzAllowsRpcWithPrincipalsFieldOnTlsAuthenticatedConnectionTest() public void staticAuthzAllowsRpcWithPrincipalsFieldOnTlsAuthenticatedConnectionTest()
throws Exception { throws Exception {
File caCertFile = TestUtils.loadCert(CA_PEM_FILE);
File serverKey0File = TestUtils.loadCert(SERVER_0_KEY_FILE);
File serverCert0File = TestUtils.loadCert(SERVER_0_PEM_FILE);
String policy = "{" String policy = "{"
+ " \"name\" : \"authz\" ," + " \"name\" : \"authz\" ,"
+ " \"allow_rules\": [" + " \"allow_rules\": ["
@ -392,13 +384,13 @@ public class AuthorizationEnd2EndTest {
+ "}"; + "}";
AuthorizationServerInterceptor interceptor = createStaticAuthorizationInterceptor(policy); AuthorizationServerInterceptor interceptor = createStaticAuthorizationInterceptor(policy);
ServerCredentials serverCredentials = TlsServerCredentials.newBuilder() ServerCredentials serverCredentials = TlsServerCredentials.newBuilder()
.keyManager(serverCert0File, serverKey0File) .keyManager(TlsTesting.loadCert(SERVER_0_PEM_FILE), TlsTesting.loadCert(SERVER_0_KEY_FILE))
.trustManager(caCertFile) .trustManager(TlsTesting.loadCert(CA_PEM_FILE))
.clientAuth(ClientAuth.OPTIONAL) .clientAuth(ClientAuth.OPTIONAL)
.build(); .build();
initServerWithAuthzInterceptor(interceptor, serverCredentials); initServerWithAuthzInterceptor(interceptor, serverCredentials);
ChannelCredentials channelCredentials = TlsChannelCredentials.newBuilder() ChannelCredentials channelCredentials = TlsChannelCredentials.newBuilder()
.trustManager(caCertFile) .trustManager(TlsTesting.loadCert(CA_PEM_FILE))
.build(); .build();
getStub(channelCredentials).unaryRpc(SimpleRequest.getDefaultInstance()); getStub(channelCredentials).unaryRpc(SimpleRequest.getDefaultInstance());
} }

View File

@ -36,10 +36,10 @@ import io.grpc.benchmarks.proto.BenchmarkServiceGrpc;
import io.grpc.benchmarks.proto.Control; import io.grpc.benchmarks.proto.Control;
import io.grpc.benchmarks.proto.Stats; import io.grpc.benchmarks.proto.Stats;
import io.grpc.benchmarks.qps.AsyncServer; import io.grpc.benchmarks.qps.AsyncServer;
import io.grpc.internal.testing.TestUtils; import io.grpc.testing.TlsTesting;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.PooledByteBufAllocator; import io.netty.buffer.PooledByteBufAllocator;
import java.io.File; import java.io.InputStream;
import java.lang.management.ManagementFactory; import java.lang.management.ManagementFactory;
import java.util.List; import java.util.List;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
@ -115,8 +115,8 @@ final class LoadServer {
} }
} }
if (config.hasSecurityParams()) { if (config.hasSecurityParams()) {
File cert = TestUtils.loadCert("server1.pem"); InputStream cert = TlsTesting.loadCert("server1.pem");
File key = TestUtils.loadCert("server1.key"); InputStream key = TlsTesting.loadCert("server1.key");
serverBuilder.useTransportSecurity(cert, key); serverBuilder.useTransportSecurity(cert, key);
} }
benchmarkService = new AsyncServer.BenchmarkServiceImpl(); benchmarkService = new AsyncServer.BenchmarkServiceImpl();

View File

@ -23,18 +23,18 @@ import io.grpc.Status;
import io.grpc.benchmarks.Utils; import io.grpc.benchmarks.Utils;
import io.grpc.benchmarks.proto.BenchmarkServiceGrpc; import io.grpc.benchmarks.proto.BenchmarkServiceGrpc;
import io.grpc.benchmarks.proto.Messages; import io.grpc.benchmarks.proto.Messages;
import io.grpc.internal.testing.TestUtils;
import io.grpc.netty.NettyServerBuilder; import io.grpc.netty.NettyServerBuilder;
import io.grpc.stub.ServerCallStreamObserver; import io.grpc.stub.ServerCallStreamObserver;
import io.grpc.stub.StreamObserver; import io.grpc.stub.StreamObserver;
import io.grpc.stub.StreamObservers; import io.grpc.stub.StreamObservers;
import io.grpc.testing.TlsTesting;
import io.netty.channel.EventLoopGroup; import io.netty.channel.EventLoopGroup;
import io.netty.channel.ServerChannel; import io.netty.channel.ServerChannel;
import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.util.concurrent.DefaultThreadFactory; import io.netty.util.concurrent.DefaultThreadFactory;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator; import java.util.Iterator;
import java.util.concurrent.ForkJoinPool; import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinPool.ForkJoinWorkerThreadFactory; import java.util.concurrent.ForkJoinPool.ForkJoinWorkerThreadFactory;
@ -164,8 +164,8 @@ public class AsyncServer {
System.out.println("Using fake CA for TLS certificate.\n" System.out.println("Using fake CA for TLS certificate.\n"
+ "Run the Java client with --tls --testca"); + "Run the Java client with --tls --testca");
File cert = TestUtils.loadCert("server1.pem"); InputStream cert = TlsTesting.loadCert("server1.pem");
File key = TestUtils.loadCert("server1.key"); InputStream key = TlsTesting.loadCert("server1.key");
builder.useTransportSecurity(cert, key); builder.useTransportSecurity(cert, key);
} }
if (config.directExecutor) { if (config.directExecutor) {

View File

@ -38,11 +38,11 @@ import io.grpc.Server;
import io.grpc.ServerBuilder; import io.grpc.ServerBuilder;
import io.grpc.Status; import io.grpc.Status;
import io.grpc.StatusException; import io.grpc.StatusException;
import io.grpc.internal.testing.TestUtils;
import io.grpc.netty.GrpcSslContexts; import io.grpc.netty.GrpcSslContexts;
import io.grpc.netty.NegotiationType; import io.grpc.netty.NegotiationType;
import io.grpc.netty.NettyChannelBuilder; import io.grpc.netty.NettyChannelBuilder;
import io.grpc.stub.StreamObserver; import io.grpc.stub.StreamObserver;
import io.grpc.testing.TlsTesting;
import io.netty.handler.ssl.SslContext; import io.netty.handler.ssl.SslContext;
import java.io.IOException; import java.io.IOException;
import java.net.InetAddress; import java.net.InetAddress;
@ -345,7 +345,7 @@ public class StressTestClient {
if (useTestCa) { if (useTestCa) {
try { try {
sslContext = GrpcSslContexts.forClient().trustManager( sslContext = GrpcSslContexts.forClient().trustManager(
TestUtils.loadCert("ca.pem")).build(); TlsTesting.loadCert("ca.pem")).build();
} catch (Exception ex) { } catch (Exception ex) {
throw new RuntimeException(ex); throw new RuntimeException(ex);
} }

View File

@ -39,6 +39,7 @@ import io.grpc.netty.InternalNettyChannelBuilder;
import io.grpc.netty.NettyChannelBuilder; import io.grpc.netty.NettyChannelBuilder;
import io.grpc.okhttp.InternalOkHttpChannelBuilder; import io.grpc.okhttp.InternalOkHttpChannelBuilder;
import io.grpc.okhttp.OkHttpChannelBuilder; import io.grpc.okhttp.OkHttpChannelBuilder;
import io.grpc.testing.TlsTesting;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.nio.charset.Charset; import java.nio.charset.Charset;
@ -537,7 +538,7 @@ public class TestServiceClient {
} else { } else {
try { try {
channelCredentials = TlsChannelCredentials.newBuilder() channelCredentials = TlsChannelCredentials.newBuilder()
.trustManager(TestUtils.loadCert("ca.pem")) .trustManager(TlsTesting.loadCert("ca.pem"))
.build(); .build();
} catch (Exception ex) { } catch (Exception ex) {
throw new RuntimeException(ex); throw new RuntimeException(ex);

View File

@ -28,6 +28,7 @@ import io.grpc.TlsServerCredentials;
import io.grpc.alts.AltsServerCredentials; import io.grpc.alts.AltsServerCredentials;
import io.grpc.internal.testing.TestUtils; import io.grpc.internal.testing.TestUtils;
import io.grpc.services.MetricRecorder; import io.grpc.services.MetricRecorder;
import io.grpc.testing.TlsTesting;
import io.grpc.xds.orca.OrcaMetricReportingServerInterceptor; import io.grpc.xds.orca.OrcaMetricReportingServerInterceptor;
import io.grpc.xds.orca.OrcaServiceImpl; import io.grpc.xds.orca.OrcaServiceImpl;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
@ -151,7 +152,7 @@ public class TestServiceServer {
} }
} else if (useTls) { } else if (useTls) {
serverCreds = TlsServerCredentials.create( serverCreds = TlsServerCredentials.create(
TestUtils.loadCert("server1.pem"), TestUtils.loadCert("server1.key")); TlsTesting.loadCert("server1.pem"), TlsTesting.loadCert("server1.key"));
} else { } else {
serverCreds = InsecureServerCredentials.create(); serverCreds = InsecureServerCredentials.create();
} }

View File

@ -29,10 +29,10 @@ import io.grpc.TlsChannelCredentials;
import io.grpc.TlsServerCredentials; import io.grpc.TlsServerCredentials;
import io.grpc.internal.testing.TestUtils; import io.grpc.internal.testing.TestUtils;
import io.grpc.stub.StreamObserver; import io.grpc.stub.StreamObserver;
import io.grpc.testing.TlsTesting;
import io.grpc.testing.integration.Messages.ResponseParameters; import io.grpc.testing.integration.Messages.ResponseParameters;
import io.grpc.testing.integration.Messages.StreamingOutputCallRequest; import io.grpc.testing.integration.Messages.StreamingOutputCallRequest;
import io.grpc.testing.integration.Messages.StreamingOutputCallResponse; import io.grpc.testing.integration.Messages.StreamingOutputCallResponse;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -188,13 +188,9 @@ public class ConcurrencyTest {
* Creates and starts a new {@link TestServiceImpl} server. * Creates and starts a new {@link TestServiceImpl} server.
*/ */
private Server newServer() throws IOException { private Server newServer() throws IOException {
File serverCertChainFile = TestUtils.loadCert("server1.pem");
File serverPrivateKeyFile = TestUtils.loadCert("server1.key");
File serverTrustedCaCerts = TestUtils.loadCert("ca.pem");
ServerCredentials serverCreds = TlsServerCredentials.newBuilder() ServerCredentials serverCreds = TlsServerCredentials.newBuilder()
.keyManager(serverCertChainFile, serverPrivateKeyFile) .keyManager(TlsTesting.loadCert("server1.pem"), TlsTesting.loadCert("server1.key"))
.trustManager(serverTrustedCaCerts) .trustManager(TlsTesting.loadCert("ca.pem"))
.clientAuth(TlsServerCredentials.ClientAuth.REQUIRE) .clientAuth(TlsServerCredentials.ClientAuth.REQUIRE)
.build(); .build();
@ -205,13 +201,9 @@ public class ConcurrencyTest {
} }
private ManagedChannel newClientChannel() throws IOException { private ManagedChannel newClientChannel() throws IOException {
File clientCertChainFile = TestUtils.loadCert("client.pem");
File clientPrivateKeyFile = TestUtils.loadCert("client.key");
File clientTrustedCaCerts = TestUtils.loadCert("ca.pem");
ChannelCredentials channelCreds = TlsChannelCredentials.newBuilder() ChannelCredentials channelCreds = TlsChannelCredentials.newBuilder()
.keyManager(clientCertChainFile, clientPrivateKeyFile) .keyManager(TlsTesting.loadCert("client.pem"), TlsTesting.loadCert("client.key"))
.trustManager(clientTrustedCaCerts) .trustManager(TlsTesting.loadCert("ca.pem"))
.build(); .build();
return Grpc.newChannelBuilder("localhost:" + server.getPort(), channelCreds) return Grpc.newChannelBuilder("localhost:" + server.getPort(), channelCreds)

View File

@ -26,6 +26,7 @@ import io.grpc.netty.InternalNettyChannelBuilder;
import io.grpc.netty.InternalNettyServerBuilder; import io.grpc.netty.InternalNettyServerBuilder;
import io.grpc.netty.NettyChannelBuilder; import io.grpc.netty.NettyChannelBuilder;
import io.grpc.netty.NettyServerBuilder; import io.grpc.netty.NettyServerBuilder;
import io.grpc.testing.TlsTesting;
import java.io.IOException; import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import org.junit.Test; import org.junit.Test;
@ -43,8 +44,8 @@ public class Http2NettyTest extends AbstractInteropTest {
// Starts the server with HTTPS. // Starts the server with HTTPS.
try { try {
ServerCredentials serverCreds = TlsServerCredentials.newBuilder() ServerCredentials serverCreds = TlsServerCredentials.newBuilder()
.keyManager(TestUtils.loadCert("server1.pem"), TestUtils.loadCert("server1.key")) .keyManager(TlsTesting.loadCert("server1.pem"), TlsTesting.loadCert("server1.key"))
.trustManager(TestUtils.loadCert("ca.pem")) .trustManager(TlsTesting.loadCert("ca.pem"))
.clientAuth(TlsServerCredentials.ClientAuth.REQUIRE) .clientAuth(TlsServerCredentials.ClientAuth.REQUIRE)
.build(); .build();
NettyServerBuilder builder = NettyServerBuilder.forPort(0, serverCreds) NettyServerBuilder builder = NettyServerBuilder.forPort(0, serverCreds)
@ -62,8 +63,8 @@ public class Http2NettyTest extends AbstractInteropTest {
protected NettyChannelBuilder createChannelBuilder() { protected NettyChannelBuilder createChannelBuilder() {
try { try {
ChannelCredentials channelCreds = TlsChannelCredentials.newBuilder() ChannelCredentials channelCreds = TlsChannelCredentials.newBuilder()
.keyManager(TestUtils.loadCert("client.pem"), TestUtils.loadCert("client.key")) .keyManager(TlsTesting.loadCert("client.pem"), TlsTesting.loadCert("client.key"))
.trustManager(TestUtils.loadCert("ca.pem")) .trustManager(TlsTesting.loadCert("ca.pem"))
.build(); .build();
NettyChannelBuilder builder = NettyChannelBuilder NettyChannelBuilder builder = NettyChannelBuilder
.forAddress("localhost", ((InetSocketAddress) getListenAddress()).getPort(), channelCreds) .forAddress("localhost", ((InetSocketAddress) getListenAddress()).getPort(), channelCreds)

View File

@ -37,6 +37,7 @@ import io.grpc.okhttp.InternalOkHttpChannelBuilder;
import io.grpc.okhttp.OkHttpChannelBuilder; import io.grpc.okhttp.OkHttpChannelBuilder;
import io.grpc.okhttp.internal.Platform; import io.grpc.okhttp.internal.Platform;
import io.grpc.stub.StreamObserver; import io.grpc.stub.StreamObserver;
import io.grpc.testing.TlsTesting;
import io.grpc.testing.integration.EmptyProtos.Empty; import io.grpc.testing.integration.EmptyProtos.Empty;
import java.io.IOException; import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
@ -68,7 +69,7 @@ public class Http2OkHttpTest extends AbstractInteropTest {
// Starts the server with HTTPS. // Starts the server with HTTPS.
try { try {
ServerCredentials serverCreds = TlsServerCredentials.create( ServerCredentials serverCreds = TlsServerCredentials.create(
TestUtils.loadCert("server1.pem"), TestUtils.loadCert("server1.key")); TlsTesting.loadCert("server1.pem"), TlsTesting.loadCert("server1.key"));
NettyServerBuilder builder = NettyServerBuilder.forPort(0, serverCreds) NettyServerBuilder builder = NettyServerBuilder.forPort(0, serverCreds)
.flowControlWindow(AbstractInteropTest.TEST_FLOW_CONTROL_WINDOW) .flowControlWindow(AbstractInteropTest.TEST_FLOW_CONTROL_WINDOW)
.maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE); .maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE);
@ -86,7 +87,7 @@ public class Http2OkHttpTest extends AbstractInteropTest {
ChannelCredentials channelCreds; ChannelCredentials channelCreds;
try { try {
channelCreds = TlsChannelCredentials.newBuilder() channelCreds = TlsChannelCredentials.newBuilder()
.trustManager(TestUtils.loadCert("ca.pem")) .trustManager(TlsTesting.loadCert("ca.pem"))
.build(); .build();
} catch (IOException ex) { } catch (IOException ex) {
throw new RuntimeException(ex); throw new RuntimeException(ex);

View File

@ -36,6 +36,7 @@ import io.grpc.okhttp.InternalOkHttpServerBuilder;
import io.grpc.okhttp.OkHttpChannelBuilder; import io.grpc.okhttp.OkHttpChannelBuilder;
import io.grpc.okhttp.OkHttpServerBuilder; import io.grpc.okhttp.OkHttpServerBuilder;
import io.grpc.stub.MetadataUtils; import io.grpc.stub.MetadataUtils;
import io.grpc.testing.TlsTesting;
import java.io.IOException; import java.io.IOException;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
@ -87,7 +88,7 @@ public class Http2Test extends AbstractInteropTest {
ServerCredentials serverCreds; ServerCredentials serverCreds;
try { try {
serverCreds = TlsServerCredentials.create( serverCreds = TlsServerCredentials.create(
TestUtils.loadCert("server1.pem"), TestUtils.loadCert("server1.key")); TlsTesting.loadCert("server1.pem"), TlsTesting.loadCert("server1.key"));
} catch (IOException ex) { } catch (IOException ex) {
throw new RuntimeException(ex); throw new RuntimeException(ex);
} }
@ -115,7 +116,7 @@ public class Http2Test extends AbstractInteropTest {
ChannelCredentials channelCreds; ChannelCredentials channelCreds;
try { try {
channelCreds = TlsChannelCredentials.newBuilder() channelCreds = TlsChannelCredentials.newBuilder()
.trustManager(TestUtils.loadCert("ca.pem")) .trustManager(TlsTesting.loadCert("ca.pem"))
.build(); .build();
} catch (Exception ex) { } catch (Exception ex) {
throw new RuntimeException(ex); throw new RuntimeException(ex);

View File

@ -26,7 +26,6 @@ import io.grpc.ManagedChannel;
import io.grpc.Server; import io.grpc.Server;
import io.grpc.ServerCredentials; import io.grpc.ServerCredentials;
import io.grpc.TlsServerCredentials; import io.grpc.TlsServerCredentials;
import io.grpc.internal.testing.TestUtils;
import io.grpc.netty.shaded.io.grpc.netty.GrpcSslContexts; import io.grpc.netty.shaded.io.grpc.netty.GrpcSslContexts;
import io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder; import io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder;
import io.grpc.netty.shaded.io.grpc.netty.NettyServerBuilder; import io.grpc.netty.shaded.io.grpc.netty.NettyServerBuilder;
@ -34,6 +33,7 @@ import io.grpc.netty.shaded.io.grpc.netty.NettySslContextChannelCredentials;
import io.grpc.netty.shaded.io.netty.handler.ssl.SslContextBuilder; import io.grpc.netty.shaded.io.netty.handler.ssl.SslContextBuilder;
import io.grpc.netty.shaded.io.netty.handler.ssl.SslProvider; import io.grpc.netty.shaded.io.netty.handler.ssl.SslProvider;
import io.grpc.stub.StreamObserver; import io.grpc.stub.StreamObserver;
import io.grpc.testing.TlsTesting;
import io.grpc.testing.protobuf.SimpleRequest; import io.grpc.testing.protobuf.SimpleRequest;
import io.grpc.testing.protobuf.SimpleResponse; import io.grpc.testing.protobuf.SimpleResponse;
import io.grpc.testing.protobuf.SimpleServiceGrpc; import io.grpc.testing.protobuf.SimpleServiceGrpc;
@ -112,13 +112,13 @@ public final class ShadingTest {
@Test @Test
public void tcnative() throws Exception { public void tcnative() throws Exception {
ServerCredentials serverCreds = TlsServerCredentials.create( ServerCredentials serverCreds = TlsServerCredentials.create(
TestUtils.loadCert("server1.pem"), TestUtils.loadCert("server1.key")); TlsTesting.loadCert("server1.pem"), TlsTesting.loadCert("server1.key"));
server = Grpc.newServerBuilderForPort(0, serverCreds) server = Grpc.newServerBuilderForPort(0, serverCreds)
.addService(new SimpleServiceImpl()) .addService(new SimpleServiceImpl())
.build().start(); .build().start();
ChannelCredentials creds = NettySslContextChannelCredentials.create( ChannelCredentials creds = NettySslContextChannelCredentials.create(
GrpcSslContexts.configure(SslContextBuilder.forClient(), SslProvider.OPENSSL) GrpcSslContexts.configure(SslContextBuilder.forClient(), SslProvider.OPENSSL)
.trustManager(TestUtils.loadCert("ca.pem")).build()); .trustManager(TlsTesting.loadCert("ca.pem")).build());
channel = Grpc.newChannelBuilder("localhost:" + server.getPort(), creds) channel = Grpc.newChannelBuilder("localhost:" + server.getPort(), creds)
.overrideAuthority("foo.test.google.fr") .overrideAuthority("foo.test.google.fr")
.build(); .build();

View File

@ -34,6 +34,7 @@ import io.grpc.TlsServerCredentials;
import io.grpc.TlsServerCredentials.ClientAuth; import io.grpc.TlsServerCredentials.ClientAuth;
import io.grpc.internal.testing.TestUtils; import io.grpc.internal.testing.TestUtils;
import io.grpc.stub.StreamObserver; import io.grpc.stub.StreamObserver;
import io.grpc.testing.TlsTesting;
import io.grpc.testing.protobuf.SimpleRequest; import io.grpc.testing.protobuf.SimpleRequest;
import io.grpc.testing.protobuf.SimpleResponse; import io.grpc.testing.protobuf.SimpleResponse;
import io.grpc.testing.protobuf.SimpleServiceGrpc; import io.grpc.testing.protobuf.SimpleServiceGrpc;
@ -98,20 +99,13 @@ public class AdvancedTlsTest {
serverCert0File = TestUtils.loadCert(SERVER_0_PEM_FILE); serverCert0File = TestUtils.loadCert(SERVER_0_PEM_FILE);
clientKey0File = TestUtils.loadCert(CLIENT_0_KEY_FILE); clientKey0File = TestUtils.loadCert(CLIENT_0_KEY_FILE);
clientCert0File = TestUtils.loadCert(CLIENT_0_PEM_FILE); clientCert0File = TestUtils.loadCert(CLIENT_0_PEM_FILE);
caCert = CertificateUtils.getX509Certificates( caCert = CertificateUtils.getX509Certificates(TlsTesting.loadCert(CA_PEM_FILE));
TestUtils.class.getResourceAsStream("/certs/" + CA_PEM_FILE)); serverKey0 = CertificateUtils.getPrivateKey(TlsTesting.loadCert(SERVER_0_KEY_FILE));
serverKey0 = CertificateUtils.getPrivateKey( serverCert0 = CertificateUtils.getX509Certificates(TlsTesting.loadCert(SERVER_0_PEM_FILE));
TestUtils.class.getResourceAsStream("/certs/" + SERVER_0_KEY_FILE)); clientKey0 = CertificateUtils.getPrivateKey(TlsTesting.loadCert(CLIENT_0_KEY_FILE));
serverCert0 = CertificateUtils.getX509Certificates( clientCert0 = CertificateUtils.getX509Certificates(TlsTesting.loadCert(CLIENT_0_PEM_FILE));
TestUtils.class.getResourceAsStream("/certs/" + SERVER_0_PEM_FILE)); serverKeyBad = CertificateUtils.getPrivateKey(TlsTesting.loadCert(SERVER_BAD_KEY_FILE));
clientKey0 = CertificateUtils.getPrivateKey( serverCertBad = CertificateUtils.getX509Certificates(TlsTesting.loadCert(SERVER_BAD_PEM_FILE));
TestUtils.class.getResourceAsStream("/certs/" + CLIENT_0_KEY_FILE));
clientCert0 = CertificateUtils.getX509Certificates(
TestUtils.class.getResourceAsStream("/certs/" + CLIENT_0_PEM_FILE));
serverKeyBad = CertificateUtils.getPrivateKey(
TestUtils.class.getResourceAsStream("/certs/" + SERVER_BAD_KEY_FILE));
serverCertBad = CertificateUtils.getX509Certificates(
TestUtils.class.getResourceAsStream("/certs/" + SERVER_BAD_PEM_FILE));
} }
@After @After

View File

@ -68,6 +68,7 @@ import io.grpc.internal.TransportTracer;
import io.grpc.internal.testing.TestUtils; import io.grpc.internal.testing.TestUtils;
import io.grpc.netty.NettyChannelBuilder.LocalSocketPicker; import io.grpc.netty.NettyChannelBuilder.LocalSocketPicker;
import io.grpc.netty.NettyTestUtil.TrackingObjectPoolForTest; import io.grpc.netty.NettyTestUtil.TrackingObjectPoolForTest;
import io.grpc.testing.TlsTesting;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelConfig; import io.netty.channel.ChannelConfig;
import io.netty.channel.ChannelDuplexHandler; import io.netty.channel.ChannelDuplexHandler;
@ -88,7 +89,6 @@ import io.netty.handler.ssl.SslContext;
import io.netty.handler.ssl.SupportedCipherSuiteFilter; import io.netty.handler.ssl.SupportedCipherSuiteFilter;
import io.netty.util.AsciiString; import io.netty.util.AsciiString;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
@ -297,8 +297,8 @@ public class NettyClientTransportTest {
@Test @Test
public void tlsNegotiationFailurePropagatesToStatus() throws Exception { public void tlsNegotiationFailurePropagatesToStatus() throws Exception {
File serverCert = TestUtils.loadCert("server1.pem"); InputStream serverCert = TlsTesting.loadCert("server1.pem");
File serverKey = TestUtils.loadCert("server1.key"); InputStream serverKey = TlsTesting.loadCert("server1.key");
// Don't trust ca.pem, so that client auth fails // Don't trust ca.pem, so that client auth fails
SslContext sslContext = GrpcSslContexts.forServer(serverCert, serverKey) SslContext sslContext = GrpcSslContexts.forServer(serverCert, serverKey)
.ciphers(TestUtils.preferredTestCiphers(), SupportedCipherSuiteFilter.INSTANCE) .ciphers(TestUtils.preferredTestCiphers(), SupportedCipherSuiteFilter.INSTANCE)
@ -307,9 +307,9 @@ public class NettyClientTransportTest {
negotiator = ProtocolNegotiators.serverTls(sslContext); negotiator = ProtocolNegotiators.serverTls(sslContext);
startServer(); startServer();
File caCert = TestUtils.loadCert("ca.pem"); InputStream caCert = TlsTesting.loadCert("ca.pem");
File clientCert = TestUtils.loadCert("client.pem"); InputStream clientCert = TlsTesting.loadCert("client.pem");
File clientKey = TestUtils.loadCert("client.key"); InputStream clientKey = TlsTesting.loadCert("client.key");
SslContext clientContext = GrpcSslContexts.forClient() SslContext clientContext = GrpcSslContexts.forClient()
.trustManager(caCert) .trustManager(caCert)
.ciphers(TestUtils.preferredTestCiphers(), SupportedCipherSuiteFilter.INSTANCE) .ciphers(TestUtils.preferredTestCiphers(), SupportedCipherSuiteFilter.INSTANCE)
@ -691,8 +691,8 @@ public class NettyClientTransportTest {
assertEquals(false, serverExecutorPool.isInUse()); assertEquals(false, serverExecutorPool.isInUse());
assertEquals(false, clientExecutorPool.isInUse()); assertEquals(false, clientExecutorPool.isInUse());
File serverCert = TestUtils.loadCert("server1.pem"); InputStream serverCert = TlsTesting.loadCert("server1.pem");
File serverKey = TestUtils.loadCert("server1.key"); InputStream serverKey = TlsTesting.loadCert("server1.key");
SslContext sslContext = GrpcSslContexts.forServer(serverCert, serverKey) SslContext sslContext = GrpcSslContexts.forServer(serverCert, serverKey)
.ciphers(TestUtils.preferredTestCiphers(), SupportedCipherSuiteFilter.INSTANCE) .ciphers(TestUtils.preferredTestCiphers(), SupportedCipherSuiteFilter.INSTANCE)
.clientAuth(ClientAuth.NONE) .clientAuth(ClientAuth.NONE)
@ -702,9 +702,9 @@ public class NettyClientTransportTest {
// after starting the server, the Executor in the server pool should be used // after starting the server, the Executor in the server pool should be used
assertEquals(true, serverExecutorPool.isInUse()); assertEquals(true, serverExecutorPool.isInUse());
File caCert = TestUtils.loadCert("ca.pem"); InputStream caCert = TlsTesting.loadCert("ca.pem");
File clientCert = TestUtils.loadCert("client.pem"); InputStream clientCert = TlsTesting.loadCert("client.pem");
File clientKey = TestUtils.loadCert("client.key"); InputStream clientKey = TlsTesting.loadCert("client.key");
SslContext clientContext = GrpcSslContexts.forClient() SslContext clientContext = GrpcSslContexts.forClient()
.trustManager(caCert) .trustManager(caCert)
.ciphers(TestUtils.preferredTestCiphers(), SupportedCipherSuiteFilter.INSTANCE) .ciphers(TestUtils.preferredTestCiphers(), SupportedCipherSuiteFilter.INSTANCE)
@ -732,7 +732,7 @@ public class NettyClientTransportTest {
} }
private ProtocolNegotiator newNegotiator() throws IOException { private ProtocolNegotiator newNegotiator() throws IOException {
File caCert = TestUtils.loadCert("ca.pem"); InputStream caCert = TlsTesting.loadCert("ca.pem");
SslContext clientContext = GrpcSslContexts.forClient().trustManager(caCert) SslContext clientContext = GrpcSslContexts.forClient().trustManager(caCert)
.ciphers(TestUtils.preferredTestCiphers(), SupportedCipherSuiteFilter.INSTANCE).build(); .ciphers(TestUtils.preferredTestCiphers(), SupportedCipherSuiteFilter.INSTANCE).build();
return ProtocolNegotiators.tls(clientContext); return ProtocolNegotiators.tls(clientContext);
@ -802,8 +802,8 @@ public class NettyClientTransportTest {
private static SslContext createSslContext() { private static SslContext createSslContext() {
try { try {
File serverCert = TestUtils.loadCert("server1.pem"); InputStream serverCert = TlsTesting.loadCert("server1.pem");
File key = TestUtils.loadCert("server1.key"); InputStream key = TlsTesting.loadCert("server1.key");
return GrpcSslContexts.forServer(serverCert, key) return GrpcSslContexts.forServer(serverCert, key)
.ciphers(TestUtils.preferredTestCiphers(), SupportedCipherSuiteFilter.INSTANCE).build(); .ciphers(TestUtils.preferredTestCiphers(), SupportedCipherSuiteFilter.INSTANCE).build();
} catch (IOException ex) { } catch (IOException ex) {

View File

@ -67,6 +67,7 @@ import io.grpc.netty.ProtocolNegotiators.ClientTlsProtocolNegotiator;
import io.grpc.netty.ProtocolNegotiators.HostPort; import io.grpc.netty.ProtocolNegotiators.HostPort;
import io.grpc.netty.ProtocolNegotiators.ServerTlsHandler; import io.grpc.netty.ProtocolNegotiators.ServerTlsHandler;
import io.grpc.netty.ProtocolNegotiators.WaitUntilActiveHandler; import io.grpc.netty.ProtocolNegotiators.WaitUntilActiveHandler;
import io.grpc.testing.TlsTesting;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
@ -112,6 +113,7 @@ import io.netty.handler.ssl.SslHandshakeCompletionEvent;
import io.netty.handler.ssl.SupportedCipherSuiteFilter; import io.netty.handler.ssl.SupportedCipherSuiteFilter;
import io.netty.handler.ssl.util.SelfSignedCertificate; import io.netty.handler.ssl.util.SelfSignedCertificate;
import java.io.File; import java.io.File;
import java.io.InputStream;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.SocketAddress; import java.net.SocketAddress;
import java.security.KeyStore; import java.security.KeyStore;
@ -189,8 +191,8 @@ public class ProtocolNegotiatorsTest {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
File serverCert = TestUtils.loadCert("server1.pem"); InputStream serverCert = TlsTesting.loadCert("server1.pem");
File key = TestUtils.loadCert("server1.key"); InputStream key = TlsTesting.loadCert("server1.key");
sslContext = GrpcSslContexts.forServer(serverCert, key) sslContext = GrpcSslContexts.forServer(serverCert, key)
.ciphers(TestUtils.preferredTestCiphers(), SupportedCipherSuiteFilter.INSTANCE).build(); .ciphers(TestUtils.preferredTestCiphers(), SupportedCipherSuiteFilter.INSTANCE).build();
engine = SSLContext.getDefault().createSSLEngine(); engine = SSLContext.getDefault().createSSLEngine();
@ -789,8 +791,8 @@ public class ProtocolNegotiatorsTest {
} }
}; };
File serverCert = TestUtils.loadCert("server1.pem"); InputStream serverCert = TlsTesting.loadCert("server1.pem");
File key = TestUtils.loadCert("server1.key"); InputStream key = TlsTesting.loadCert("server1.key");
List<String> alpnList = Arrays.asList("managed_mtls", "h2"); List<String> alpnList = Arrays.asList("managed_mtls", "h2");
ApplicationProtocolConfig apn = new ApplicationProtocolConfig( ApplicationProtocolConfig apn = new ApplicationProtocolConfig(
ApplicationProtocolConfig.Protocol.ALPN, ApplicationProtocolConfig.Protocol.ALPN,
@ -826,8 +828,8 @@ public class ProtocolNegotiatorsTest {
} }
}; };
File serverCert = TestUtils.loadCert("server1.pem"); InputStream serverCert = TlsTesting.loadCert("server1.pem");
File key = TestUtils.loadCert("server1.key"); InputStream key = TlsTesting.loadCert("server1.key");
List<String> alpnList = Arrays.asList("managed_mtls", "h2"); List<String> alpnList = Arrays.asList("managed_mtls", "h2");
ApplicationProtocolConfig apn = new ApplicationProtocolConfig( ApplicationProtocolConfig apn = new ApplicationProtocolConfig(
ApplicationProtocolConfig.Protocol.ALPN, ApplicationProtocolConfig.Protocol.ALPN,
@ -898,8 +900,8 @@ public class ProtocolNegotiatorsTest {
}; };
DefaultEventLoopGroup elg = new DefaultEventLoopGroup(1); DefaultEventLoopGroup elg = new DefaultEventLoopGroup(1);
File clientCert = TestUtils.loadCert("client.pem"); InputStream clientCert = TlsTesting.loadCert("client.pem");
File key = TestUtils.loadCert("client.key"); InputStream key = TlsTesting.loadCert("client.key");
List<String> alpnList = Arrays.asList("managed_mtls", "h2"); List<String> alpnList = Arrays.asList("managed_mtls", "h2");
ApplicationProtocolConfig apn = new ApplicationProtocolConfig( ApplicationProtocolConfig apn = new ApplicationProtocolConfig(
ApplicationProtocolConfig.Protocol.ALPN, ApplicationProtocolConfig.Protocol.ALPN,

View File

@ -41,6 +41,7 @@ import io.grpc.internal.GrpcUtil;
import io.grpc.internal.SharedResourceHolder; import io.grpc.internal.SharedResourceHolder;
import io.grpc.internal.testing.TestUtils; import io.grpc.internal.testing.TestUtils;
import io.grpc.testing.GrpcCleanupRule; import io.grpc.testing.GrpcCleanupRule;
import io.grpc.testing.TlsTesting;
import io.netty.handler.ssl.util.SelfSignedCertificate; import io.netty.handler.ssl.util.SelfSignedCertificate;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
@ -313,7 +314,7 @@ public class OkHttpChannelBuilderTest {
public void sslSocketFactoryFrom_tls_mtls_passwordUnsupported() throws Exception { public void sslSocketFactoryFrom_tls_mtls_passwordUnsupported() throws Exception {
ChannelCredentials creds = TlsChannelCredentials.newBuilder() ChannelCredentials creds = TlsChannelCredentials.newBuilder()
.keyManager( .keyManager(
TestUtils.loadCert("server1.pem"), TestUtils.loadCert("server1.key"), "password") TlsTesting.loadCert("server1.pem"), TlsTesting.loadCert("server1.key"), "password")
.build(); .build();
OkHttpChannelBuilder.SslSocketFactoryResult result = OkHttpChannelBuilder.SslSocketFactoryResult result =
OkHttpChannelBuilder.sslSocketFactoryFrom(creds); OkHttpChannelBuilder.sslSocketFactoryFrom(creds);

View File

@ -18,6 +18,7 @@ package io.grpc.internal.testing;
import com.google.common.base.Throwables; import com.google.common.base.Throwables;
import io.grpc.internal.ConscryptLoader; import io.grpc.internal.ConscryptLoader;
import io.grpc.testing.TlsTesting;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.BufferedOutputStream; import java.io.BufferedOutputStream;
import java.io.File; import java.io.File;
@ -125,8 +126,7 @@ public class TestUtils {
* @param name name of a file in src/main/resources/certs. * @param name name of a file in src/main/resources/certs.
*/ */
public static File loadCert(String name) throws IOException { public static File loadCert(String name) throws IOException {
InputStream InputStream in = new BufferedInputStream(TlsTesting.loadCert(name));
in = new BufferedInputStream(TestUtils.class.getResourceAsStream("/certs/" + name));
File tmpFile = File.createTempFile(name, ""); File tmpFile = File.createTempFile(name, "");
tmpFile.deleteOnExit(); tmpFile.deleteOnExit();
@ -154,7 +154,7 @@ public class TestUtils {
throws CertificateException, IOException { throws CertificateException, IOException {
CertificateFactory cf = CertificateFactory.getInstance("X.509"); CertificateFactory cf = CertificateFactory.getInstance("X.509");
InputStream in = TestUtils.class.getResourceAsStream("/certs/" + fileName); InputStream in = TlsTesting.loadCert(fileName);
try { try {
return (X509Certificate) cf.generateCertificate(in); return (X509Certificate) cf.generateCertificate(in);
} finally { } finally {

View File

@ -31,6 +31,7 @@ import io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.DownstreamTlsCont
import io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext; import io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext;
import io.envoyproxy.envoy.type.matcher.v3.StringMatcher; import io.envoyproxy.envoy.type.matcher.v3.StringMatcher;
import io.grpc.internal.testing.TestUtils; import io.grpc.internal.testing.TestUtils;
import io.grpc.testing.TlsTesting;
import io.grpc.xds.EnvoyServerProtoData; import io.grpc.xds.EnvoyServerProtoData;
import io.grpc.xds.internal.security.trust.CertificateUtils; import io.grpc.xds.internal.security.trust.CertificateUtils;
import io.netty.handler.ssl.SslContext; import io.netty.handler.ssl.SslContext;
@ -200,9 +201,9 @@ public class CommonTlsContextTestsUtil {
} }
} }
/** Gets contents of a resource from TestUtils.class loader. */ /** Gets contents of a certs resource. */
public static String getResourceContents(String resourceName) throws IOException { public static String getResourceContents(String resourceName) throws IOException {
InputStream inputStream = TestUtils.class.getResourceAsStream("/certs/" + resourceName); InputStream inputStream = TlsTesting.loadCert(resourceName);
String text = null; String text = null;
try (Reader reader = new InputStreamReader(inputStream, UTF_8)) { try (Reader reader = new InputStreamReader(inputStream, UTF_8)) {
text = CharStreams.toString(reader); text = CharStreams.toString(reader);

View File

@ -28,6 +28,7 @@ import io.envoyproxy.envoy.config.core.v3.DataSource;
import io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.CertificateValidationContext; import io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.CertificateValidationContext;
import io.envoyproxy.envoy.type.matcher.v3.StringMatcher; import io.envoyproxy.envoy.type.matcher.v3.StringMatcher;
import io.grpc.internal.testing.TestUtils; import io.grpc.internal.testing.TestUtils;
import io.grpc.testing.TlsTesting;
import java.io.IOException; import java.io.IOException;
import java.security.cert.CertStoreException; import java.security.cert.CertStoreException;
import java.security.cert.CertificateException; import java.security.cert.CertificateException;
@ -58,7 +59,7 @@ public class XdsTrustManagerFactoryTest {
assertThat(acceptedIssuers).hasLength(1); assertThat(acceptedIssuers).hasLength(1);
X509Certificate caCert = acceptedIssuers[0]; X509Certificate caCert = acceptedIssuers[0];
assertThat(caCert) assertThat(caCert)
.isEqualTo(CertificateUtils.toX509Certificates(TestUtils.loadCert(CA_PEM_FILE))[0]); .isEqualTo(CertificateUtils.toX509Certificates(TlsTesting.loadCert(CA_PEM_FILE))[0]);
} }
@Test @Test
@ -78,7 +79,7 @@ public class XdsTrustManagerFactoryTest {
assertThat(acceptedIssuers).hasLength(1); assertThat(acceptedIssuers).hasLength(1);
X509Certificate caCert = acceptedIssuers[0]; X509Certificate caCert = acceptedIssuers[0];
assertThat(caCert) assertThat(caCert)
.isEqualTo(CertificateUtils.toX509Certificates(TestUtils.loadCert(CA_PEM_FILE))[0]); .isEqualTo(CertificateUtils.toX509Certificates(TlsTesting.loadCert(CA_PEM_FILE))[0]);
} }
@Test @Test
@ -101,7 +102,7 @@ public class XdsTrustManagerFactoryTest {
assertThat(acceptedIssuers).hasLength(1); assertThat(acceptedIssuers).hasLength(1);
X509Certificate caCert = acceptedIssuers[0]; X509Certificate caCert = acceptedIssuers[0];
assertThat(caCert) assertThat(caCert)
.isEqualTo(CertificateUtils.toX509Certificates(TestUtils.loadCert(CA_PEM_FILE))[0]); .isEqualTo(CertificateUtils.toX509Certificates(TlsTesting.loadCert(CA_PEM_FILE))[0]);
} }
@Test @Test
@ -114,7 +115,7 @@ public class XdsTrustManagerFactoryTest {
new XdsTrustManagerFactory(new X509Certificate[]{x509Cert}, staticValidationContext); new XdsTrustManagerFactory(new X509Certificate[]{x509Cert}, staticValidationContext);
XdsX509TrustManager xdsX509TrustManager = (XdsX509TrustManager) factory.getTrustManagers()[0]; XdsX509TrustManager xdsX509TrustManager = (XdsX509TrustManager) factory.getTrustManagers()[0];
X509Certificate[] serverChain = X509Certificate[] serverChain =
CertificateUtils.toX509Certificates(TestUtils.loadCert(SERVER_1_PEM_FILE)); CertificateUtils.toX509Certificates(TlsTesting.loadCert(SERVER_1_PEM_FILE));
xdsX509TrustManager.checkServerTrusted(serverChain, "RSA"); xdsX509TrustManager.checkServerTrusted(serverChain, "RSA");
} }
@ -143,7 +144,7 @@ public class XdsTrustManagerFactoryTest {
new XdsTrustManagerFactory(new X509Certificate[]{x509Cert}, staticValidationContext); new XdsTrustManagerFactory(new X509Certificate[]{x509Cert}, staticValidationContext);
XdsX509TrustManager xdsX509TrustManager = (XdsX509TrustManager) factory.getTrustManagers()[0]; XdsX509TrustManager xdsX509TrustManager = (XdsX509TrustManager) factory.getTrustManagers()[0];
X509Certificate[] serverChain = X509Certificate[] serverChain =
CertificateUtils.toX509Certificates(TestUtils.loadCert(SERVER_1_PEM_FILE)); CertificateUtils.toX509Certificates(TlsTesting.loadCert(SERVER_1_PEM_FILE));
try { try {
xdsX509TrustManager.checkServerTrusted(serverChain, "RSA"); xdsX509TrustManager.checkServerTrusted(serverChain, "RSA");
Assert.fail("no exception thrown"); Assert.fail("no exception thrown");
@ -164,7 +165,7 @@ public class XdsTrustManagerFactoryTest {
new XdsTrustManagerFactory(new X509Certificate[]{x509Cert}, staticValidationContext); new XdsTrustManagerFactory(new X509Certificate[]{x509Cert}, staticValidationContext);
XdsX509TrustManager xdsX509TrustManager = (XdsX509TrustManager) factory.getTrustManagers()[0]; XdsX509TrustManager xdsX509TrustManager = (XdsX509TrustManager) factory.getTrustManagers()[0];
X509Certificate[] clientChain = X509Certificate[] clientChain =
CertificateUtils.toX509Certificates(TestUtils.loadCert(SERVER_1_PEM_FILE)); CertificateUtils.toX509Certificates(TlsTesting.loadCert(SERVER_1_PEM_FILE));
try { try {
xdsX509TrustManager.checkClientTrusted(clientChain, "RSA"); xdsX509TrustManager.checkClientTrusted(clientChain, "RSA");
Assert.fail("no exception thrown"); Assert.fail("no exception thrown");
@ -182,7 +183,7 @@ public class XdsTrustManagerFactoryTest {
new XdsTrustManagerFactory(getCertContextFromPath(CA_PEM_FILE)); new XdsTrustManagerFactory(getCertContextFromPath(CA_PEM_FILE));
XdsX509TrustManager xdsX509TrustManager = (XdsX509TrustManager) factory.getTrustManagers()[0]; XdsX509TrustManager xdsX509TrustManager = (XdsX509TrustManager) factory.getTrustManagers()[0];
X509Certificate[] serverChain = X509Certificate[] serverChain =
CertificateUtils.toX509Certificates(TestUtils.loadCert(SERVER_1_PEM_FILE)); CertificateUtils.toX509Certificates(TlsTesting.loadCert(SERVER_1_PEM_FILE));
xdsX509TrustManager.checkServerTrusted(serverChain, "RSA"); xdsX509TrustManager.checkServerTrusted(serverChain, "RSA");
} }
@ -193,7 +194,7 @@ public class XdsTrustManagerFactoryTest {
new XdsTrustManagerFactory(getCertContextFromPath(CA_PEM_FILE)); new XdsTrustManagerFactory(getCertContextFromPath(CA_PEM_FILE));
XdsX509TrustManager xdsX509TrustManager = (XdsX509TrustManager) factory.getTrustManagers()[0]; XdsX509TrustManager xdsX509TrustManager = (XdsX509TrustManager) factory.getTrustManagers()[0];
X509Certificate[] clientChain = X509Certificate[] clientChain =
CertificateUtils.toX509Certificates(TestUtils.loadCert(CLIENT_PEM_FILE)); CertificateUtils.toX509Certificates(TlsTesting.loadCert(CLIENT_PEM_FILE));
xdsX509TrustManager.checkClientTrusted(clientChain, "RSA"); xdsX509TrustManager.checkClientTrusted(clientChain, "RSA");
} }
@ -204,7 +205,7 @@ public class XdsTrustManagerFactoryTest {
new XdsTrustManagerFactory(getCertContextFromPath(CA_PEM_FILE)); new XdsTrustManagerFactory(getCertContextFromPath(CA_PEM_FILE));
XdsX509TrustManager xdsX509TrustManager = (XdsX509TrustManager) factory.getTrustManagers()[0]; XdsX509TrustManager xdsX509TrustManager = (XdsX509TrustManager) factory.getTrustManagers()[0];
X509Certificate[] serverChain = X509Certificate[] serverChain =
CertificateUtils.toX509Certificates(TestUtils.loadCert(BAD_SERVER_PEM_FILE)); CertificateUtils.toX509Certificates(TlsTesting.loadCert(BAD_SERVER_PEM_FILE));
try { try {
xdsX509TrustManager.checkServerTrusted(serverChain, "RSA"); xdsX509TrustManager.checkServerTrusted(serverChain, "RSA");
Assert.fail("no exception thrown"); Assert.fail("no exception thrown");
@ -222,7 +223,7 @@ public class XdsTrustManagerFactoryTest {
new XdsTrustManagerFactory(getCertContextFromPath(CA_PEM_FILE)); new XdsTrustManagerFactory(getCertContextFromPath(CA_PEM_FILE));
XdsX509TrustManager xdsX509TrustManager = (XdsX509TrustManager) factory.getTrustManagers()[0]; XdsX509TrustManager xdsX509TrustManager = (XdsX509TrustManager) factory.getTrustManagers()[0];
X509Certificate[] clientChain = X509Certificate[] clientChain =
CertificateUtils.toX509Certificates(TestUtils.loadCert(BAD_CLIENT_PEM_FILE)); CertificateUtils.toX509Certificates(TlsTesting.loadCert(BAD_CLIENT_PEM_FILE));
try { try {
xdsX509TrustManager.checkClientTrusted(clientChain, "RSA"); xdsX509TrustManager.checkClientTrusted(clientChain, "RSA");
Assert.fail("no exception thrown"); Assert.fail("no exception thrown");

View File

@ -33,7 +33,7 @@ import com.google.common.collect.ImmutableList;
import io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.CertificateValidationContext; import io.envoyproxy.envoy.extensions.transport_sockets.tls.v3.CertificateValidationContext;
import io.envoyproxy.envoy.type.matcher.v3.RegexMatcher; import io.envoyproxy.envoy.type.matcher.v3.RegexMatcher;
import io.envoyproxy.envoy.type.matcher.v3.StringMatcher; import io.envoyproxy.envoy.type.matcher.v3.StringMatcher;
import io.grpc.internal.testing.TestUtils; import io.grpc.testing.TlsTesting;
import java.io.IOException; import java.io.IOException;
import java.security.cert.CertStoreException; import java.security.cert.CertStoreException;
import java.security.cert.CertificateException; import java.security.cert.CertificateException;
@ -74,7 +74,7 @@ public class XdsX509TrustManagerTest {
public void nullCertContextTest() throws CertificateException, IOException { public void nullCertContextTest() throws CertificateException, IOException {
trustManager = new XdsX509TrustManager(null, mockDelegate); trustManager = new XdsX509TrustManager(null, mockDelegate);
X509Certificate[] certs = X509Certificate[] certs =
CertificateUtils.toX509Certificates(TestUtils.loadCert(SERVER_1_PEM_FILE)); CertificateUtils.toX509Certificates(TlsTesting.loadCert(SERVER_1_PEM_FILE));
trustManager.verifySubjectAltNameInChain(certs); trustManager.verifySubjectAltNameInChain(certs);
} }
@ -83,7 +83,7 @@ public class XdsX509TrustManagerTest {
CertificateValidationContext certContext = CertificateValidationContext.getDefaultInstance(); CertificateValidationContext certContext = CertificateValidationContext.getDefaultInstance();
trustManager = new XdsX509TrustManager(certContext, mockDelegate); trustManager = new XdsX509TrustManager(certContext, mockDelegate);
X509Certificate[] certs = X509Certificate[] certs =
CertificateUtils.toX509Certificates(TestUtils.loadCert(SERVER_1_PEM_FILE)); CertificateUtils.toX509Certificates(TlsTesting.loadCert(SERVER_1_PEM_FILE));
trustManager.verifySubjectAltNameInChain(certs); trustManager.verifySubjectAltNameInChain(certs);
} }
@ -125,7 +125,7 @@ public class XdsX509TrustManagerTest {
CertificateValidationContext.newBuilder().addMatchSubjectAltNames(stringMatcher).build(); CertificateValidationContext.newBuilder().addMatchSubjectAltNames(stringMatcher).build();
trustManager = new XdsX509TrustManager(certContext, mockDelegate); trustManager = new XdsX509TrustManager(certContext, mockDelegate);
X509Certificate[] certs = X509Certificate[] certs =
CertificateUtils.toX509Certificates(TestUtils.loadCert(CLIENT_PEM_FILE)); CertificateUtils.toX509Certificates(TlsTesting.loadCert(CLIENT_PEM_FILE));
try { try {
trustManager.verifySubjectAltNameInChain(certs); trustManager.verifySubjectAltNameInChain(certs);
fail("no exception thrown"); fail("no exception thrown");
@ -146,7 +146,7 @@ public class XdsX509TrustManagerTest {
CertificateValidationContext.newBuilder().addMatchSubjectAltNames(stringMatcher).build(); CertificateValidationContext.newBuilder().addMatchSubjectAltNames(stringMatcher).build();
trustManager = new XdsX509TrustManager(certContext, mockDelegate); trustManager = new XdsX509TrustManager(certContext, mockDelegate);
X509Certificate[] certs = X509Certificate[] certs =
CertificateUtils.toX509Certificates(TestUtils.loadCert(SERVER_1_PEM_FILE)); CertificateUtils.toX509Certificates(TlsTesting.loadCert(SERVER_1_PEM_FILE));
trustManager.verifySubjectAltNameInChain(certs); trustManager.verifySubjectAltNameInChain(certs);
} }
@ -163,7 +163,7 @@ public class XdsX509TrustManagerTest {
CertificateValidationContext.newBuilder().addMatchSubjectAltNames(stringMatcher).build(); CertificateValidationContext.newBuilder().addMatchSubjectAltNames(stringMatcher).build();
trustManager = new XdsX509TrustManager(certContext, mockDelegate); trustManager = new XdsX509TrustManager(certContext, mockDelegate);
X509Certificate[] certs = X509Certificate[] certs =
CertificateUtils.toX509Certificates(TestUtils.loadCert(SERVER_1_PEM_FILE)); CertificateUtils.toX509Certificates(TlsTesting.loadCert(SERVER_1_PEM_FILE));
try { try {
trustManager.verifySubjectAltNameInChain(certs); trustManager.verifySubjectAltNameInChain(certs);
fail("no exception thrown"); fail("no exception thrown");
@ -181,7 +181,7 @@ public class XdsX509TrustManagerTest {
CertificateValidationContext.newBuilder().addMatchSubjectAltNames(stringMatcher).build(); CertificateValidationContext.newBuilder().addMatchSubjectAltNames(stringMatcher).build();
trustManager = new XdsX509TrustManager(certContext, mockDelegate); trustManager = new XdsX509TrustManager(certContext, mockDelegate);
X509Certificate[] certs = X509Certificate[] certs =
CertificateUtils.toX509Certificates(TestUtils.loadCert(SERVER_1_PEM_FILE)); CertificateUtils.toX509Certificates(TlsTesting.loadCert(SERVER_1_PEM_FILE));
trustManager.verifySubjectAltNameInChain(certs); trustManager.verifySubjectAltNameInChain(certs);
} }
@ -197,7 +197,7 @@ public class XdsX509TrustManagerTest {
CertificateValidationContext.newBuilder().addMatchSubjectAltNames(stringMatcher).build(); CertificateValidationContext.newBuilder().addMatchSubjectAltNames(stringMatcher).build();
trustManager = new XdsX509TrustManager(certContext, mockDelegate); trustManager = new XdsX509TrustManager(certContext, mockDelegate);
X509Certificate[] certs = X509Certificate[] certs =
CertificateUtils.toX509Certificates(TestUtils.loadCert(SERVER_1_PEM_FILE)); CertificateUtils.toX509Certificates(TlsTesting.loadCert(SERVER_1_PEM_FILE));
trustManager.verifySubjectAltNameInChain(certs); trustManager.verifySubjectAltNameInChain(certs);
} }
@ -211,7 +211,7 @@ public class XdsX509TrustManagerTest {
CertificateValidationContext.newBuilder().addMatchSubjectAltNames(stringMatcher).build(); CertificateValidationContext.newBuilder().addMatchSubjectAltNames(stringMatcher).build();
trustManager = new XdsX509TrustManager(certContext, mockDelegate); trustManager = new XdsX509TrustManager(certContext, mockDelegate);
X509Certificate[] certs = X509Certificate[] certs =
CertificateUtils.toX509Certificates(TestUtils.loadCert(SERVER_1_PEM_FILE)); CertificateUtils.toX509Certificates(TlsTesting.loadCert(SERVER_1_PEM_FILE));
try { try {
trustManager.verifySubjectAltNameInChain(certs); trustManager.verifySubjectAltNameInChain(certs);
fail("no exception thrown"); fail("no exception thrown");
@ -232,7 +232,7 @@ public class XdsX509TrustManagerTest {
CertificateValidationContext.newBuilder().addMatchSubjectAltNames(stringMatcher).build(); CertificateValidationContext.newBuilder().addMatchSubjectAltNames(stringMatcher).build();
trustManager = new XdsX509TrustManager(certContext, mockDelegate); trustManager = new XdsX509TrustManager(certContext, mockDelegate);
X509Certificate[] certs = X509Certificate[] certs =
CertificateUtils.toX509Certificates(TestUtils.loadCert(SERVER_1_PEM_FILE)); CertificateUtils.toX509Certificates(TlsTesting.loadCert(SERVER_1_PEM_FILE));
trustManager.verifySubjectAltNameInChain(certs); trustManager.verifySubjectAltNameInChain(certs);
} }
@ -245,7 +245,7 @@ public class XdsX509TrustManagerTest {
CertificateValidationContext.newBuilder().addMatchSubjectAltNames(stringMatcher).build(); CertificateValidationContext.newBuilder().addMatchSubjectAltNames(stringMatcher).build();
trustManager = new XdsX509TrustManager(certContext, mockDelegate); trustManager = new XdsX509TrustManager(certContext, mockDelegate);
X509Certificate[] certs = X509Certificate[] certs =
CertificateUtils.toX509Certificates(TestUtils.loadCert(SERVER_1_PEM_FILE)); CertificateUtils.toX509Certificates(TlsTesting.loadCert(SERVER_1_PEM_FILE));
trustManager.verifySubjectAltNameInChain(certs); trustManager.verifySubjectAltNameInChain(certs);
} }
@ -259,7 +259,7 @@ public class XdsX509TrustManagerTest {
CertificateValidationContext.newBuilder().addMatchSubjectAltNames(stringMatcher).build(); CertificateValidationContext.newBuilder().addMatchSubjectAltNames(stringMatcher).build();
trustManager = new XdsX509TrustManager(certContext, mockDelegate); trustManager = new XdsX509TrustManager(certContext, mockDelegate);
X509Certificate[] certs = X509Certificate[] certs =
CertificateUtils.toX509Certificates(TestUtils.loadCert(SERVER_1_PEM_FILE)); CertificateUtils.toX509Certificates(TlsTesting.loadCert(SERVER_1_PEM_FILE));
try { try {
trustManager.verifySubjectAltNameInChain(certs); trustManager.verifySubjectAltNameInChain(certs);
fail("no exception thrown"); fail("no exception thrown");
@ -277,7 +277,7 @@ public class XdsX509TrustManagerTest {
CertificateValidationContext.newBuilder().addMatchSubjectAltNames(stringMatcher).build(); CertificateValidationContext.newBuilder().addMatchSubjectAltNames(stringMatcher).build();
trustManager = new XdsX509TrustManager(certContext, mockDelegate); trustManager = new XdsX509TrustManager(certContext, mockDelegate);
X509Certificate[] certs = X509Certificate[] certs =
CertificateUtils.toX509Certificates(TestUtils.loadCert(SERVER_1_PEM_FILE)); CertificateUtils.toX509Certificates(TlsTesting.loadCert(SERVER_1_PEM_FILE));
trustManager.verifySubjectAltNameInChain(certs); trustManager.verifySubjectAltNameInChain(certs);
} }
@ -290,7 +290,7 @@ public class XdsX509TrustManagerTest {
CertificateValidationContext.newBuilder().addMatchSubjectAltNames(stringMatcher).build(); CertificateValidationContext.newBuilder().addMatchSubjectAltNames(stringMatcher).build();
trustManager = new XdsX509TrustManager(certContext, mockDelegate); trustManager = new XdsX509TrustManager(certContext, mockDelegate);
X509Certificate[] certs = X509Certificate[] certs =
CertificateUtils.toX509Certificates(TestUtils.loadCert(SERVER_1_PEM_FILE)); CertificateUtils.toX509Certificates(TlsTesting.loadCert(SERVER_1_PEM_FILE));
trustManager.verifySubjectAltNameInChain(certs); trustManager.verifySubjectAltNameInChain(certs);
} }
@ -304,7 +304,7 @@ public class XdsX509TrustManagerTest {
CertificateValidationContext.newBuilder().addMatchSubjectAltNames(stringMatcher).build(); CertificateValidationContext.newBuilder().addMatchSubjectAltNames(stringMatcher).build();
trustManager = new XdsX509TrustManager(certContext, mockDelegate); trustManager = new XdsX509TrustManager(certContext, mockDelegate);
X509Certificate[] certs = X509Certificate[] certs =
CertificateUtils.toX509Certificates(TestUtils.loadCert(SERVER_1_PEM_FILE)); CertificateUtils.toX509Certificates(TlsTesting.loadCert(SERVER_1_PEM_FILE));
try { try {
trustManager.verifySubjectAltNameInChain(certs); trustManager.verifySubjectAltNameInChain(certs);
fail("no exception thrown"); fail("no exception thrown");
@ -322,7 +322,7 @@ public class XdsX509TrustManagerTest {
CertificateValidationContext.newBuilder().addMatchSubjectAltNames(stringMatcher).build(); CertificateValidationContext.newBuilder().addMatchSubjectAltNames(stringMatcher).build();
trustManager = new XdsX509TrustManager(certContext, mockDelegate); trustManager = new XdsX509TrustManager(certContext, mockDelegate);
X509Certificate[] certs = X509Certificate[] certs =
CertificateUtils.toX509Certificates(TestUtils.loadCert(SERVER_1_PEM_FILE)); CertificateUtils.toX509Certificates(TlsTesting.loadCert(SERVER_1_PEM_FILE));
trustManager.verifySubjectAltNameInChain(certs); trustManager.verifySubjectAltNameInChain(certs);
} }
@ -338,7 +338,7 @@ public class XdsX509TrustManagerTest {
CertificateValidationContext.newBuilder().addMatchSubjectAltNames(stringMatcher).build(); CertificateValidationContext.newBuilder().addMatchSubjectAltNames(stringMatcher).build();
trustManager = new XdsX509TrustManager(certContext, mockDelegate); trustManager = new XdsX509TrustManager(certContext, mockDelegate);
X509Certificate[] certs = X509Certificate[] certs =
CertificateUtils.toX509Certificates(TestUtils.loadCert(SERVER_1_PEM_FILE)); CertificateUtils.toX509Certificates(TlsTesting.loadCert(SERVER_1_PEM_FILE));
trustManager.verifySubjectAltNameInChain(certs); trustManager.verifySubjectAltNameInChain(certs);
} }
@ -354,7 +354,7 @@ public class XdsX509TrustManagerTest {
CertificateValidationContext.newBuilder().addMatchSubjectAltNames(stringMatcher).build(); CertificateValidationContext.newBuilder().addMatchSubjectAltNames(stringMatcher).build();
trustManager = new XdsX509TrustManager(certContext, mockDelegate); trustManager = new XdsX509TrustManager(certContext, mockDelegate);
X509Certificate[] certs = X509Certificate[] certs =
CertificateUtils.toX509Certificates(TestUtils.loadCert(SERVER_1_PEM_FILE)); CertificateUtils.toX509Certificates(TlsTesting.loadCert(SERVER_1_PEM_FILE));
trustManager.verifySubjectAltNameInChain(certs); trustManager.verifySubjectAltNameInChain(certs);
} }
@ -370,7 +370,7 @@ public class XdsX509TrustManagerTest {
CertificateValidationContext.newBuilder().addMatchSubjectAltNames(stringMatcher).build(); CertificateValidationContext.newBuilder().addMatchSubjectAltNames(stringMatcher).build();
trustManager = new XdsX509TrustManager(certContext, mockDelegate); trustManager = new XdsX509TrustManager(certContext, mockDelegate);
X509Certificate[] certs = X509Certificate[] certs =
CertificateUtils.toX509Certificates(TestUtils.loadCert(SERVER_1_PEM_FILE)); CertificateUtils.toX509Certificates(TlsTesting.loadCert(SERVER_1_PEM_FILE));
trustManager.verifySubjectAltNameInChain(certs); trustManager.verifySubjectAltNameInChain(certs);
} }
@ -386,7 +386,7 @@ public class XdsX509TrustManagerTest {
CertificateValidationContext.newBuilder().addMatchSubjectAltNames(stringMatcher).build(); CertificateValidationContext.newBuilder().addMatchSubjectAltNames(stringMatcher).build();
trustManager = new XdsX509TrustManager(certContext, mockDelegate); trustManager = new XdsX509TrustManager(certContext, mockDelegate);
X509Certificate[] certs = X509Certificate[] certs =
CertificateUtils.toX509Certificates(TestUtils.loadCert(SERVER_1_PEM_FILE)); CertificateUtils.toX509Certificates(TlsTesting.loadCert(SERVER_1_PEM_FILE));
try { try {
trustManager.verifySubjectAltNameInChain(certs); trustManager.verifySubjectAltNameInChain(certs);
fail("no exception thrown"); fail("no exception thrown");
@ -409,7 +409,7 @@ public class XdsX509TrustManagerTest {
.build(); .build();
trustManager = new XdsX509TrustManager(certContext, mockDelegate); trustManager = new XdsX509TrustManager(certContext, mockDelegate);
X509Certificate[] certs = X509Certificate[] certs =
CertificateUtils.toX509Certificates(TestUtils.loadCert(SERVER_1_PEM_FILE)); CertificateUtils.toX509Certificates(TlsTesting.loadCert(SERVER_1_PEM_FILE));
trustManager.verifySubjectAltNameInChain(certs); trustManager.verifySubjectAltNameInChain(certs);
} }
@ -422,7 +422,7 @@ public class XdsX509TrustManagerTest {
CertificateValidationContext.newBuilder().addMatchSubjectAltNames(stringMatcher).build(); CertificateValidationContext.newBuilder().addMatchSubjectAltNames(stringMatcher).build();
trustManager = new XdsX509TrustManager(certContext, mockDelegate); trustManager = new XdsX509TrustManager(certContext, mockDelegate);
X509Certificate[] certs = X509Certificate[] certs =
CertificateUtils.toX509Certificates(TestUtils.loadCert(SERVER_1_PEM_FILE)); CertificateUtils.toX509Certificates(TlsTesting.loadCert(SERVER_1_PEM_FILE));
try { try {
trustManager.verifySubjectAltNameInChain(certs); trustManager.verifySubjectAltNameInChain(certs);
fail("no exception thrown"); fail("no exception thrown");
@ -445,7 +445,7 @@ public class XdsX509TrustManagerTest {
.build(); .build();
trustManager = new XdsX509TrustManager(certContext, mockDelegate); trustManager = new XdsX509TrustManager(certContext, mockDelegate);
X509Certificate[] certs = X509Certificate[] certs =
CertificateUtils.toX509Certificates(TestUtils.loadCert(SERVER_1_PEM_FILE)); CertificateUtils.toX509Certificates(TlsTesting.loadCert(SERVER_1_PEM_FILE));
trustManager.verifySubjectAltNameInChain(certs); trustManager.verifySubjectAltNameInChain(certs);
} }
@ -463,7 +463,7 @@ public class XdsX509TrustManagerTest {
.build(); .build();
trustManager = new XdsX509TrustManager(certContext, mockDelegate); trustManager = new XdsX509TrustManager(certContext, mockDelegate);
X509Certificate[] certs = X509Certificate[] certs =
CertificateUtils.toX509Certificates(TestUtils.loadCert(SERVER_1_PEM_FILE)); CertificateUtils.toX509Certificates(TlsTesting.loadCert(SERVER_1_PEM_FILE));
trustManager.verifySubjectAltNameInChain(certs); trustManager.verifySubjectAltNameInChain(certs);
} }
@ -480,7 +480,7 @@ public class XdsX509TrustManagerTest {
CertificateValidationContext.newBuilder().addMatchSubjectAltNames(stringMatcher).build(); CertificateValidationContext.newBuilder().addMatchSubjectAltNames(stringMatcher).build();
trustManager = new XdsX509TrustManager(certContext, mockDelegate); trustManager = new XdsX509TrustManager(certContext, mockDelegate);
X509Certificate[] certs = X509Certificate[] certs =
CertificateUtils.toX509Certificates(TestUtils.loadCert(SERVER_1_PEM_FILE)); CertificateUtils.toX509Certificates(TlsTesting.loadCert(SERVER_1_PEM_FILE));
try { try {
trustManager.verifySubjectAltNameInChain(certs); trustManager.verifySubjectAltNameInChain(certs);
fail("no exception thrown"); fail("no exception thrown");
@ -501,7 +501,7 @@ public class XdsX509TrustManagerTest {
.build(); .build();
trustManager = new XdsX509TrustManager(certContext, mockDelegate); trustManager = new XdsX509TrustManager(certContext, mockDelegate);
X509Certificate[] certs = X509Certificate[] certs =
CertificateUtils.toX509Certificates(TestUtils.loadCert(SERVER_1_PEM_FILE)); CertificateUtils.toX509Certificates(TlsTesting.loadCert(SERVER_1_PEM_FILE));
trustManager.verifySubjectAltNameInChain(certs); trustManager.verifySubjectAltNameInChain(certs);
} }
@ -517,7 +517,7 @@ public class XdsX509TrustManagerTest {
.build(); .build();
trustManager = new XdsX509TrustManager(certContext, mockDelegate); trustManager = new XdsX509TrustManager(certContext, mockDelegate);
X509Certificate[] certs = X509Certificate[] certs =
CertificateUtils.toX509Certificates(TestUtils.loadCert(SERVER_1_PEM_FILE)); CertificateUtils.toX509Certificates(TlsTesting.loadCert(SERVER_1_PEM_FILE));
try { try {
trustManager.verifySubjectAltNameInChain(certs); trustManager.verifySubjectAltNameInChain(certs);
fail("no exception thrown"); fail("no exception thrown");
@ -531,7 +531,7 @@ public class XdsX509TrustManagerTest {
throws CertificateException, IOException, CertStoreException { throws CertificateException, IOException, CertStoreException {
TestSslEngine sslEngine = buildTrustManagerAndGetSslEngine(); TestSslEngine sslEngine = buildTrustManagerAndGetSslEngine();
X509Certificate[] serverCerts = X509Certificate[] serverCerts =
CertificateUtils.toX509Certificates(TestUtils.loadCert(SERVER_1_PEM_FILE)); CertificateUtils.toX509Certificates(TlsTesting.loadCert(SERVER_1_PEM_FILE));
trustManager.checkServerTrusted(serverCerts, "ECDHE_ECDSA", sslEngine); trustManager.checkServerTrusted(serverCerts, "ECDHE_ECDSA", sslEngine);
verify(sslEngine, times(1)).getHandshakeSession(); verify(sslEngine, times(1)).getHandshakeSession();
} }
@ -541,7 +541,7 @@ public class XdsX509TrustManagerTest {
throws CertificateException, IOException, CertStoreException { throws CertificateException, IOException, CertStoreException {
TestSslEngine sslEngine = buildTrustManagerAndGetSslEngine(); TestSslEngine sslEngine = buildTrustManagerAndGetSslEngine();
X509Certificate[] badServerCert = X509Certificate[] badServerCert =
CertificateUtils.toX509Certificates(TestUtils.loadCert(BAD_SERVER_PEM_FILE)); CertificateUtils.toX509Certificates(TlsTesting.loadCert(BAD_SERVER_PEM_FILE));
try { try {
trustManager.checkServerTrusted(badServerCert, "ECDHE_ECDSA", sslEngine); trustManager.checkServerTrusted(badServerCert, "ECDHE_ECDSA", sslEngine);
fail("exception expected"); fail("exception expected");
@ -557,7 +557,7 @@ public class XdsX509TrustManagerTest {
throws CertificateException, IOException, CertStoreException { throws CertificateException, IOException, CertStoreException {
TestSslSocket sslSocket = buildTrustManagerAndGetSslSocket(); TestSslSocket sslSocket = buildTrustManagerAndGetSslSocket();
X509Certificate[] serverCerts = X509Certificate[] serverCerts =
CertificateUtils.toX509Certificates(TestUtils.loadCert(SERVER_1_PEM_FILE)); CertificateUtils.toX509Certificates(TlsTesting.loadCert(SERVER_1_PEM_FILE));
trustManager.checkServerTrusted(serverCerts, "ECDHE_ECDSA", sslSocket); trustManager.checkServerTrusted(serverCerts, "ECDHE_ECDSA", sslSocket);
verify(sslSocket, times(1)).isConnected(); verify(sslSocket, times(1)).isConnected();
verify(sslSocket, times(1)).getHandshakeSession(); verify(sslSocket, times(1)).getHandshakeSession();
@ -568,7 +568,7 @@ public class XdsX509TrustManagerTest {
throws CertificateException, IOException, CertStoreException { throws CertificateException, IOException, CertStoreException {
TestSslSocket sslSocket = buildTrustManagerAndGetSslSocket(); TestSslSocket sslSocket = buildTrustManagerAndGetSslSocket();
X509Certificate[] badServerCert = X509Certificate[] badServerCert =
CertificateUtils.toX509Certificates(TestUtils.loadCert(BAD_SERVER_PEM_FILE)); CertificateUtils.toX509Certificates(TlsTesting.loadCert(BAD_SERVER_PEM_FILE));
try { try {
trustManager.checkServerTrusted(badServerCert, "ECDHE_ECDSA", sslSocket); trustManager.checkServerTrusted(badServerCert, "ECDHE_ECDSA", sslSocket);
fail("exception expected"); fail("exception expected");
@ -628,7 +628,7 @@ public class XdsX509TrustManagerTest {
private SSLParameters buildTrustManagerAndGetSslParameters() private SSLParameters buildTrustManagerAndGetSslParameters()
throws CertificateException, IOException, CertStoreException { throws CertificateException, IOException, CertStoreException {
X509Certificate[] caCerts = X509Certificate[] caCerts =
CertificateUtils.toX509Certificates(TestUtils.loadCert(CA_PEM_FILE)); CertificateUtils.toX509Certificates(TlsTesting.loadCert(CA_PEM_FILE));
trustManager = XdsTrustManagerFactory.createSdsX509TrustManager(caCerts, trustManager = XdsTrustManagerFactory.createSdsX509TrustManager(caCerts,
null); null);
when(mockSession.getProtocol()).thenReturn("TLSv1.2"); when(mockSession.getProtocol()).thenReturn("TLSv1.2");