Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 26 additions & 18 deletions okhttp/src/main/java/okhttp3/internal/platform/Platform.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.net.InetSocketAddress;
import java.net.Socket;
import java.security.NoSuchAlgorithmException;
import java.security.Security;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
Expand All @@ -40,6 +39,9 @@
import okio.Buffer;

/**
* Replacement Platform class that avoids eager call to Security.getProviders()
* ----------------------------------------------------------------------------
*
* Access to platform-specific features.
*
* <h3>Server name indication (SNI)</h3>
Expand Down Expand Up @@ -185,16 +187,19 @@ public CertificateChainCleaner buildCertificateChainCleaner(SSLSocketFactory ssl
return buildCertificateChainCleaner(trustManager);
}

public static boolean isConscryptPreferred() {
// mainly to allow tests to run cleanly
if ("conscrypt".equals(System.getProperty("okhttp.platform"))) {
return true;
}

// check if Provider manually installed
String preferredProvider = Security.getProviders()[0].getName();
return "Conscrypt".equals(preferredProvider);
}
/* Avoid eager call to Security.getProviders()
----------------------------------------------
| public static boolean isConscryptPreferred() {
| // mainly to allow tests to run cleanly
| if ("conscrypt".equals(System.getProperty("okhttp.platform"))) {
| return true;
| }
|
| // check if Provider manually installed
| String preferredProvider = Security.getProviders()[0].getName();
| return "Conscrypt".equals(preferredProvider);
| }
---------------------------------------------- */

/** Attempt to match the host runtime to a capable Platform implementation. */
private static Platform findPlatform() {
Expand All @@ -212,13 +217,16 @@ public static boolean isAndroid() {
}

private static Platform findJvmPlatform() {
if (isConscryptPreferred()) {
Platform conscrypt = ConscryptPlatform.buildIfSupported();

if (conscrypt != null) {
return conscrypt;
}
}
/* Avoid eager call to Security.getProviders()
----------------------------------------------
| if (isConscryptPreferred()) {
| Platform conscrypt = ConscryptPlatform.buildIfSupported();
|
| if (conscrypt != null) {
| return conscrypt;
| }
| }
---------------------------------------------- */

Platform jdk9 = Jdk9Platform.buildIfSupported();

Expand Down