Skip to content

Commit b24a605

Browse files
committed
Address review comments.
1 parent c0327b5 commit b24a605

File tree

8 files changed

+321
-269
lines changed

8 files changed

+321
-269
lines changed

netty/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ tasks.named("jar").configure {
1818
dependencies {
1919
api project(':grpc-api'),
2020
libraries.netty.codec.http2
21-
implementation project(':grpc-core'),
21+
implementation project(':grpc-core'),
2222
libs.netty.handler.proxy,
2323
libraries.guava,
2424
libraries.errorprone.annotations,

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

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,15 @@
6060
import io.netty.util.concurrent.GenericFutureListener;
6161
import java.net.SocketAddress;
6262
import java.nio.channels.ClosedChannelException;
63-
import java.security.cert.CertificateException;
6463
import java.util.Map;
6564
import java.util.concurrent.Executor;
6665
import java.util.concurrent.TimeUnit;
67-
import java.util.logging.Level;
68-
import java.util.logging.Logger;
6966
import javax.annotation.Nullable;
70-
import javax.net.ssl.SSLPeerUnverifiedException;
7167

7268
/**
7369
* A Netty-based {@link ConnectionClientTransport} implementation.
7470
*/
7571
class NettyClientTransport implements ConnectionClientTransport {
76-
private static final Logger logger = Logger.getLogger(NettyClientTransport.class.getName());
7772

7873
private final InternalLogId logId;
7974
private final Map<ChannelOption<?>, ?> channelOptions;
@@ -199,26 +194,11 @@ public ClientStream newStream(
199194
if (channel == null) {
200195
return new FailingClientStream(statusExplainingWhyTheChannelIsNull, tracers);
201196
}
202-
try {
203-
if (callOptions.getAuthority() != null && !negotiator.mayBeVerifyAuthority(
204-
callOptions.getAuthority())) {
205-
String errMsg = String.format("Peer hostname verification failed for authority '%s'.",
206-
callOptions.getAuthority());
207-
logger.log(Level.FINE, errMsg);
208-
return new FailingClientStream(Status.INTERNAL.withDescription(errMsg), tracers);
197+
if (callOptions.getAuthority() != null) {
198+
Status verificationStatus = negotiator.verifyAuthority(callOptions.getAuthority());
199+
if (verificationStatus != Status.OK) {
200+
return new FailingClientStream(verificationStatus, tracers);
209201
}
210-
} catch (UnsupportedOperationException ex) {
211-
logger.log(Level.FINE,
212-
"Can't allow authority override in rpc when X509ExtendedTrustManager is not available.",
213-
callOptions.getAuthority());
214-
return new FailingClientStream(Status.INTERNAL.withDescription(
215-
"Can't allow authority override in rpc when X509ExtendedTrustManager is not available"),
216-
tracers);
217-
} catch (SSLPeerUnverifiedException | CertificateException ex) {
218-
String errMsg = String.format("Peer hostname verification failed for authority '%s'.",
219-
callOptions.getAuthority());
220-
logger.log(Level.FINE, errMsg, ex);
221-
return new FailingClientStream(Status.INTERNAL.withDescription(errMsg), tracers);
222202
}
223203
StatsTraceContext statsTraceCtx =
224204
StatsTraceContext.newClientContext(tracers, getAttributes(), headers);
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
/*
2+
* Copyright 2024 The gRPC Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.grpc.netty;
18+
19+
import java.nio.ByteBuffer;
20+
import javax.net.ssl.SSLEngine;
21+
import javax.net.ssl.SSLEngineResult;
22+
import javax.net.ssl.SSLException;
23+
import javax.net.ssl.SSLSession;
24+
25+
/**
26+
* A no-op implementation of SslEngine, to facilitate overriding only the required methods in
27+
* specific implementations.
28+
*/
29+
public class NoopSslEngine extends SSLEngine {
30+
@Override
31+
public SSLEngineResult wrap(ByteBuffer[] srcs, int offset, int length, ByteBuffer dst)
32+
throws SSLException {
33+
return null;
34+
}
35+
36+
@Override
37+
public SSLEngineResult unwrap(ByteBuffer src, ByteBuffer[] dsts, int offset, int length)
38+
throws SSLException {
39+
return null;
40+
}
41+
42+
@Override
43+
public Runnable getDelegatedTask() {
44+
return null;
45+
}
46+
47+
@Override
48+
public void closeInbound() throws SSLException {
49+
50+
}
51+
52+
@Override
53+
public boolean isInboundDone() {
54+
return false;
55+
}
56+
57+
@Override
58+
public void closeOutbound() {
59+
60+
}
61+
62+
@Override
63+
public boolean isOutboundDone() {
64+
return false;
65+
}
66+
67+
@Override
68+
public String[] getSupportedCipherSuites() {
69+
return new String[0];
70+
}
71+
72+
@Override
73+
public String[] getEnabledCipherSuites() {
74+
return new String[0];
75+
}
76+
77+
@Override
78+
public void setEnabledCipherSuites(String[] suites) {
79+
80+
}
81+
82+
@Override
83+
public String[] getSupportedProtocols() {
84+
return new String[0];
85+
}
86+
87+
@Override
88+
public String[] getEnabledProtocols() {
89+
return new String[0];
90+
}
91+
92+
@Override
93+
public void setEnabledProtocols(String[] protocols) {
94+
95+
}
96+
97+
@Override
98+
public SSLSession getSession() {
99+
return null;
100+
}
101+
102+
@Override
103+
public void beginHandshake() throws SSLException {
104+
105+
}
106+
107+
@Override
108+
public SSLEngineResult.HandshakeStatus getHandshakeStatus() {
109+
return null;
110+
}
111+
112+
@Override
113+
public void setUseClientMode(boolean mode) {
114+
115+
}
116+
117+
@Override
118+
public boolean getUseClientMode() {
119+
return false;
120+
}
121+
122+
@Override
123+
public void setNeedClientAuth(boolean need) {
124+
125+
}
126+
127+
@Override
128+
public boolean getNeedClientAuth() {
129+
return false;
130+
}
131+
132+
@Override
133+
public void setWantClientAuth(boolean want) {
134+
135+
}
136+
137+
@Override
138+
public boolean getWantClientAuth() {
139+
return false;
140+
}
141+
142+
@Override
143+
public void setEnableSessionCreation(boolean flag) {
144+
145+
}
146+
147+
@Override
148+
public boolean getEnableSessionCreation() {
149+
return false;
150+
}
151+
}
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/*
2+
* Copyright 2024 The gRPC Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.grpc.netty;
18+
19+
import java.security.Principal;
20+
import java.security.cert.Certificate;
21+
import javax.net.ssl.SSLPeerUnverifiedException;
22+
import javax.net.ssl.SSLSession;
23+
import javax.net.ssl.SSLSessionContext;
24+
25+
/** A no-op ssl session, to facilitate overriding only the required methods in specific
26+
* implementations.
27+
*/
28+
class NoopSslSession implements SSLSession {
29+
@Override
30+
public byte[] getId() {
31+
return new byte[0];
32+
}
33+
34+
@Override
35+
public SSLSessionContext getSessionContext() {
36+
return null;
37+
}
38+
39+
@Override
40+
@SuppressWarnings("deprecation")
41+
public javax.security.cert.X509Certificate[] getPeerCertificateChain() {
42+
throw new UnsupportedOperationException("This method is deprecated and marked for removal. "
43+
+ "Use the getPeerCertificates() method instead.");
44+
}
45+
46+
@Override
47+
public long getCreationTime() {
48+
return 0;
49+
}
50+
51+
@Override
52+
public long getLastAccessedTime() {
53+
return 0;
54+
}
55+
56+
@Override
57+
public void invalidate() {
58+
}
59+
60+
@Override
61+
public boolean isValid() {
62+
return false;
63+
}
64+
65+
@Override
66+
public void putValue(String s, Object o) {
67+
}
68+
69+
@Override
70+
public Object getValue(String s) {
71+
return null;
72+
}
73+
74+
@Override
75+
public void removeValue(String s) {
76+
}
77+
78+
@Override
79+
public String[] getValueNames() {
80+
return new String[0];
81+
}
82+
83+
@Override
84+
public Certificate[] getPeerCertificates() throws SSLPeerUnverifiedException {
85+
return new Certificate[0];
86+
}
87+
88+
@Override
89+
public Certificate[] getLocalCertificates() {
90+
return new Certificate[0];
91+
}
92+
93+
@Override
94+
public Principal getPeerPrincipal() throws SSLPeerUnverifiedException {
95+
return null;
96+
}
97+
98+
@Override
99+
public Principal getLocalPrincipal() {
100+
return null;
101+
}
102+
103+
@Override
104+
public String getCipherSuite() {
105+
return null;
106+
}
107+
108+
@Override
109+
public String getProtocol() {
110+
return null;
111+
}
112+
113+
@Override
114+
public String getPeerHost() {
115+
return null;
116+
}
117+
118+
@Override
119+
public int getPeerPort() {
120+
return 0;
121+
}
122+
123+
@Override
124+
public int getPacketBufferSize() {
125+
return 0;
126+
}
127+
128+
@Override
129+
public int getApplicationBufferSize() {
130+
return 0;
131+
}
132+
}

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@
1616

1717
package io.grpc.netty;
1818

19+
import io.grpc.Status;
1920
import io.grpc.internal.ObjectPool;
2021
import io.netty.channel.ChannelHandler;
2122
import io.netty.util.AsciiString;
22-
import java.security.cert.CertificateException;
2323
import java.util.concurrent.Executor;
24-
import javax.net.ssl.SSLPeerUnverifiedException;
2524

2625
/**
2726
* An class that provides a Netty handler to control protocol negotiation.
@@ -68,13 +67,8 @@ interface ServerFactory {
6867

6968
/**
7069
* Verify the authority against peer if applicable depending on the transport credential type.
71-
* @throws UnsupportedOperationException if the verification should happen but the required
72-
* type of TrustManager could not be found.
73-
* @throws SSLPeerUnverifiedException if peer verification failed
74-
* @throws CertificateException if certificates have a problem
7570
*/
76-
default boolean mayBeVerifyAuthority(String authority)
77-
throws SSLPeerUnverifiedException, CertificateException {
78-
return true;
71+
default Status verifyAuthority(String authority) {
72+
return Status.UNAVAILABLE;
7973
}
8074
}

0 commit comments

Comments
 (0)