Search in sources :

Example 1 with ServerCredentials

use of io.grpc.ServerCredentials in project grpc-java by grpc.

the class ConcurrencyTest method newServer.

/**
 * Creates and starts a new {@link TestServiceImpl} server.
 */
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().keyManager(serverCertChainFile, serverPrivateKeyFile).trustManager(serverTrustedCaCerts).clientAuth(TlsServerCredentials.ClientAuth.REQUIRE).build();
    return Grpc.newServerBuilderForPort(0, serverCreds).addService(new TestServiceImpl(serverExecutor)).build().start();
}
Also used : TlsServerCredentials(io.grpc.TlsServerCredentials) ServerCredentials(io.grpc.ServerCredentials) File(java.io.File)

Example 2 with ServerCredentials

use of io.grpc.ServerCredentials in project grpc-java by grpc.

the class Http2NettyTest method getServerBuilder.

@Override
protected ServerBuilder<?> getServerBuilder() {
    // Starts the server with HTTPS.
    try {
        ServerCredentials serverCreds = TlsServerCredentials.newBuilder().keyManager(TestUtils.loadCert("server1.pem"), TestUtils.loadCert("server1.key")).trustManager(TestUtils.loadCert("ca.pem")).clientAuth(TlsServerCredentials.ClientAuth.REQUIRE).build();
        NettyServerBuilder builder = NettyServerBuilder.forPort(0, serverCreds).flowControlWindow(AbstractInteropTest.TEST_FLOW_CONTROL_WINDOW).maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE);
        // Disable the default census stats tracer, use testing tracer instead.
        InternalNettyServerBuilder.setStatsEnabled(builder, false);
        return builder.addStreamTracerFactory(createCustomCensusTracerFactory());
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
}
Also used : NettyServerBuilder(io.grpc.netty.NettyServerBuilder) InternalNettyServerBuilder(io.grpc.netty.InternalNettyServerBuilder) ServerCredentials(io.grpc.ServerCredentials) TlsServerCredentials(io.grpc.TlsServerCredentials) IOException(java.io.IOException)

Example 3 with ServerCredentials

use of io.grpc.ServerCredentials in project grpc-java by grpc.

the class TestServiceServer method start.

@VisibleForTesting
void start() throws Exception {
    executor = Executors.newSingleThreadScheduledExecutor();
    ServerCredentials serverCreds;
    if (useAlts) {
        if (localHandshakerPort > -1) {
            serverCreds = AltsServerCredentials.newBuilder().enableUntrustedAltsForTesting().setHandshakerAddressForTesting("localhost:" + localHandshakerPort).build();
        } else {
            serverCreds = AltsServerCredentials.create();
        }
    } else if (useTls) {
        serverCreds = TlsServerCredentials.create(TestUtils.loadCert("server1.pem"), TestUtils.loadCert("server1.key"));
    } else {
        serverCreds = InsecureServerCredentials.create();
    }
    server = Grpc.newServerBuilderForPort(port, serverCreds).maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE).addService(ServerInterceptors.intercept(new TestServiceImpl(executor), TestServiceImpl.interceptors())).build().start();
}
Also used : ServerCredentials(io.grpc.ServerCredentials) AltsServerCredentials(io.grpc.alts.AltsServerCredentials) InsecureServerCredentials(io.grpc.InsecureServerCredentials) TlsServerCredentials(io.grpc.TlsServerCredentials) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 4 with ServerCredentials

use of io.grpc.ServerCredentials in project grpc-java by grpc.

the class ProtocolNegotiatorsTest method fromServer_choice.

@Test
public void fromServer_choice() throws Exception {
    ProtocolNegotiators.FromServerCredentialsResult result = ProtocolNegotiators.from(ChoiceServerCredentials.create(new ServerCredentials() {
    }, TlsServerCredentials.create(server1Cert, server1Key), InsecureServerCredentials.create()));
    assertThat(result.error).isNull();
    assertThat(result.negotiator).isInstanceOf(ProtocolNegotiators.TlsProtocolNegotiatorServerFactory.class);
    result = ProtocolNegotiators.from(ChoiceServerCredentials.create(InsecureServerCredentials.create(), new ServerCredentials() {
    }, TlsServerCredentials.create(server1Cert, server1Key)));
    assertThat(result.error).isNull();
    assertThat(result.negotiator).isInstanceOf(ProtocolNegotiators.PlaintextProtocolNegotiatorServerFactory.class);
}
Also used : InsecureServerCredentials(io.grpc.InsecureServerCredentials) TlsServerCredentials(io.grpc.TlsServerCredentials) ChoiceServerCredentials(io.grpc.ChoiceServerCredentials) ServerCredentials(io.grpc.ServerCredentials) Test(org.junit.Test)

Example 5 with ServerCredentials

use of io.grpc.ServerCredentials in project grpc-java by grpc.

the class ProtocolNegotiatorsTest method from_tls_clientAuthOptional_noClientCert.

@Test
public void from_tls_clientAuthOptional_noClientCert() throws Exception {
    ServerCredentials serverCreds = TlsServerCredentials.newBuilder().keyManager(server1Cert, server1Key).trustManager(caCert).clientAuth(TlsServerCredentials.ClientAuth.OPTIONAL).build();
    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)

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