@Override protected ManagedChannel createChannel() { try { final int port = server.getPort(); return OkHttpChannelBuilder .forAddress("localhost", port) .negotiationType(NegotiationType.TLS) .maxInboundMessageSize(16 * 1024 * 1024) .connectionSpec(ConnectionSpec.MODERN_TLS) .overrideAuthority("example.com:" + port) .sslSocketFactory(TestUtils.newSslSocketFactoryForCa( Platform.get().getProvider(), ssc.certificate())) .build(); } catch (Exception ex) { throw new RuntimeException(ex); } }
public static ManagedChannel build(String host, int port, @Nullable String serverHostOverride, boolean useTls, @Nullable InputStream testCa, @Nullable String androidSocketFactoryTls) { ManagedChannelBuilder<?> channelBuilder = ManagedChannelBuilder.forAddress(host, port) .maxInboundMessageSize(16 * 1024 * 1024); if (serverHostOverride != null) { // Force the hostname to match the cert the server uses. channelBuilder.overrideAuthority(serverHostOverride); } if (useTls) { try { SSLSocketFactory factory; if (androidSocketFactoryTls != null) { factory = getSslCertificateSocketFactory(testCa, androidSocketFactoryTls); } else { factory = getSslSocketFactory(testCa); } ((OkHttpChannelBuilder) channelBuilder).negotiationType(NegotiationType.TLS); ((OkHttpChannelBuilder) channelBuilder).sslSocketFactory(factory); } catch (Exception e) { throw new RuntimeException(e); } } else { channelBuilder.usePlaintext(true); } return channelBuilder.build(); }