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