Skip to content

Commit 0152478

Browse files
committed
Authority verify in Netty transport.
1 parent f31b8bc commit 0152478

File tree

3 files changed

+14
-42
lines changed

3 files changed

+14
-42
lines changed

examples/example-tls/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def protocVersion = '3.25.5'
3030
dependencies {
3131
implementation "io.grpc:grpc-protobuf:${grpcVersion}"
3232
implementation "io.grpc:grpc-stub:${grpcVersion}"
33+
implementation "io.grpc:grpc-api:${grpcVersion}"
3334
compileOnly "org.apache.tomcat:annotations-api:6.0.53"
3435
runtimeOnly "io.grpc:grpc-netty-shaded:${grpcVersion}"
3536
}

netty/src/main/java/io/grpc/netty/ProtocolNegotiators.java

Lines changed: 12 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,6 @@ protected void userEventTriggered0(ChannelHandlerContext ctx, Object evt) throws
602602
static final class ClientTlsProtocolNegotiator implements ProtocolNegotiator {
603603

604604
private SSLEngine sslEngine;
605-
private SSLSession sslHandshakeSession;
606605

607606
public ClientTlsProtocolNegotiator(SslContext sslContext,
608607
ObjectPool<? extends Executor> executorPool, Optional<Runnable> handshakeCompleteRunnable,
@@ -664,7 +663,6 @@ public void verifyAuthorityAllowedForPeerCert(String authority)
664663

665664
public void setSslEngine(SSLEngine sslEngine) {
666665
this.sslEngine = sslEngine;
667-
this.sslHandshakeSession = sslEngine.getHandshakeSession();
668666
}
669667
}
670668

@@ -1223,13 +1221,7 @@ public String getPeerHost() {
12231221

12241222
@Override
12251223
public SSLSession getHandshakeSession() {
1226-
List<byte[]> statusResponses;
1227-
if (sslEngine.getHandshakeSession() instanceof ExtendedSSLSession) {
1228-
statusResponses = ((ExtendedSSLSession) sslEngine.getHandshakeSession()).getStatusResponses();
1229-
} else {
1230-
statusResponses = Collections.<byte[]>emptyList();
1231-
}
1232-
return new FakeExtendedSSLSession(peerHost, statusResponses);
1224+
return new FakeSSLSession(peerHost);
12331225
}
12341226

12351227
@Override
@@ -1360,54 +1352,28 @@ public boolean getEnableSessionCreation() {
13601352
}
13611353
}
13621354

1363-
static class FakeExtendedSSLSession extends ExtendedSSLSession {
1355+
static class FakeSSLSession implements SSLSession {
13641356
private final String peerHost;
1365-
private final List<byte[]> statusResponses;
13661357

1367-
FakeExtendedSSLSession(String peerHost, List<byte[]> statusResponses) {
1358+
FakeSSLSession(String peerHost) {
13681359
this.peerHost = peerHost;
1369-
this.statusResponses = statusResponses;
13701360
}
13711361

13721362
@Override
1373-
public String getPeerHost() {
1374-
return peerHost;
1363+
public byte[] getId() {
1364+
return new byte[0];
13751365
}
13761366

13771367
@Override
1378-
public List<SNIServerName> getRequestedServerNames() {
1379-
return Collections.<SNIServerName>emptyList();
1380-
}
1381-
1382-
public List<byte[]> getStatusResponses() {
1383-
return statusResponses;
1368+
public SSLSessionContext getSessionContext() {
1369+
return null;
13841370
}
13851371

13861372
@Override
13871373
public javax.security.cert.X509Certificate[] getPeerCertificateChain() throws SSLPeerUnverifiedException {
13881374
throw new UnsupportedOperationException("This method is deprecated and marked for removal. Use the getPeerCertificates() method instead.");
13891375
}
13901376

1391-
@Override
1392-
public String[] getLocalSupportedSignatureAlgorithms() {
1393-
return new String[0];
1394-
}
1395-
1396-
@Override
1397-
public String[] getPeerSupportedSignatureAlgorithms() {
1398-
return new String[0];
1399-
}
1400-
1401-
@Override
1402-
public byte[] getId() {
1403-
return new byte[0];
1404-
}
1405-
1406-
@Override
1407-
public SSLSessionContext getSessionContext() {
1408-
return null;
1409-
}
1410-
14111377
@Override
14121378
public long getCreationTime() {
14131379
return 0;
@@ -1478,6 +1444,11 @@ public String getProtocol() {
14781444
return null;
14791445
}
14801446

1447+
@Override
1448+
public String getPeerHost() {
1449+
return peerHost;
1450+
}
1451+
14811452
@Override
14821453
public int getPeerPort() {
14831454
return 0;

netty/src/test/java/io/grpc/netty/NettyClientTransportTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ private static class Rpc {
951951

952952
Rpc(NettyClientTransport transport, Metadata headers) {
953953
stream = transport.newStream(
954-
METHOD, headers, CallOptions.DEFAULT,
954+
METHOD, headers, CallOptions.DEFAULT.withAuthority("wrong-authority"),
955955
new ClientStreamTracer[]{ new ClientStreamTracer() {} });
956956
stream.start(listener);
957957
stream.request(1);

0 commit comments

Comments
 (0)