Skip to content

Commit 5fb58fe

Browse files
Only check ALPN if TLS extensions are enabled
1 parent d2729db commit 5fb58fe

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

okhttp/src/main/java/io/grpc/okhttp/TlsServerHandshakerSocketFactory.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,16 @@ public HandshakeResult handshake(Socket socket, Attributes attributes) throws IO
5555
SSLSocket sslSocket = (SSLSocket) socket;
5656
sslSocket.setUseClientMode(false);
5757
connectionSpec.apply(sslSocket, false);
58-
Protocol expectedProtocol = Protocol.HTTP_2;
59-
String negotiatedProtocol = OkHttpProtocolNegotiator.get().negotiate(
60-
sslSocket,
61-
null,
62-
connectionSpec.supportsTlsExtensions() ? Collections.singletonList(expectedProtocol) : null);
63-
if (!expectedProtocol.toString().equals(negotiatedProtocol)) {
64-
throw new IOException("Expected NPN/ALPN " + expectedProtocol + ": " + negotiatedProtocol);
58+
if (connectionSpec.supportsTlsExtensions()) {
59+
Protocol expectedProtocol = Protocol.HTTP_2;
60+
String negotiatedProtocol = OkHttpProtocolNegotiator.get().negotiate(
61+
sslSocket,
62+
null,
63+
Collections.singletonList(expectedProtocol)
64+
);
65+
if (!expectedProtocol.toString().equals(negotiatedProtocol)) {
66+
throw new IOException("Expected NPN/ALPN " + expectedProtocol + ": " + negotiatedProtocol);
67+
}
6568
}
6669
attributes = result.attributes.toBuilder()
6770
.set(GrpcAttributes.ATTR_SECURITY_LEVEL, SecurityLevel.PRIVACY_AND_INTEGRITY)

0 commit comments

Comments
 (0)