what-the-bank/sources/okhttp3/repackaged/ConnectionSpec.java

265 lines
10 KiB
Java
Raw Normal View History

2024-07-27 18:17:47 +07:00
package okhttp3.repackaged;
import java.util.Arrays;
import java.util.List;
import javax.net.ssl.SSLSocket;
import okhttp3.repackaged.internal.Util;
/* loaded from: classes6.dex */
public final class ConnectionSpec {
public static final ConnectionSpec CLEARTEXT;
public static final ConnectionSpec COMPATIBLE_TLS;
public static final ConnectionSpec MODERN_TLS;
private static final CipherSuite[] ahq;
private final String[] cipherSuites;
private final boolean supportsTlsExtensions;
private final boolean tls;
private final String[] tlsVersions;
static {
CipherSuite[] cipherSuiteArr = {CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, CipherSuite.TLS_DHE_RSA_WITH_AES_128_GCM_SHA256, CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, CipherSuite.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, CipherSuite.TLS_DHE_RSA_WITH_AES_128_CBC_SHA, CipherSuite.TLS_DHE_RSA_WITH_AES_256_CBC_SHA, CipherSuite.TLS_RSA_WITH_AES_128_GCM_SHA256, CipherSuite.TLS_RSA_WITH_AES_128_CBC_SHA, CipherSuite.TLS_RSA_WITH_AES_256_CBC_SHA, CipherSuite.TLS_RSA_WITH_3DES_EDE_CBC_SHA};
ahq = cipherSuiteArr;
ConnectionSpec build = new Builder(true).cipherSuites(cipherSuiteArr).tlsVersions(TlsVersion.TLS_1_2, TlsVersion.TLS_1_1, TlsVersion.TLS_1_0).supportsTlsExtensions(true).build();
MODERN_TLS = build;
COMPATIBLE_TLS = new Builder(build).tlsVersions(TlsVersion.TLS_1_0).supportsTlsExtensions(true).build();
CLEARTEXT = new Builder(false).build();
}
private ConnectionSpec(Builder builder) {
this.tls = builder.tls;
this.cipherSuites = builder.cipherSuites;
this.tlsVersions = builder.tlsVersions;
this.supportsTlsExtensions = builder.supportsTlsExtensions;
}
public final List<CipherSuite> cipherSuites() {
String[] strArr = this.cipherSuites;
if (strArr == null) {
return null;
}
CipherSuite[] cipherSuiteArr = new CipherSuite[strArr.length];
int i = 0;
while (true) {
String[] strArr2 = this.cipherSuites;
if (i < strArr2.length) {
cipherSuiteArr[i] = CipherSuite.forJavaName(strArr2[i]);
i++;
} else {
return Util.immutableList(cipherSuiteArr);
}
}
}
public final List<TlsVersion> tlsVersions() {
String[] strArr = this.tlsVersions;
if (strArr == null) {
return null;
}
TlsVersion[] tlsVersionArr = new TlsVersion[strArr.length];
int i = 0;
while (true) {
String[] strArr2 = this.tlsVersions;
if (i < strArr2.length) {
tlsVersionArr[i] = TlsVersion.forJavaName(strArr2[i]);
i++;
} else {
return Util.immutableList(tlsVersionArr);
}
}
}
/* JADX INFO: Access modifiers changed from: package-private */
public final void apply(SSLSocket sSLSocket, boolean z) {
ConnectionSpec a = a(sSLSocket, z);
String[] strArr = a.tlsVersions;
if (strArr != null) {
sSLSocket.setEnabledProtocols(strArr);
}
String[] strArr2 = a.cipherSuites;
if (strArr2 != null) {
sSLSocket.setEnabledCipherSuites(strArr2);
}
}
private ConnectionSpec a(SSLSocket sSLSocket, boolean z) {
String[] enabledCipherSuites;
String[] enabledProtocols;
String[] strArr = this.cipherSuites;
if (strArr != null) {
enabledCipherSuites = (String[]) Util.intersect(String.class, strArr, sSLSocket.getEnabledCipherSuites());
} else {
enabledCipherSuites = sSLSocket.getEnabledCipherSuites();
}
String[] strArr2 = this.tlsVersions;
if (strArr2 != null) {
enabledProtocols = (String[]) Util.intersect(String.class, strArr2, sSLSocket.getEnabledProtocols());
} else {
enabledProtocols = sSLSocket.getEnabledProtocols();
}
if (z && Util.contains(sSLSocket.getSupportedCipherSuites(), "TLS_FALLBACK_SCSV")) {
enabledCipherSuites = Util.concat(enabledCipherSuites, "TLS_FALLBACK_SCSV");
}
return new Builder(this).cipherSuites(enabledCipherSuites).tlsVersions(enabledProtocols).build();
}
public final boolean isCompatible(SSLSocket sSLSocket) {
if (!this.tls) {
return false;
}
String[] strArr = this.tlsVersions;
if (strArr != null && !a(strArr, sSLSocket.getEnabledProtocols())) {
return false;
}
String[] strArr2 = this.cipherSuites;
return strArr2 == null || a(strArr2, sSLSocket.getEnabledCipherSuites());
}
private static boolean a(String[] strArr, String[] strArr2) {
if (strArr != null && strArr2 != null && strArr.length != 0 && strArr2.length != 0) {
for (String str : strArr) {
if (Util.contains(strArr2, str)) {
return true;
}
}
}
return false;
}
public final boolean equals(Object obj) {
if (!(obj instanceof ConnectionSpec)) {
return false;
}
if (obj == this) {
return true;
}
ConnectionSpec connectionSpec = (ConnectionSpec) obj;
boolean z = this.tls;
if (z != connectionSpec.tls) {
return false;
}
return !z || (Arrays.equals(this.cipherSuites, connectionSpec.cipherSuites) && Arrays.equals(this.tlsVersions, connectionSpec.tlsVersions) && this.supportsTlsExtensions == connectionSpec.supportsTlsExtensions);
}
public final int hashCode() {
if (!this.tls) {
return 17;
}
return ((((Arrays.hashCode(this.cipherSuites) + 527) * 31) + Arrays.hashCode(this.tlsVersions)) * 31) + (!this.supportsTlsExtensions ? 1 : 0);
}
public final String toString() {
if (!this.tls) {
return "ConnectionSpec()";
}
String obj = this.cipherSuites != null ? cipherSuites().toString() : "[all enabled]";
String obj2 = this.tlsVersions != null ? tlsVersions().toString() : "[all enabled]";
StringBuilder sb = new StringBuilder("ConnectionSpec(cipherSuites=");
sb.append(obj);
sb.append(", tlsVersions=");
sb.append(obj2);
sb.append(", supportsTlsExtensions=");
sb.append(this.supportsTlsExtensions);
sb.append(")");
return sb.toString();
}
/* loaded from: classes6.dex */
public static final class Builder {
private String[] cipherSuites;
private boolean supportsTlsExtensions;
private boolean tls;
private String[] tlsVersions;
Builder(boolean z) {
this.tls = z;
}
public Builder(ConnectionSpec connectionSpec) {
this.tls = connectionSpec.tls;
this.cipherSuites = connectionSpec.cipherSuites;
this.tlsVersions = connectionSpec.tlsVersions;
this.supportsTlsExtensions = connectionSpec.supportsTlsExtensions;
}
public final Builder allEnabledCipherSuites() {
if (!this.tls) {
throw new IllegalStateException("no cipher suites for cleartext connections");
}
this.cipherSuites = null;
return this;
}
public final Builder cipherSuites(CipherSuite... cipherSuiteArr) {
if (!this.tls) {
throw new IllegalStateException("no cipher suites for cleartext connections");
}
String[] strArr = new String[cipherSuiteArr.length];
for (int i = 0; i < cipherSuiteArr.length; i++) {
strArr[i] = cipherSuiteArr[i].javaName;
}
return cipherSuites(strArr);
}
public final Builder cipherSuites(String... strArr) {
if (!this.tls) {
throw new IllegalStateException("no cipher suites for cleartext connections");
}
if (strArr.length == 0) {
throw new IllegalArgumentException("At least one cipher suite is required");
}
this.cipherSuites = (String[]) strArr.clone();
return this;
}
public final Builder allEnabledTlsVersions() {
if (!this.tls) {
throw new IllegalStateException("no TLS versions for cleartext connections");
}
this.tlsVersions = null;
return this;
}
public final Builder tlsVersions(TlsVersion... tlsVersionArr) {
if (!this.tls) {
throw new IllegalStateException("no TLS versions for cleartext connections");
}
String[] strArr = new String[tlsVersionArr.length];
for (int i = 0; i < tlsVersionArr.length; i++) {
strArr[i] = tlsVersionArr[i].javaName;
}
return tlsVersions(strArr);
}
public final Builder tlsVersions(String... strArr) {
if (!this.tls) {
throw new IllegalStateException("no TLS versions for cleartext connections");
}
if (strArr.length == 0) {
throw new IllegalArgumentException("At least one TLS version is required");
}
this.tlsVersions = (String[]) strArr.clone();
return this;
}
public final Builder supportsTlsExtensions(boolean z) {
if (!this.tls) {
throw new IllegalStateException("no TLS extensions for cleartext connections");
}
this.supportsTlsExtensions = z;
return this;
}
public final ConnectionSpec build() {
return new ConnectionSpec(this);
}
}
public final boolean supportsTlsExtensions() {
return this.supportsTlsExtensions;
}
public final boolean isTls() {
return this.tls;
}
}