Search in sources :

Example 1 with ChannelCredentials

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

the class ComputeEngineChannelCredentials method create.

/**
 * Creates credentials for Google Compute Engine. This class sets up a secure channel using ALTS
 * if applicable and using TLS as fallback.
 */
public static ChannelCredentials create() {
    ChannelCredentials nettyCredentials = InternalNettyChannelCredentials.create(createClientFactory());
    CallCredentials callCredentials;
    if (InternalCheckGcpEnvironment.isOnGcp()) {
        callCredentials = MoreCallCredentials.from(ComputeEngineCredentials.create());
    } else {
        callCredentials = new FailingCallCredentials(Status.INTERNAL.withDescription("Compute Engine Credentials can only be used on Google Cloud Platform"));
    }
    return CompositeChannelCredentials.create(nettyCredentials, callCredentials);
}
Also used : ChannelCredentials(io.grpc.ChannelCredentials) InternalNettyChannelCredentials(io.grpc.netty.InternalNettyChannelCredentials) CompositeChannelCredentials(io.grpc.CompositeChannelCredentials) CallCredentials(io.grpc.CallCredentials) MoreCallCredentials(io.grpc.auth.MoreCallCredentials)

Example 2 with ChannelCredentials

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

the class TesterOkHttpChannelBuilder method build.

public static ManagedChannel build(String host, int port, @Nullable String serverHostOverride, boolean useTls, @Nullable InputStream testCa) {
    ChannelCredentials credentials;
    if (useTls) {
        if (testCa == null) {
            credentials = TlsChannelCredentials.create();
        } else {
            try {
                credentials = TlsChannelCredentials.newBuilder().trustManager(testCa).build();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    } else {
        credentials = InsecureChannelCredentials.create();
    }
    ManagedChannelBuilder<?> channelBuilder = Grpc.newChannelBuilderForAddress(host, port, credentials).maxInboundMessageSize(16 * 1024 * 1024);
    if (!(channelBuilder instanceof OkHttpChannelBuilder)) {
        throw new RuntimeException("Did not receive an OkHttpChannelBuilder");
    }
    if (serverHostOverride != null) {
        // Force the hostname to match the cert the server uses.
        channelBuilder.overrideAuthority(serverHostOverride);
    }
    return channelBuilder.build();
}
Also used : InsecureChannelCredentials(io.grpc.InsecureChannelCredentials) TlsChannelCredentials(io.grpc.TlsChannelCredentials) ChannelCredentials(io.grpc.ChannelCredentials) OkHttpChannelBuilder(io.grpc.okhttp.OkHttpChannelBuilder)

Example 3 with ChannelCredentials

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

the class Http2NettyTest method createChannelBuilder.

@Override
protected NettyChannelBuilder createChannelBuilder() {
    try {
        ChannelCredentials channelCreds = TlsChannelCredentials.newBuilder().keyManager(TestUtils.loadCert("client.pem"), TestUtils.loadCert("client.key")).trustManager(TestUtils.loadCert("ca.pem")).build();
        NettyChannelBuilder builder = NettyChannelBuilder.forAddress("localhost", ((InetSocketAddress) getListenAddress()).getPort(), channelCreds).overrideAuthority(TestUtils.TEST_SERVER_HOST).flowControlWindow(AbstractInteropTest.TEST_FLOW_CONTROL_WINDOW).maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE);
        // Disable the default census stats interceptor, use testing interceptor instead.
        InternalNettyChannelBuilder.setStatsEnabled(builder, false);
        return builder.intercept(createCensusStatsClientInterceptor());
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
Also used : ChannelCredentials(io.grpc.ChannelCredentials) TlsChannelCredentials(io.grpc.TlsChannelCredentials) InetSocketAddress(java.net.InetSocketAddress) NettyChannelBuilder(io.grpc.netty.NettyChannelBuilder) InternalNettyChannelBuilder(io.grpc.netty.InternalNettyChannelBuilder) IOException(java.io.IOException)

Example 4 with ChannelCredentials

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

the class AltsHandshakerTest method setup.

@Before
public void setup() throws Exception {
    // create new EventLoopGroups to avoid deadlock at server side handshake negotiation, e.g.
    // happens when handshakerServer and testServer child channels are on the same eventloop.
    handshakerServer = grpcCleanup.register(NettyServerBuilder.forPort(0).bossEventLoopGroup(new NioEventLoopGroup(0, new DefaultThreadFactory("test-alts-boss"))).workerEventLoopGroup(new NioEventLoopGroup(0, new DefaultThreadFactory("test-alts-worker"))).channelType(NioServerSocketChannel.class).addService(new AltsHandshakerTestService()).build()).start();
    startAltsServer();
    ChannelCredentials channelCredentials = AltsChannelCredentials.newBuilder().enableUntrustedAltsForTesting().setHandshakerAddressForTesting("localhost:" + handshakerServer.getPort()).build();
    channel = grpcCleanup.register(Grpc.newChannelBuilderForAddress("localhost", testServer.getPort(), channelCredentials).build());
}
Also used : DefaultThreadFactory(io.netty.util.concurrent.DefaultThreadFactory) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) AltsChannelCredentials(io.grpc.alts.AltsChannelCredentials) ChannelCredentials(io.grpc.ChannelCredentials) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) Before(org.junit.Before)

Example 5 with ChannelCredentials

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

the class BootstrapperImpl method parseServerInfos.

private static List<ServerInfo> parseServerInfos(List<?> rawServerConfigs, XdsLogger logger) throws XdsInitializationException {
    logger.log(XdsLogLevel.INFO, "Configured with {0} xDS servers", rawServerConfigs.size());
    ImmutableList.Builder<ServerInfo> servers = ImmutableList.builder();
    List<Map<String, ?>> serverConfigList = JsonUtil.checkObjectList(rawServerConfigs);
    for (Map<String, ?> serverConfig : serverConfigList) {
        String serverUri = JsonUtil.getString(serverConfig, "server_uri");
        if (serverUri == null) {
            throw new XdsInitializationException("Invalid bootstrap: missing 'server_uri'");
        }
        logger.log(XdsLogLevel.INFO, "xDS server URI: {0}", serverUri);
        List<?> rawChannelCredsList = JsonUtil.getList(serverConfig, "channel_creds");
        if (rawChannelCredsList == null || rawChannelCredsList.isEmpty()) {
            throw new XdsInitializationException("Invalid bootstrap: server " + serverUri + " 'channel_creds' required");
        }
        ChannelCredentials channelCredentials = parseChannelCredentials(JsonUtil.checkObjectList(rawChannelCredsList), serverUri);
        if (channelCredentials == null) {
            throw new XdsInitializationException("Server " + serverUri + ": no supported channel credentials found");
        }
        boolean useProtocolV3 = false;
        List<String> serverFeatures = JsonUtil.getListOfStrings(serverConfig, "server_features");
        if (serverFeatures != null) {
            logger.log(XdsLogLevel.INFO, "Server features: {0}", serverFeatures);
            useProtocolV3 = serverFeatures.contains(XDS_V3_SERVER_FEATURE);
        }
        servers.add(ServerInfo.create(serverUri, channelCredentials, useProtocolV3));
    }
    return servers.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) InsecureChannelCredentials(io.grpc.InsecureChannelCredentials) GoogleDefaultChannelCredentials(io.grpc.alts.GoogleDefaultChannelCredentials) ChannelCredentials(io.grpc.ChannelCredentials) TlsChannelCredentials(io.grpc.TlsChannelCredentials) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Map(java.util.Map)

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