根据SslServerSocket.setEnabledProtocols()这个限定支持的协议的方法方法可知里面调用的SSLParametersImpl的setEnabledProtocols方法
void setEnabledProtocols(String[] protocols) {
281 if (protocols == null) {
282 throw new IllegalArgumentException("protocols == null");
283 }
284 String[] filteredProtocols =
285 filterFromProtocols(protocols, NativeCrypto.OBSOLETE_PROTOCOL_SSLV3);
286 isEnabledProtocolsFiltered = protocols.length != filteredProtocols.length;
287 enabledProtocols = NativeCrypto.checkEnabledProtocols(filteredProtocols).clone();
288 }
里面调用了NativeCrypto.checkEnabledProtocols方法,NativeCrypto主要就是用于判断设备支持的协议,所以可以做以下修改:
external/conscrypt/common/src/main/java/org/conscrypt/NativeCrypto.java
/** Protocols to enable by default when "TLSv1.3" is requested. */
static final String[] TLSV13_PROTOCOLS = new String[] {
- SUPPORTED_PROTOCOL_TLSV1,
- SUPPORTED_PROTOCOL_TLSV1_1,
+ // SUPPORTED_PROTOCOL_TLSV1,
+ //SUPPORTED_PROTOCOL_TLSV1_1,
SUPPORTED_PROTOCOL_TLSV1_2,
- SUPPORTED_PROTOCOL_TLSV1_3,
+ //SUPPORTED_PROTOCOL_TLSV1_3,
};
/** Protocols to enable by default when "TLSv1.2" is requested. */
static final String[] TLSV12_PROTOCOLS = new String[] {
- SUPPORTED_PROTOCOL_TLSV1,
- SUPPORTED_PROTOCOL_TLSV1_1,
+ // SUPPORTED_PROTOCOL_TLSV1,
+ //SUPPORTED_PROTOCOL_TLSV1_1,
SUPPORTED_PROTOCOL_TLSV1_2,
};
@@ -991,10 +991,10 @@ public final class NativeCrypto {
static final String[] DEFAULT_PROTOCOLS = TLSV13_PROTOCOLS;
private static final String[] SUPPORTED_PROTOCOLS = new String[] {
- SUPPORTED_PROTOCOL_TLSV1,
- SUPPORTED_PROTOCOL_TLSV1_1,
+ //SUPPORTED_PROTOCOL_TLSV1,
+ //SUPPORTED_PROTOCOL_TLSV1_1,
SUPPORTED_PROTOCOL_TLSV1_2,
- SUPPORTED_PROTOCOL_TLSV1_3,
+ //SUPPORTED_PROTOCOL_TLSV1_3,
};
static String[] getSupportedProtocols() {
@@ -1044,7 +1044,7 @@ public final class NativeCrypto {
}
private static int getProtocolConstant(String protocol) {
- if (protocol.equals(SUPPORTED_PROTOCOL_TLSV1)) {
+ /** if (protocol.equals(SUPPORTED_PROTOCOL_TLSV1)) {
return NativeConstants.TLS1_VERSION;
} else if (protocol.equals(SUPPORTED_PROTOCOL_TLSV1_1)) {
return NativeConstants.TLS1_1_VERSION;
@@ -1054,6 +1054,12 @@ public final class NativeCrypto {
return NativeConstants.TLS1_3_VERSION;
} else {
throw new AssertionError("Unknown protocol encountered: " + protocol);
+ } **/
+
+ if (protocol.equals(SUPPORTED_PROTOCOL_TLSV1_2)) {
+ return NativeConstants.TLS1_2_VERSION;
+ } else {
+ throw new AssertionError("Unknown protocol encountered: " + protocol);
}
}
@@ -1065,12 +1071,15 @@ public final class NativeCrypto {
if (protocol == null) {
throw new IllegalArgumentException("protocols contains null");
}
- if (!protocol.equals(SUPPORTED_PROTOCOL_TLSV1)
+ /** if (!protocol.equals(SUPPORTED_PROTOCOL_TLSV1)
&& !protocol.equals(SUPPORTED_PROTOCOL_TLSV1_1)
&& !protocol.equals(SUPPORTED_PROTOCOL_TLSV1_2)
&& !protocol.equals(SUPPORTED_PROTOCOL_TLSV1_3)
&& !protocol.equals(OBSOLETE_PROTOCOL_SSLV3)) {
throw new IllegalArgumentException("protocol " + protocol + " is not supported");
+ }**/
+ if (!protocol.equals(SUPPORTED_PROTOCOL_TLSV1_2)) {
+ throw new IllegalArgumentException("protocol " + protocol + " is not supported");
}
}
return protocols;
external/conscrypt/repackaged/common/src/main/java/com/android/org/conscrypt/NativeCrypto.java
+
/**
* Provides the Java side of our JNI glue for OpenSSL.
* <p>
@@ -1003,16 +1004,16 @@ public final class NativeCrypto {
/** Protocols to enable by default when "TLSv1.3" is requested. */
static final String[] TLSV13_PROTOCOLS = new String[] {
- SUPPORTED_PROTOCOL_TLSV1,
- SUPPORTED_PROTOCOL_TLSV1_1,
+ //SUPPORTED_PROTOCOL_TLSV1,
+ //SUPPORTED_PROTOCOL_TLSV1_1,
SUPPORTED_PROTOCOL_TLSV1_2,
- SUPPORTED_PROTOCOL_TLSV1_3,
+ // SUPPORTED_PROTOCOL_TLSV1_3,
};
/** Protocols to enable by default when "TLSv1.2" is requested. */
static final String[] TLSV12_PROTOCOLS = new String[] {
- SUPPORTED_PROTOCOL_TLSV1,
- SUPPORTED_PROTOCOL_TLSV1_1,
+ //SUPPORTED_PROTOCOL_TLSV1,
+ //SUPPORTED_PROTOCOL_TLSV1_1,
SUPPORTED_PROTOCOL_TLSV1_2,
};
@@ -1024,10 +1025,10 @@ public final class NativeCrypto {
static final String[] DEFAULT_PROTOCOLS = TLSV13_PROTOCOLS;
private static final String[] SUPPORTED_PROTOCOLS = new String[] {
- SUPPORTED_PROTOCOL_TLSV1,
- SUPPORTED_PROTOCOL_TLSV1_1,
+ //SUPPORTED_PROTOCOL_TLSV1,
+ //SUPPORTED_PROTOCOL_TLSV1_1,
SUPPORTED_PROTOCOL_TLSV1_2,
- SUPPORTED_PROTOCOL_TLSV1_3,
+ //SUPPORTED_PROTOCOL_TLSV1_3,
};
static String[] getSupportedProtocols() {
@@ -1077,7 +1078,7 @@ public final class NativeCrypto {
}
private static int getProtocolConstant(String protocol) {
- if (protocol.equals(SUPPORTED_PROTOCOL_TLSV1)) {
+ /** if (protocol.equals(SUPPORTED_PROTOCOL_TLSV1)) {
return NativeConstants.TLS1_VERSION;
} else if (protocol.equals(SUPPORTED_PROTOCOL_TLSV1_1)) {
return NativeConstants.TLS1_1_VERSION;
@@ -1087,6 +1088,12 @@ public final class NativeCrypto {
return NativeConstants.TLS1_3_VERSION;
} else {
throw new AssertionError("Unknown protocol encountered: " + protocol);
+ } **/
+
+ if (protocol.equals(SUPPORTED_PROTOCOL_TLSV1_2)) {
+ return NativeConstants.TLS1_2_VERSION;
+ } else {
+ throw new AssertionError("Unknown protocol encountered: " + protocol);
}
}
@@ -1098,12 +1105,16 @@ public final class NativeCrypto {
if (protocol == null) {
throw new IllegalArgumentException("protocols contains null");
}
- if (!protocol.equals(SUPPORTED_PROTOCOL_TLSV1)
+ /** if (!protocol.equals(SUPPORTED_PROTOCOL_TLSV1)
&& !protocol.equals(SUPPORTED_PROTOCOL_TLSV1_1)
&& !protocol.equals(SUPPORTED_PROTOCOL_TLSV1_2)
&& !protocol.equals(SUPPORTED_PROTOCOL_TLSV1_3)
&& !protocol.equals(OBSOLETE_PROTOCOL_SSLV3)) {
throw new IllegalArgumentException("protocol " + protocol + " is not supported");
+ } **/
+
+ if (!protocol.equals(SUPPORTED_PROTOCOL_TLSV1_2)) {
+ throw new IllegalArgumentException("protocol " + protocol + " is not supported");
}
}
return protocols;