Search in sources :

Example 6 with ChannelCredentials

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();
}
Also used : InsecureChannelCredentials(io.grpc.InsecureChannelCredentials) ChannelCredentials(io.grpc.ChannelCredentials) TlsChannelCredentials(io.grpc.TlsChannelCredentials) IOException(java.io.IOException)

Example 7 with ChannelCredentials

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

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

Example 9 with ChannelCredentials

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();
}
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 10 with ChannelCredentials

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

ChannelCredentials (io.grpc.ChannelCredentials)35 TlsChannelCredentials (io.grpc.TlsChannelCredentials)28 Test (org.junit.Test)24 InsecureChannelCredentials (io.grpc.InsecureChannelCredentials)22 CompositeChannelCredentials (io.grpc.CompositeChannelCredentials)18 ChoiceChannelCredentials (io.grpc.ChoiceChannelCredentials)16 ServerCredentials (io.grpc.ServerCredentials)14 TlsServerCredentials (io.grpc.TlsServerCredentials)14 InsecureServerCredentials (io.grpc.InsecureServerCredentials)8 ChoiceServerCredentials (io.grpc.ChoiceServerCredentials)7 InternalChannelz (io.grpc.InternalChannelz)6 StatusRuntimeException (io.grpc.StatusRuntimeException)6 SimpleServiceGrpc (io.grpc.testing.protobuf.SimpleServiceGrpc)6 AdvancedTlsX509KeyManager (io.grpc.util.AdvancedTlsX509KeyManager)5 AdvancedTlsX509TrustManager (io.grpc.util.AdvancedTlsX509TrustManager)5 SelfSignedCertificate (io.netty.handler.ssl.util.SelfSignedCertificate)3 KeyStore (java.security.KeyStore)3 KeyManagerFactory (javax.net.ssl.KeyManagerFactory)3 SSLContext (javax.net.ssl.SSLContext)3 ManagedChannel (io.grpc.ManagedChannel)2