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

345 lines
15 KiB
Java
Raw Normal View History

2024-07-27 18:17:47 +07:00
package okhttp3;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import javax.net.ssl.SSLSocket;
import o.C14881gav;
import o.C14953gcr;
import o.C14957gcv;
import o.gaZ;
import okhttp3.internal.Util;
/* loaded from: classes.dex */
public final class ConnectionSpec {
private static final CipherSuite[] APPROVED_CIPHER_SUITES;
public static final ConnectionSpec CLEARTEXT;
public static final ConnectionSpec COMPATIBLE_TLS;
public static final Companion Companion = new Companion(null);
public static final ConnectionSpec MODERN_TLS;
private static final CipherSuite[] RESTRICTED_CIPHER_SUITES;
public static final ConnectionSpec RESTRICTED_TLS;
private final String[] cipherSuitesAsString;
private final boolean isTls;
private final boolean supportsTlsExtensions;
private final String[] tlsVersionsAsString;
public ConnectionSpec(boolean z, boolean z2, String[] strArr, String[] strArr2) {
this.isTls = z;
this.supportsTlsExtensions = z2;
this.cipherSuitesAsString = strArr;
this.tlsVersionsAsString = strArr2;
}
/* renamed from: -deprecated_cipherSuites, reason: not valid java name */
public final List<CipherSuite> m384deprecated_cipherSuites() {
return cipherSuites();
}
/* renamed from: -deprecated_tlsVersions, reason: not valid java name */
public final List<TlsVersion> m386deprecated_tlsVersions() {
return tlsVersions();
}
public final void apply$okhttp(SSLSocket sSLSocket, boolean z) {
C14957gcv.e(sSLSocket, "");
ConnectionSpec supportedSpec = supportedSpec(sSLSocket, z);
if (supportedSpec.tlsVersions() != null) {
sSLSocket.setEnabledProtocols(supportedSpec.tlsVersionsAsString);
}
if (supportedSpec.cipherSuites() != null) {
sSLSocket.setEnabledCipherSuites(supportedSpec.cipherSuitesAsString);
}
}
private final ConnectionSpec supportedSpec(SSLSocket sSLSocket, boolean z) {
String[] enabledCipherSuites;
String[] enabledProtocols;
if (this.cipherSuitesAsString != null) {
String[] enabledCipherSuites2 = sSLSocket.getEnabledCipherSuites();
C14957gcv.c(enabledCipherSuites2, "");
enabledCipherSuites = Util.intersect(enabledCipherSuites2, this.cipherSuitesAsString, CipherSuite.Companion.getORDER_BY_NAME$okhttp());
} else {
enabledCipherSuites = sSLSocket.getEnabledCipherSuites();
}
if (this.tlsVersionsAsString != null) {
String[] enabledProtocols2 = sSLSocket.getEnabledProtocols();
C14957gcv.c(enabledProtocols2, "");
String[] strArr = this.tlsVersionsAsString;
gaZ gaz = gaZ.a;
C14957gcv.d(gaz, "");
enabledProtocols = Util.intersect(enabledProtocols2, strArr, gaz);
} else {
enabledProtocols = sSLSocket.getEnabledProtocols();
}
String[] supportedCipherSuites = sSLSocket.getSupportedCipherSuites();
C14957gcv.c(supportedCipherSuites, "");
int indexOf = Util.indexOf(supportedCipherSuites, "TLS_FALLBACK_SCSV", CipherSuite.Companion.getORDER_BY_NAME$okhttp());
if (z && indexOf != -1) {
C14957gcv.c(enabledCipherSuites, "");
String str = supportedCipherSuites[indexOf];
C14957gcv.c((Object) str, "");
enabledCipherSuites = Util.concat(enabledCipherSuites, str);
}
Builder builder = new Builder(this);
C14957gcv.c(enabledCipherSuites, "");
Builder cipherSuites = builder.cipherSuites((String[]) Arrays.copyOf(enabledCipherSuites, enabledCipherSuites.length));
C14957gcv.c(enabledProtocols, "");
return cipherSuites.tlsVersions((String[]) Arrays.copyOf(enabledProtocols, enabledProtocols.length)).build();
}
public final boolean isCompatible(SSLSocket sSLSocket) {
C14957gcv.e(sSLSocket, "");
if (!this.isTls) {
return false;
}
String[] strArr = this.tlsVersionsAsString;
if (strArr != null) {
String[] enabledProtocols = sSLSocket.getEnabledProtocols();
gaZ gaz = gaZ.a;
C14957gcv.d(gaz, "");
if (!Util.hasIntersection(strArr, enabledProtocols, gaz)) {
return false;
}
}
String[] strArr2 = this.cipherSuitesAsString;
return strArr2 == null || Util.hasIntersection(strArr2, sSLSocket.getEnabledCipherSuites(), CipherSuite.Companion.getORDER_BY_NAME$okhttp());
}
public final boolean equals(Object obj) {
if (!(obj instanceof ConnectionSpec)) {
return false;
}
if (obj == this) {
return true;
}
boolean z = this.isTls;
ConnectionSpec connectionSpec = (ConnectionSpec) obj;
if (z != connectionSpec.isTls) {
return false;
}
return !z || (Arrays.equals(this.cipherSuitesAsString, connectionSpec.cipherSuitesAsString) && Arrays.equals(this.tlsVersionsAsString, connectionSpec.tlsVersionsAsString) && this.supportsTlsExtensions == connectionSpec.supportsTlsExtensions);
}
public final int hashCode() {
if (!this.isTls) {
return 17;
}
String[] strArr = this.cipherSuitesAsString;
int hashCode = strArr == null ? 0 : Arrays.hashCode(strArr);
String[] strArr2 = this.tlsVersionsAsString;
return ((((hashCode + 527) * 31) + (strArr2 != null ? Arrays.hashCode(strArr2) : 0)) * 31) + (!this.supportsTlsExtensions ? 1 : 0);
}
public final String toString() {
if (!this.isTls) {
return "ConnectionSpec()";
}
StringBuilder sb = new StringBuilder("ConnectionSpec(cipherSuites=");
sb.append((Object) Objects.toString(cipherSuites(), "[all enabled]"));
sb.append(", tlsVersions=");
sb.append((Object) Objects.toString(tlsVersions(), "[all enabled]"));
sb.append(", supportsTlsExtensions=");
sb.append(this.supportsTlsExtensions);
sb.append(')');
return sb.toString();
}
/* loaded from: classes.dex */
public static final class Builder {
private String[] cipherSuites;
private boolean supportsTlsExtensions;
private boolean tls;
private String[] tlsVersions;
public Builder(boolean z) {
this.tls = z;
}
public Builder(ConnectionSpec connectionSpec) {
C14957gcv.e(connectionSpec, "");
this.tls = connectionSpec.isTls();
this.cipherSuites = connectionSpec.cipherSuitesAsString;
this.tlsVersions = connectionSpec.tlsVersionsAsString;
this.supportsTlsExtensions = connectionSpec.supportsTlsExtensions();
}
public final Builder allEnabledCipherSuites() {
if (!getTls$okhttp()) {
throw new IllegalArgumentException("no cipher suites for cleartext connections".toString());
}
setCipherSuites$okhttp(null);
return this;
}
public final Builder cipherSuites(CipherSuite... cipherSuiteArr) {
C14957gcv.e(cipherSuiteArr, "");
if (!getTls$okhttp()) {
throw new IllegalArgumentException("no cipher suites for cleartext connections".toString());
}
ArrayList arrayList = new ArrayList(cipherSuiteArr.length);
for (CipherSuite cipherSuite : cipherSuiteArr) {
arrayList.add(cipherSuite.javaName());
}
Object[] array = arrayList.toArray(new String[0]);
if (array != null) {
String[] strArr = (String[]) array;
return cipherSuites((String[]) Arrays.copyOf(strArr, strArr.length));
}
throw new NullPointerException("null cannot be cast to non-null type kotlin.Array<T of kotlin.collections.ArraysKt__ArraysJVMKt.toTypedArray>");
}
public final Builder cipherSuites(String... strArr) {
C14957gcv.e(strArr, "");
if (!getTls$okhttp()) {
throw new IllegalArgumentException("no cipher suites for cleartext connections".toString());
}
if (!(!(strArr.length == 0))) {
throw new IllegalArgumentException("At least one cipher suite is required".toString());
}
setCipherSuites$okhttp((String[]) strArr.clone());
return this;
}
public final Builder allEnabledTlsVersions() {
if (!getTls$okhttp()) {
throw new IllegalArgumentException("no TLS versions for cleartext connections".toString());
}
setTlsVersions$okhttp(null);
return this;
}
public final Builder tlsVersions(TlsVersion... tlsVersionArr) {
C14957gcv.e(tlsVersionArr, "");
if (!getTls$okhttp()) {
throw new IllegalArgumentException("no TLS versions for cleartext connections".toString());
}
ArrayList arrayList = new ArrayList(tlsVersionArr.length);
for (TlsVersion tlsVersion : tlsVersionArr) {
arrayList.add(tlsVersion.javaName());
}
Object[] array = arrayList.toArray(new String[0]);
if (array != null) {
String[] strArr = (String[]) array;
return tlsVersions((String[]) Arrays.copyOf(strArr, strArr.length));
}
throw new NullPointerException("null cannot be cast to non-null type kotlin.Array<T of kotlin.collections.ArraysKt__ArraysJVMKt.toTypedArray>");
}
public final Builder tlsVersions(String... strArr) {
C14957gcv.e(strArr, "");
if (!getTls$okhttp()) {
throw new IllegalArgumentException("no TLS versions for cleartext connections".toString());
}
if (!(!(strArr.length == 0))) {
throw new IllegalArgumentException("At least one TLS version is required".toString());
}
setTlsVersions$okhttp((String[]) strArr.clone());
return this;
}
public final Builder supportsTlsExtensions(boolean z) {
if (!getTls$okhttp()) {
throw new IllegalArgumentException("no TLS extensions for cleartext connections".toString());
}
setSupportsTlsExtensions$okhttp(z);
return this;
}
public final ConnectionSpec build() {
return new ConnectionSpec(this.tls, this.supportsTlsExtensions, this.cipherSuites, this.tlsVersions);
}
public final void setTlsVersions$okhttp(String[] strArr) {
this.tlsVersions = strArr;
}
public final void setTls$okhttp(boolean z) {
this.tls = z;
}
public final void setSupportsTlsExtensions$okhttp(boolean z) {
this.supportsTlsExtensions = z;
}
public final void setCipherSuites$okhttp(String[] strArr) {
this.cipherSuites = strArr;
}
public final String[] getTlsVersions$okhttp() {
return this.tlsVersions;
}
public final boolean getTls$okhttp() {
return this.tls;
}
public final boolean getSupportsTlsExtensions$okhttp() {
return this.supportsTlsExtensions;
}
public final String[] getCipherSuites$okhttp() {
return this.cipherSuites;
}
}
/* loaded from: classes.dex */
public static final class Companion {
private Companion() {
}
public /* synthetic */ Companion(C14953gcr c14953gcr) {
this();
}
}
static {
CipherSuite[] cipherSuiteArr = {CipherSuite.TLS_AES_128_GCM_SHA256, CipherSuite.TLS_AES_256_GCM_SHA384, CipherSuite.TLS_CHACHA20_POLY1305_SHA256, CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, CipherSuite.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, CipherSuite.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256, CipherSuite.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256};
RESTRICTED_CIPHER_SUITES = cipherSuiteArr;
CipherSuite[] cipherSuiteArr2 = {CipherSuite.TLS_AES_128_GCM_SHA256, CipherSuite.TLS_AES_256_GCM_SHA384, CipherSuite.TLS_CHACHA20_POLY1305_SHA256, CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, CipherSuite.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, CipherSuite.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256, CipherSuite.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256, CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, CipherSuite.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, CipherSuite.TLS_RSA_WITH_AES_128_GCM_SHA256, CipherSuite.TLS_RSA_WITH_AES_256_GCM_SHA384, CipherSuite.TLS_RSA_WITH_AES_128_CBC_SHA, CipherSuite.TLS_RSA_WITH_AES_256_CBC_SHA, CipherSuite.TLS_RSA_WITH_3DES_EDE_CBC_SHA};
APPROVED_CIPHER_SUITES = cipherSuiteArr2;
RESTRICTED_TLS = new Builder(true).cipherSuites((CipherSuite[]) Arrays.copyOf(cipherSuiteArr, 9)).tlsVersions(TlsVersion.TLS_1_3, TlsVersion.TLS_1_2).supportsTlsExtensions(true).build();
MODERN_TLS = new Builder(true).cipherSuites((CipherSuite[]) Arrays.copyOf(cipherSuiteArr2, 16)).tlsVersions(TlsVersion.TLS_1_3, TlsVersion.TLS_1_2).supportsTlsExtensions(true).build();
COMPATIBLE_TLS = new Builder(true).cipherSuites((CipherSuite[]) Arrays.copyOf(cipherSuiteArr2, 16)).tlsVersions(TlsVersion.TLS_1_3, TlsVersion.TLS_1_2, TlsVersion.TLS_1_1, TlsVersion.TLS_1_0).supportsTlsExtensions(true).build();
CLEARTEXT = new Builder(false).build();
}
public final List<CipherSuite> cipherSuites() {
String[] strArr = this.cipherSuitesAsString;
if (strArr == null) {
return null;
}
ArrayList arrayList = new ArrayList(strArr.length);
for (String str : strArr) {
arrayList.add(CipherSuite.Companion.forJavaName(str));
}
return C14881gav.d((Iterable) arrayList);
}
public final List<TlsVersion> tlsVersions() {
String[] strArr = this.tlsVersionsAsString;
if (strArr == null) {
return null;
}
ArrayList arrayList = new ArrayList(strArr.length);
for (String str : strArr) {
arrayList.add(TlsVersion.Companion.forJavaName(str));
}
return C14881gav.d((Iterable) arrayList);
}
public final boolean supportsTlsExtensions() {
return this.supportsTlsExtensions;
}
public final boolean isTls() {
return this.isTls;
}
/* renamed from: -deprecated_supportsTlsExtensions, reason: not valid java name */
public final boolean m385deprecated_supportsTlsExtensions() {
return this.supportsTlsExtensions;
}
}