use of io.grpc.ChannelCredentials in project grpc-java by grpc.
the class Utils method newClientChannel.
/**
* Create a {@link ManagedChannel} for the given parameters.
*/
public static ManagedChannel newClientChannel(Transport transport, String target, boolean tls, boolean testca, @Nullable String authorityOverride, int flowControlWindow, boolean directExecutor) {
ChannelCredentials credentials;
if (tls) {
if (testca) {
try {
credentials = TlsChannelCredentials.newBuilder().trustManager(TlsTesting.loadCert("ca.pem")).build();
} catch (IOException ex) {
throw new RuntimeException(ex);
}
} else {
credentials = TlsChannelCredentials.create();
}
} else {
credentials = InsecureChannelCredentials.create();
}
ManagedChannelBuilder<?> builder;
if (transport == Transport.OK_HTTP) {
builder = OkHttpChannelBuilder.forTarget(target, credentials).flowControlWindow(flowControlWindow);
} else {
if (target.startsWith(UNIX_DOMAIN_SOCKET_PREFIX)) {
builder = configureNetty(NettyChannelBuilder.forAddress(parseUnixSocketAddress(target), credentials), transport, flowControlWindow);
} else {
builder = configureNetty(NettyChannelBuilder.forTarget(target, credentials), transport, flowControlWindow);
}
}
if (authorityOverride != null) {
builder.overrideAuthority(authorityOverride);
}
if (directExecutor) {
builder.directExecutor();
} else {
// TODO(carl-mastrangelo): This should not be necessary. I don't know where this should be
// put. Move it somewhere else, or remove it if no longer necessary.
// See: https://github.com/grpc/grpc-java/issues/2119
builder.executor(getExecutor());
}
return builder.build();
}
use of io.grpc.ChannelCredentials 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();
}
use of io.grpc.ChannelCredentials in project grpc-java by grpc.
the class ProtocolNegotiatorsTest method fromClient_choice.
@Test
public void fromClient_choice() {
ProtocolNegotiators.FromChannelCredentialsResult result = ProtocolNegotiators.from(ChoiceChannelCredentials.create(new ChannelCredentials() {
@Override
public ChannelCredentials withoutBearerTokens() {
throw new UnsupportedOperationException();
}
}, TlsChannelCredentials.create(), InsecureChannelCredentials.create()));
assertThat(result.error).isNull();
assertThat(result.callCredentials).isNull();
assertThat(result.negotiator).isInstanceOf(ProtocolNegotiators.TlsProtocolNegotiatorClientFactory.class);
result = ProtocolNegotiators.from(ChoiceChannelCredentials.create(InsecureChannelCredentials.create(), new ChannelCredentials() {
@Override
public ChannelCredentials withoutBearerTokens() {
throw new UnsupportedOperationException();
}
}, TlsChannelCredentials.create()));
assertThat(result.error).isNull();
assertThat(result.callCredentials).isNull();
assertThat(result.negotiator).isInstanceOf(ProtocolNegotiators.PlaintextProtocolNegotiatorClientFactory.class);
}
use of io.grpc.ChannelCredentials 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.ChannelCredentials 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();
}
Aggregations