Skip to content

HostnameVerifier exists in OkHttpChannelBuilder, but not exists in NettyChannelBuilder #12039

@becomeStar

Description

@becomeStar

Hello. I have a question about hostname verification using ssl protocol in grpc-java.
In test environment, I needed to use InsecureTrustManagerFactory.INSTANCE
when building ManagedChannel to avoid certification verification.
When I use nettyChannelBuilder in client side, hostname check seems not to execute if I set below option

this.channel = NettyChannelBuilder.forAddress("localhost", 443)
                                                            .sslContext(GrpcSslContexts.forClient()
                                                                            .trustManager(InsecureTrustManagerFactory.INSTANCE)
                                                                            .build())
                                                             .build();

But when I use OkHttpChannelBuilder in client side, hostname check seems to execute automatically even if I use InsecureTrustManagerFactory.INSTANCE like below

SSLContext context = SSLContext.getInstance("TLS");
context.init(null, InsecureTrustManagerFactory.INSTANCE.getTrustManagers() , null);

this.channel = OkHttpChannelBuilder.forAddress("localhost", 443)
        .sslSocketFactory(context.getSocketFactory())
        .build();

I confirmed that hostname check would not be executed when I overrode hostnameVerifier like below.

this.channel = OkHttpChannelBuilder.forAddress("localhost", 443)
        .sslSocketFactory(context.getSocketFactory())
        .hostnameVerifier((hostname, session) -> true)
        .build();

OkHttpTlsUpgrader.java

if (!hostnameVerifier.verify(canonicalizeHost(host), sslSocket.getSession())) {
  throw new SSLPeerUnverifiedException("Cannot verify hostname: " + host);
}

When using InsecureTrustManagerFactory.INSTANCE to avoid certification verification, hostname check works in okhttp channel, but not works in netty channel. I wonder if there is a need to match the same standards.

There will be two options like below

(1) hostname check is executed regardless of InsecureTrustManagerFactory.INSTANCE when building channel using NettyChannelBuilder

(2) hostname check isn’t executed if InsecureTrustManagerFactory.INSTANCE is used when building channel using OkHttpChannelBuilder

Thank you for reading. If I have misunderstood anything, please let me know.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions