Search in sources :

Example 6 with ServerCredentials

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();
}
Also used : InsecureServerCredentials(io.grpc.InsecureServerCredentials) TlsServerCredentials(io.grpc.TlsServerCredentials) ChoiceServerCredentials(io.grpc.ChoiceServerCredentials) ServerCredentials(io.grpc.ServerCredentials) Test(org.junit.Test)

Example 7 with ServerCredentials

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();
}
Also used : InsecureServerCredentials(io.grpc.InsecureServerCredentials) TlsServerCredentials(io.grpc.TlsServerCredentials) ChoiceServerCredentials(io.grpc.ChoiceServerCredentials) ServerCredentials(io.grpc.ServerCredentials) ChoiceChannelCredentials(io.grpc.ChoiceChannelCredentials) TlsChannelCredentials(io.grpc.TlsChannelCredentials) InsecureChannelCredentials(io.grpc.InsecureChannelCredentials) ChannelCredentials(io.grpc.ChannelCredentials) CompositeChannelCredentials(io.grpc.CompositeChannelCredentials) InternalChannelz(io.grpc.InternalChannelz) Test(org.junit.Test)

Example 8 with ServerCredentials

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();
}
Also used : InsecureServerCredentials(io.grpc.InsecureServerCredentials) TlsServerCredentials(io.grpc.TlsServerCredentials) ChoiceServerCredentials(io.grpc.ChoiceServerCredentials) ServerCredentials(io.grpc.ServerCredentials) ChoiceChannelCredentials(io.grpc.ChoiceChannelCredentials) TlsChannelCredentials(io.grpc.TlsChannelCredentials) InsecureChannelCredentials(io.grpc.InsecureChannelCredentials) ChannelCredentials(io.grpc.ChannelCredentials) CompositeChannelCredentials(io.grpc.CompositeChannelCredentials) InternalChannelz(io.grpc.InternalChannelz) Test(org.junit.Test)

Example 9 with ServerCredentials

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());
}
Also used : LocalAddress(io.netty.channel.local.LocalAddress) ServerCredentials(io.grpc.ServerCredentials) InsecureServerCredentials(io.grpc.InsecureServerCredentials) InetSocketAddress(java.net.InetSocketAddress) LocalChannel(io.netty.channel.local.LocalChannel) ManagedChannel(io.grpc.ManagedChannel) LocalServerChannel(io.netty.channel.local.LocalServerChannel) LocalChannel(io.netty.channel.local.LocalChannel) ServerChannel(io.netty.channel.ServerChannel) Channel(io.netty.channel.Channel) AsyncServer(io.grpc.benchmarks.qps.AsyncServer) ByteString(com.google.protobuf.ByteString) LocalServerChannel(io.netty.channel.local.LocalServerChannel) ServerChannel(io.netty.channel.ServerChannel) DefaultEventLoopGroup(io.netty.channel.DefaultEventLoopGroup) StatusRuntimeException(io.grpc.StatusRuntimeException) EventLoopGroup(io.netty.channel.EventLoopGroup) DefaultEventLoopGroup(io.netty.channel.DefaultEventLoopGroup) Setup(org.openjdk.jmh.annotations.Setup)

Example 10 with ServerCredentials

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();
    }
}
Also used : AdvancedTlsX509KeyManager(io.grpc.util.AdvancedTlsX509KeyManager) TlsServerCredentials(io.grpc.TlsServerCredentials) ServerCredentials(io.grpc.ServerCredentials) ChannelCredentials(io.grpc.ChannelCredentials) TlsChannelCredentials(io.grpc.TlsChannelCredentials) AdvancedTlsX509TrustManager(io.grpc.util.AdvancedTlsX509TrustManager) StatusRuntimeException(io.grpc.StatusRuntimeException) SimpleServiceGrpc(io.grpc.testing.protobuf.SimpleServiceGrpc) Test(org.junit.Test)

Aggregations

ServerCredentials (io.grpc.ServerCredentials)27 TlsServerCredentials (io.grpc.TlsServerCredentials)21 InsecureServerCredentials (io.grpc.InsecureServerCredentials)16 Test (org.junit.Test)16 ChannelCredentials (io.grpc.ChannelCredentials)14 TlsChannelCredentials (io.grpc.TlsChannelCredentials)13 ChoiceServerCredentials (io.grpc.ChoiceServerCredentials)10 InsecureChannelCredentials (io.grpc.InsecureChannelCredentials)8 ChoiceChannelCredentials (io.grpc.ChoiceChannelCredentials)7 CompositeChannelCredentials (io.grpc.CompositeChannelCredentials)7 StatusRuntimeException (io.grpc.StatusRuntimeException)7 InternalChannelz (io.grpc.InternalChannelz)6 SimpleServiceGrpc (io.grpc.testing.protobuf.SimpleServiceGrpc)6 AdvancedTlsX509KeyManager (io.grpc.util.AdvancedTlsX509KeyManager)5 AdvancedTlsX509TrustManager (io.grpc.util.AdvancedTlsX509TrustManager)5 NettyServerBuilder (io.grpc.netty.NettyServerBuilder)4 InternalNettyServerBuilder (io.grpc.netty.InternalNettyServerBuilder)3 AltsServerCredentials (io.grpc.alts.AltsServerCredentials)2 SslSocketAndEnginePeerVerifier (io.grpc.util.AdvancedTlsX509TrustManager.SslSocketAndEnginePeerVerifier)2 LocalAddress (io.netty.channel.local.LocalAddress)2