Skip to content

Commit 8ff4431

Browse files
committed
Review comments and fix mistakes
1 parent 1c9c3ac commit 8ff4431

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116
import javax.net.ssl.SSLSocketFactory;
117117
import javax.net.ssl.TrustManager;
118118
import javax.net.ssl.TrustManagerFactory;
119+
import javax.net.ssl.X509TrustManager;
119120
import okio.Buffer;
120121
import okio.BufferedSink;
121122
import okio.BufferedSource;
@@ -507,7 +508,12 @@ private TrustManager getTrustManager(TlsChannelCredentials tlsCreds)
507508
tmf.init((KeyStore) null);
508509
tm = tmf.getTrustManagers();
509510
}
510-
return tm[0];
511+
for (TrustManager trustManager: tm) {
512+
if (trustManager instanceof X509TrustManager) {
513+
return trustManager;
514+
}
515+
}
516+
return null;
511517
}
512518

513519
@GuardedBy("lock")
@@ -519,7 +525,7 @@ void streamReadyToStart(OkHttpClientStream clientStream, String authority) {
519525
pendingStreams.add(clientStream);
520526
setInUse(clientStream);
521527
} else {
522-
if (!authority.equals(defaultAuthority)) {
528+
if (socket instanceof SSLSocket && !authority.equals(defaultAuthority)) {
523529
Status authorityVerificationResult;
524530
if (authorityVerificationResults.containsKey(authority)) {
525531
authorityVerificationResult = authorityVerificationResults.get(authority);

0 commit comments

Comments
 (0)