what-the-bank/sources/okhttp3/internal/connection/ConnectionSpecSelector.java

81 lines
3.1 KiB
Java

package okhttp3.internal.connection;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.net.ProtocolException;
import java.net.UnknownServiceException;
import java.security.cert.CertificateException;
import java.util.Arrays;
import java.util.List;
import javax.net.ssl.SSLException;
import javax.net.ssl.SSLHandshakeException;
import javax.net.ssl.SSLPeerUnverifiedException;
import javax.net.ssl.SSLSocket;
import o.C14957gcv;
import okhttp3.ConnectionSpec;
/* loaded from: classes.dex */
public final class ConnectionSpecSelector {
private final List<ConnectionSpec> connectionSpecs;
private boolean isFallback;
private boolean isFallbackPossible;
private int nextModeIndex;
public ConnectionSpecSelector(List<ConnectionSpec> list) {
C14957gcv.e(list, "");
this.connectionSpecs = list;
}
public final ConnectionSpec configureSecureSocket(SSLSocket sSLSocket) throws IOException {
ConnectionSpec connectionSpec;
C14957gcv.e(sSLSocket, "");
int i = this.nextModeIndex;
int size = this.connectionSpecs.size();
while (true) {
if (i >= size) {
connectionSpec = null;
break;
}
int i2 = i + 1;
connectionSpec = this.connectionSpecs.get(i);
if (connectionSpec.isCompatible(sSLSocket)) {
this.nextModeIndex = i2;
break;
}
i = i2;
}
if (connectionSpec == null) {
StringBuilder sb = new StringBuilder("Unable to find acceptable protocols. isFallback=");
sb.append(this.isFallback);
sb.append(", modes=");
sb.append(this.connectionSpecs);
sb.append(", supported protocols=");
String[] enabledProtocols = sSLSocket.getEnabledProtocols();
C14957gcv.e(enabledProtocols);
String arrays = Arrays.toString(enabledProtocols);
C14957gcv.c((Object) arrays, "");
sb.append(arrays);
throw new UnknownServiceException(sb.toString());
}
this.isFallbackPossible = isFallbackPossible(sSLSocket);
connectionSpec.apply$okhttp(sSLSocket, this.isFallback);
return connectionSpec;
}
public final boolean connectionFailed(IOException iOException) {
C14957gcv.e(iOException, "");
this.isFallback = true;
return (!this.isFallbackPossible || (iOException instanceof ProtocolException) || (iOException instanceof InterruptedIOException) || ((iOException instanceof SSLHandshakeException) && (iOException.getCause() instanceof CertificateException)) || (iOException instanceof SSLPeerUnverifiedException) || !(iOException instanceof SSLException)) ? false : true;
}
private final boolean isFallbackPossible(SSLSocket sSLSocket) {
int size = this.connectionSpecs.size();
for (int i = this.nextModeIndex; i < size; i++) {
if (this.connectionSpecs.get(i).isCompatible(sSLSocket)) {
return true;
}
}
return false;
}
}