use of io.grpc.ServerCredentials in project grpc-java by grpc.
the class ProtocolNegotiatorsTest method fromServer_unknown.
@Test
public void fromServer_unknown() {
ProtocolNegotiators.FromServerCredentialsResult result = ProtocolNegotiators.from(new ServerCredentials() {
});
assertThat(result.error).isNotNull();
assertThat(result.negotiator).isNull();
}
use of io.grpc.ServerCredentials in project grpc-java by grpc.
the class ProtocolNegotiatorsTest method from_tls_clientAuthNone_noClientCert.
@Test
public void from_tls_clientAuthNone_noClientCert() throws Exception {
// Use convenience API to better match most user's usage
ServerCredentials serverCreds = TlsServerCredentials.create(server1Cert, server1Key);
ChannelCredentials channelCreds = TlsChannelCredentials.newBuilder().trustManager(caCert).build();
InternalChannelz.Tls tls = expectSuccessfulHandshake(channelCreds, serverCreds);
assertThat(tls.remoteCert).isNull();
}
use of io.grpc.ServerCredentials in project grpc-java by grpc.
the class ProtocolNegotiatorsTest method from_tls_clientAuthNone_clientCert.
@Test
public void from_tls_clientAuthNone_clientCert() throws Exception {
ServerCredentials serverCreds = TlsServerCredentials.newBuilder().keyManager(server1Cert, server1Key).trustManager(caCert).build();
ChannelCredentials channelCreds = TlsChannelCredentials.newBuilder().keyManager(server1Cert, server1Key).trustManager(caCert).build();
InternalChannelz.Tls tls = expectSuccessfulHandshake(channelCreds, serverCreds);
assertThat(tls.remoteCert).isNull();
}
use of io.grpc.ServerCredentials in project grpc-java by grpc.
the class TransportBenchmark method setUp.
@Setup
public void setUp() throws Exception {
ServerCredentials serverCreds = InsecureServerCredentials.create();
ServerBuilder<?> serverBuilder;
ManagedChannelBuilder<?> channelBuilder;
switch(transport) {
case INPROCESS:
{
String name = "bench" + Math.random();
serverBuilder = InProcessServerBuilder.forName(name);
channelBuilder = InProcessChannelBuilder.forName(name);
break;
}
case NETTY:
{
InetSocketAddress address = new InetSocketAddress("localhost", pickUnusedPort());
serverBuilder = NettyServerBuilder.forAddress(address, serverCreds);
channelBuilder = NettyChannelBuilder.forAddress(address).negotiationType(NegotiationType.PLAINTEXT);
break;
}
case NETTY_LOCAL:
{
String name = "bench" + Math.random();
LocalAddress address = new LocalAddress(name);
EventLoopGroup group = new DefaultEventLoopGroup();
serverBuilder = NettyServerBuilder.forAddress(address, serverCreds).bossEventLoopGroup(group).workerEventLoopGroup(group).channelType(LocalServerChannel.class);
channelBuilder = NettyChannelBuilder.forAddress(address).eventLoopGroup(group).channelType(LocalChannel.class).negotiationType(NegotiationType.PLAINTEXT);
groupToShutdown = group;
break;
}
case NETTY_EPOLL:
{
InetSocketAddress address = new InetSocketAddress("localhost", pickUnusedPort());
// Reflection used since they are only available on linux.
Class<?> groupClass = Class.forName("io.netty.channel.epoll.EpollEventLoopGroup");
EventLoopGroup group = (EventLoopGroup) groupClass.getConstructor().newInstance();
Class<? extends ServerChannel> serverChannelClass = Class.forName("io.netty.channel.epoll.EpollServerSocketChannel").asSubclass(ServerChannel.class);
serverBuilder = NettyServerBuilder.forAddress(address, serverCreds).bossEventLoopGroup(group).workerEventLoopGroup(group).channelType(serverChannelClass);
Class<? extends Channel> channelClass = Class.forName("io.netty.channel.epoll.EpollSocketChannel").asSubclass(Channel.class);
channelBuilder = NettyChannelBuilder.forAddress(address).eventLoopGroup(group).channelType(channelClass).negotiationType(NegotiationType.PLAINTEXT);
groupToShutdown = group;
break;
}
case OKHTTP:
{
int port = pickUnusedPort();
InetSocketAddress address = new InetSocketAddress("localhost", port);
serverBuilder = NettyServerBuilder.forAddress(address, serverCreds);
channelBuilder = OkHttpChannelBuilder.forAddress("localhost", port, InsecureChannelCredentials.create());
break;
}
default:
throw new Exception("Unknown transport: " + transport);
}
if (direct) {
serverBuilder.directExecutor();
// Because blocking stubs avoid the executor, this doesn't do much.
channelBuilder.directExecutor();
}
server = serverBuilder.addService(new AsyncServer.BenchmarkServiceImpl()).build();
server.start();
channel = channelBuilder.build();
stub = BenchmarkServiceGrpc.newBlockingStub(channel);
asyncStub = BenchmarkServiceGrpc.newStub(channel);
// Wait for channel to start
stub.unaryCall(SimpleRequest.getDefaultInstance());
}
use of io.grpc.ServerCredentials in project grpc-java by grpc.
the class AdvancedTlsTest method advancedTlsKeyManagerTrustManagerMutualTlsTest.
@Test
public void advancedTlsKeyManagerTrustManagerMutualTlsTest() throws Exception {
// Create a server with the key manager and trust manager.
AdvancedTlsX509KeyManager serverKeyManager = new AdvancedTlsX509KeyManager();
serverKeyManager.updateIdentityCredentials(serverKey0, serverCert0);
AdvancedTlsX509TrustManager serverTrustManager = AdvancedTlsX509TrustManager.newBuilder().setVerification(Verification.CERTIFICATE_ONLY_VERIFICATION).build();
serverTrustManager.updateTrustCredentials(caCert);
ServerCredentials serverCredentials = TlsServerCredentials.newBuilder().keyManager(serverKeyManager).trustManager(serverTrustManager).clientAuth(ClientAuth.REQUIRE).build();
server = Grpc.newServerBuilderForPort(0, serverCredentials).addService(new SimpleServiceImpl()).build().start();
// Create a client with the key manager and trust manager.
AdvancedTlsX509KeyManager clientKeyManager = new AdvancedTlsX509KeyManager();
clientKeyManager.updateIdentityCredentials(clientKey0, clientCert0);
AdvancedTlsX509TrustManager clientTrustManager = AdvancedTlsX509TrustManager.newBuilder().setVerification(Verification.CERTIFICATE_AND_HOST_NAME_VERIFICATION).build();
clientTrustManager.updateTrustCredentials(caCert);
ChannelCredentials channelCredentials = TlsChannelCredentials.newBuilder().keyManager(clientKeyManager).trustManager(clientTrustManager).build();
channel = Grpc.newChannelBuilderForAddress("localhost", server.getPort(), channelCredentials).overrideAuthority("foo.test.google.com.au").build();
// Start the connection.
try {
SimpleServiceGrpc.SimpleServiceBlockingStub client = SimpleServiceGrpc.newBlockingStub(channel);
client.unaryRpc(SimpleRequest.getDefaultInstance());
} catch (StatusRuntimeException e) {
fail("Failed to make a connection");
e.printStackTrace();
}
}
Aggregations