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();
}
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);
}
}
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();
}
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);
}
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();
}
Aggregations