2929import com .google .common .util .concurrent .SettableFuture ;
3030import io .grpc .Attributes ;
3131import io .grpc .CallOptions ;
32+ import io .grpc .ChannelCredentials ;
3233import io .grpc .ClientStreamTracer ;
3334import io .grpc .Grpc ;
3435import io .grpc .HttpConnectProxiedSocketAddress ;
4243import io .grpc .Status ;
4344import io .grpc .Status .Code ;
4445import io .grpc .StatusException ;
46+ import io .grpc .TlsChannelCredentials ;
47+ import io .grpc .internal .ClientStream ;
4548import io .grpc .internal .ClientStreamListener .RpcProgress ;
4649import io .grpc .internal .ConnectionClientTransport ;
4750import io .grpc .internal .GrpcAttributes ;
5457import io .grpc .internal .StatsTraceContext ;
5558import io .grpc .internal .TransportTracer ;
5659import io .grpc .okhttp .ExceptionHandlingFrameWriter .TransportExceptionHandler ;
60+ import io .grpc .okhttp .OkHttpChannelBuilder .OkHttpTransportFactory ;
5761import io .grpc .okhttp .internal .ConnectionSpec ;
5862import io .grpc .okhttp .internal .Credentials ;
5963import io .grpc .okhttp .internal .StatusLine ;
8286import java .util .List ;
8387import java .util .Locale ;
8488import java .util .Map ;
89+ import java .util .Optional ;
8590import java .util .Random ;
8691import java .util .concurrent .BrokenBarrierException ;
8792import java .util .concurrent .CountDownLatch ;
99104import javax .net .ssl .SSLSession ;
100105import javax .net .ssl .SSLSocket ;
101106import javax .net .ssl .SSLSocketFactory ;
107+ import javax .net .ssl .X509ExtendedTrustManager ;
102108import okio .Buffer ;
103109import okio .BufferedSink ;
104110import okio .BufferedSource ;
@@ -114,6 +120,7 @@ class OkHttpClientTransport implements ConnectionClientTransport, TransportExcep
114120 OutboundFlowController .Transport {
115121 private static final Map <ErrorCode , Status > ERROR_CODE_TO_STATUS = buildErrorCodeToStatusMap ();
116122 private static final Logger log = Logger .getLogger (OkHttpClientTransport .class .getName ());
123+ private final ChannelCredentials channelCredentials ;
117124
118125 private static Map <ErrorCode , Status > buildErrorCodeToStatusMap () {
119126 Map <ErrorCode , Status > errorToStatus = new EnumMap <>(ErrorCode .class );
@@ -205,6 +212,8 @@ private static Map<ErrorCode, Status> buildErrorCodeToStatusMap() {
205212 private final boolean useGetForSafeMethods ;
206213 @ GuardedBy ("lock" )
207214 private final TransportTracer transportTracer ;
215+ private Optional <X509ExtendedTrustManager > x509ExtendedTrustManager ;
216+
208217 @ GuardedBy ("lock" )
209218 private final InUseStateAggregator <OkHttpClientStream > inUseState =
210219 new InUseStateAggregator <OkHttpClientStream >() {
@@ -233,13 +242,14 @@ protected void handleNotInUse() {
233242 SettableFuture <Void > connectedFuture ;
234243
235244 public OkHttpClientTransport (
236- OkHttpChannelBuilder . OkHttpTransportFactory transportFactory ,
245+ OkHttpTransportFactory transportFactory ,
237246 InetSocketAddress address ,
238247 String authority ,
239248 @ Nullable String userAgent ,
240249 Attributes eagAttrs ,
241250 @ Nullable HttpConnectProxiedSocketAddress proxiedAddr ,
242- Runnable tooManyPingsRunnable ) {
251+ Runnable tooManyPingsRunnable ,
252+ ChannelCredentials channelCredentials ) {
243253 this (
244254 transportFactory ,
245255 address ,
@@ -249,19 +259,21 @@ public OkHttpClientTransport(
249259 GrpcUtil .STOPWATCH_SUPPLIER ,
250260 new Http2 (),
251261 proxiedAddr ,
252- tooManyPingsRunnable );
262+ tooManyPingsRunnable ,
263+ channelCredentials );
253264 }
254265
255266 private OkHttpClientTransport (
256- OkHttpChannelBuilder . OkHttpTransportFactory transportFactory ,
267+ OkHttpTransportFactory transportFactory ,
257268 InetSocketAddress address ,
258269 String authority ,
259270 @ Nullable String userAgent ,
260271 Attributes eagAttrs ,
261272 Supplier <Stopwatch > stopwatchFactory ,
262273 Variant variant ,
263274 @ Nullable HttpConnectProxiedSocketAddress proxiedAddr ,
264- Runnable tooManyPingsRunnable ) {
275+ Runnable tooManyPingsRunnable ,
276+ ChannelCredentials channelCredentials ) {
265277 this .address = Preconditions .checkNotNull (address , "address" );
266278 this .defaultAuthority = authority ;
267279 this .maxMessageSize = transportFactory .maxMessageSize ;
@@ -291,6 +303,7 @@ private OkHttpClientTransport(
291303 this .attributes = Attributes .newBuilder ()
292304 .set (GrpcAttributes .ATTR_CLIENT_EAG_ATTRS , eagAttrs ).build ();
293305 this .useGetForSafeMethods = transportFactory .useGetForSafeMethods ;
306+ this .channelCredentials = channelCredentials ;
294307 initTransportTracer ();
295308 }
296309
@@ -316,7 +329,8 @@ private OkHttpClientTransport(
316329 stopwatchFactory ,
317330 variant ,
318331 null ,
319- tooManyPingsRunnable );
332+ tooManyPingsRunnable ,
333+ null );
320334 this .connectingCallback = connectingCallback ;
321335 this .connectedFuture = Preconditions .checkNotNull (connectedFuture , "connectedFuture" );
322336 }
@@ -389,13 +403,18 @@ public void ping(final PingCallback callback, Executor executor) {
389403 }
390404
391405 @ Override
392- public OkHttpClientStream newStream (
406+ public ClientStream newStream (
393407 MethodDescriptor <?, ?> method , Metadata headers , CallOptions callOptions ,
394408 ClientStreamTracer [] tracers ) {
395409 Preconditions .checkNotNull (method , "method" );
396410 Preconditions .checkNotNull (headers , "headers" );
397411 StatsTraceContext statsTraceContext =
398412 StatsTraceContext .newClientContext (tracers , getAttributes (), headers );
413+ if (callOptions .getAuthority () != null && channelCredentials instanceof TlsChannelCredentials ) {
414+ if (x509ExtendedTrustManager == null ) {
415+
416+ }
417+ }
399418 // FIXME: it is likely wrong to pass the transportTracer here as it'll exit the lock's scope
400419 synchronized (lock ) { // to make @GuardedBy linter happy
401420 return new OkHttpClientStream (
0 commit comments