Search in sources :

Example 1 with ConnectionSpec

use of com.squareup.okhttp.ConnectionSpec in project grpc-java by grpc.

the class Http2OkHttpTest method wrongHostNameFailHostnameVerification.

@Test(timeout = 10000)
public void wrongHostNameFailHostnameVerification() throws Exception {
    OkHttpChannelBuilder builder = OkHttpChannelBuilder.forAddress("127.0.0.1", getPort()).connectionSpec(new ConnectionSpec.Builder(OkHttpChannelBuilder.DEFAULT_CONNECTION_SPEC).cipherSuites(TestUtils.preferredTestCiphers().toArray(new String[0])).tlsVersions(ConnectionSpec.MODERN_TLS.tlsVersions().toArray(new TlsVersion[0])).build()).overrideAuthority(GrpcUtil.authorityFromHostAndPort("I.am.a.bad.hostname", getPort()));
    ManagedChannel channel = builder.sslSocketFactory(TestUtils.newSslSocketFactoryForCa(Platform.get().getProvider(), TestUtils.loadCert("ca.pem"))).build();
    TestServiceGrpc.TestServiceBlockingStub blockingStub = TestServiceGrpc.newBlockingStub(channel);
    try {
        blockingStub.emptyCall(Empty.getDefaultInstance());
        fail("The rpc should have been failed due to hostname verification");
    } catch (Throwable t) {
        Throwable cause = Throwables.getRootCause(t);
        assertTrue("Failed by unexpected exception: " + cause, cause instanceof SSLPeerUnverifiedException);
    }
    channel.shutdown();
}
Also used : ConnectionSpec(com.squareup.okhttp.ConnectionSpec) SSLPeerUnverifiedException(javax.net.ssl.SSLPeerUnverifiedException) ManagedChannel(io.grpc.ManagedChannel) OkHttpChannelBuilder(io.grpc.okhttp.OkHttpChannelBuilder) Test(org.junit.Test)

Example 2 with ConnectionSpec

use of com.squareup.okhttp.ConnectionSpec in project grpc-java by grpc.

the class Http2OkHttpTest method createChannel.

@Override
protected ManagedChannel createChannel() {
    OkHttpChannelBuilder builder = OkHttpChannelBuilder.forAddress("127.0.0.1", getPort()).maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE).connectionSpec(new ConnectionSpec.Builder(OkHttpChannelBuilder.DEFAULT_CONNECTION_SPEC).cipherSuites(TestUtils.preferredTestCiphers().toArray(new String[0])).tlsVersions(ConnectionSpec.MODERN_TLS.tlsVersions().toArray(new TlsVersion[0])).build()).overrideAuthority(GrpcUtil.authorityFromHostAndPort(TestUtils.TEST_SERVER_HOST, getPort()));
    io.grpc.internal.TestingAccessor.setStatsContextFactory(builder, getClientStatsFactory());
    try {
        builder.sslSocketFactory(TestUtils.newSslSocketFactoryForCa(Platform.get().getProvider(), TestUtils.loadCert("ca.pem")));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return builder.build();
}
Also used : ConnectionSpec(com.squareup.okhttp.ConnectionSpec) IOException(java.io.IOException) SSLPeerUnverifiedException(javax.net.ssl.SSLPeerUnverifiedException) OkHttpChannelBuilder(io.grpc.okhttp.OkHttpChannelBuilder)

Aggregations

ConnectionSpec (com.squareup.okhttp.ConnectionSpec)2 OkHttpChannelBuilder (io.grpc.okhttp.OkHttpChannelBuilder)2 SSLPeerUnverifiedException (javax.net.ssl.SSLPeerUnverifiedException)2 ManagedChannel (io.grpc.ManagedChannel)1 IOException (java.io.IOException)1 Test (org.junit.Test)1