Skip to content

Commit 1d9c158

Browse files
yschimkeswankjesse
authored andcommitted
Platform cleanup - move trust manager building internal (square#3611)
* Platform cleanup move trust manager building internal * typo * missing commit
1 parent 7e040c0 commit 1d9c158

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

okhttp/src/main/java/okhttp3/OkHttpClient.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -648,13 +648,8 @@ public Builder socketFactory(SocketFactory socketFactory) {
648648
*/
649649
public Builder sslSocketFactory(SSLSocketFactory sslSocketFactory) {
650650
if (sslSocketFactory == null) throw new NullPointerException("sslSocketFactory == null");
651-
X509TrustManager trustManager = Platform.get().trustManager(sslSocketFactory);
652-
if (trustManager == null) {
653-
throw new IllegalStateException("Unable to extract the trust manager on " + Platform.get()
654-
+ ", sslSocketFactory is " + sslSocketFactory.getClass());
655-
}
656651
this.sslSocketFactory = sslSocketFactory;
657-
this.certificateChainCleaner = CertificateChainCleaner.get(trustManager);
652+
this.certificateChainCleaner = Platform.get().buildCertificateChainCleaner(sslSocketFactory);
658653
return this;
659654
}
660655

okhttp/src/main/java/okhttp3/internal/platform/AndroidPlatform.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class AndroidPlatform extends Platform {
7979
}
8080
}
8181

82-
@Override public X509TrustManager trustManager(SSLSocketFactory sslSocketFactory) {
82+
@Override protected X509TrustManager trustManager(SSLSocketFactory sslSocketFactory) {
8383
Object context = readFieldOrNull(sslSocketFactory, sslParametersClass, "sslParameters");
8484
if (context == null) {
8585
// If that didn't work, try the Google Play Services SSL provider before giving up. This

okhttp/src/main/java/okhttp3/internal/platform/Platform.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public String getPrefix() {
8585
return "OkHttp";
8686
}
8787

88-
public X509TrustManager trustManager(SSLSocketFactory sslSocketFactory) {
88+
protected X509TrustManager trustManager(SSLSocketFactory sslSocketFactory) {
8989
// Attempt to get the trust manager from an OpenJDK socket factory. We attempt this on all
9090
// platforms in order to support Robolectric, which mixes classes from both Android and the
9191
// Oracle JDK. Note that we don't support HTTP/2 or other nice features on Robolectric.
@@ -168,6 +168,17 @@ public CertificateChainCleaner buildCertificateChainCleaner(X509TrustManager tru
168168
return new BasicCertificateChainCleaner(buildTrustRootIndex(trustManager));
169169
}
170170

171+
public CertificateChainCleaner buildCertificateChainCleaner(SSLSocketFactory sslSocketFactory) {
172+
X509TrustManager trustManager = trustManager(sslSocketFactory);
173+
174+
if (trustManager == null) {
175+
throw new IllegalStateException("Unable to extract the trust manager on " + Platform.get()
176+
+ ", sslSocketFactory is " + sslSocketFactory.getClass());
177+
}
178+
179+
return buildCertificateChainCleaner(trustManager);
180+
}
181+
171182
/** Attempt to match the host runtime to a capable Platform implementation. */
172183
private static Platform findPlatform() {
173184
Platform android = AndroidPlatform.buildIfSupported();

0 commit comments

Comments
 (0)