|
63 | 63 | import java.nio.channels.ClosedChannelException; |
64 | 64 | import java.security.cert.CertificateException; |
65 | 65 | import java.util.Map; |
| 66 | +import java.util.concurrent.ConcurrentHashMap; |
66 | 67 | import java.util.concurrent.Executor; |
67 | 68 | import java.util.concurrent.TimeUnit; |
68 | 69 | import java.util.logging.Level; |
@@ -111,6 +112,7 @@ class NettyClientTransport implements ConnectionClientTransport { |
111 | 112 | private final ChannelLogger channelLogger; |
112 | 113 | private final boolean useGetForSafeMethods; |
113 | 114 | private final Ticker ticker; |
| 115 | + private final ConcurrentHashMap<String, Boolean> authoritiesAllowedForPeer = new ConcurrentHashMap<>(); |
114 | 116 |
|
115 | 117 | NettyClientTransport( |
116 | 118 | SocketAddress address, |
@@ -208,11 +210,21 @@ public ClientStream newStream( |
208 | 210 | "Can't allow authority override in rpc when X509ExtendedTrustManager is not available"), |
209 | 211 | tracers); |
210 | 212 | } |
211 | | - try { |
212 | | - clientTlsProtocolNegotiator.verifyAuthorityAllowedForPeerCert(callOptions.getAuthority()); |
213 | | - } catch (SSLPeerUnverifiedException | CertificateException e) { |
214 | | - logger.log(Level.FINE, "Peer hostname verification failed for authority '{}'.", |
215 | | - callOptions.getAuthority()); |
| 213 | + boolean peerVerified; |
| 214 | + if (authoritiesAllowedForPeer.containsKey(callOptions.getAuthority())) { |
| 215 | + peerVerified = authoritiesAllowedForPeer.get(callOptions.getAuthority()); |
| 216 | + } else { |
| 217 | + try { |
| 218 | + clientTlsProtocolNegotiator.verifyAuthorityAllowedForPeerCert(callOptions.getAuthority()); |
| 219 | + peerVerified = true; |
| 220 | + } catch (SSLPeerUnverifiedException | CertificateException e) { |
| 221 | + peerVerified = false; |
| 222 | + logger.log(Level.FINE, "Peer hostname verification failed for authority '{}'.", |
| 223 | + callOptions.getAuthority()); |
| 224 | + } |
| 225 | + authoritiesAllowedForPeer.put(callOptions.getAuthority(), peerVerified); |
| 226 | + } |
| 227 | + if (!peerVerified) { |
216 | 228 | return new FailingClientStream(Status.INTERNAL.withDescription( |
217 | 229 | "Peer hostname verification failed for authority"), tracers); |
218 | 230 | } |
|
0 commit comments