package p447.p448.p452;

import java.net.UnknownServiceException;
import java.util.Arrays;
import java.util.List;
import javax.net.ssl.SSLSocket;
import p138.p139.p143.p144.C2803;
import p138.p176.p177.p242.p246.p251.C4303;
import p402.p404.C6569;
import p402.p411.p413.C6635;
import p447.C6876;
import p447.C6881;
import p447.p448.C6943;

/* JADX INFO: renamed from: ސ.ޣ.ބ.ؠ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public final class C6959 {

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public int f20229;

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public boolean f20230;

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public boolean f20231;

    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    public final List<C6881> f20232;

    public C6959(List<C6881> list) {
        if (list != null) {
            this.f20232 = list;
        } else {
            C6635.m9824("connectionSpecs");
            throw null;
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final C6881 m10198(SSLSocket sSLSocket) throws UnknownServiceException, CloneNotSupportedException {
        C6881 c6881;
        boolean z;
        String[] enabledCipherSuites;
        String[] enabledProtocols;
        if (sSLSocket == null) {
            C6635.m9824("sslSocket");
            throw null;
        }
        int i = this.f20229;
        int size = this.f20232.size();
        while (true) {
            if (i >= size) {
                c6881 = null;
                break;
            }
            c6881 = this.f20232.get(i);
            if (c6881.m10037(sSLSocket)) {
                this.f20229 = i + 1;
                break;
            }
            i++;
        }
        if (c6881 == null) {
            StringBuilder sbM4889 = C2803.m4889("Unable to find acceptable protocols. isFallback=");
            sbM4889.append(this.f20231);
            sbM4889.append(',');
            sbM4889.append(" modes=");
            sbM4889.append(this.f20232);
            sbM4889.append(',');
            sbM4889.append(" supported protocols=");
            String[] enabledProtocols2 = sSLSocket.getEnabledProtocols();
            if (enabledProtocols2 == null) {
                C6635.m9822();
                throw null;
            }
            String string = Arrays.toString(enabledProtocols2);
            C6635.m9823((Object) string, "java.util.Arrays.toString(this)");
            sbM4889.append(string);
            throw new UnknownServiceException(sbM4889.toString());
        }
        int i2 = this.f20229;
        int size2 = this.f20232.size();
        while (true) {
            if (i2 >= size2) {
                z = false;
                break;
            }
            if (this.f20232.get(i2).m10037(sSLSocket)) {
                z = true;
                break;
            }
            i2++;
        }
        this.f20230 = z;
        boolean z2 = this.f20231;
        if (c6881.f19966 != null) {
            String[] enabledCipherSuites2 = sSLSocket.getEnabledCipherSuites();
            C6635.m9823((Object) enabledCipherSuites2, "sslSocket.enabledCipherSuites");
            String[] strArr = c6881.f19966;
            if (C6876.f19956 == null) {
                throw null;
            }
            enabledCipherSuites = C6943.m10177(enabledCipherSuites2, strArr, C6876.f19938);
        } else {
            enabledCipherSuites = sSLSocket.getEnabledCipherSuites();
        }
        if (c6881.f19967 != null) {
            String[] enabledProtocols3 = sSLSocket.getEnabledProtocols();
            C6635.m9823((Object) enabledProtocols3, "sslSocket.enabledProtocols");
            enabledProtocols = C6943.m10177(enabledProtocols3, c6881.f19967, C6569.f19346);
        } else {
            enabledProtocols = sSLSocket.getEnabledProtocols();
        }
        String[] supportedCipherSuites = sSLSocket.getSupportedCipherSuites();
        C6635.m9823((Object) supportedCipherSuites, "supportedCipherSuites");
        if (C6876.f19956 == null) {
            throw null;
        }
        int iM10153 = C6943.m10153(supportedCipherSuites, "TLS_FALLBACK_SCSV", C6876.f19938);
        if (z2 && iM10153 != -1) {
            C6635.m9823((Object) enabledCipherSuites, "cipherSuitesIntersection");
            String str = supportedCipherSuites[iM10153];
            C6635.m9823((Object) str, "supportedCipherSuites[indexOfFallbackScsv]");
            Object[] objArrCopyOf = Arrays.copyOf(enabledCipherSuites, enabledCipherSuites.length + 1);
            C6635.m9823((Object) objArrCopyOf, "java.util.Arrays.copyOf(this, newSize)");
            enabledCipherSuites = (String[]) objArrCopyOf;
            enabledCipherSuites[C4303.m6995((Object[]) enabledCipherSuites)] = str;
        }
        C6881.C6882 c6882 = new C6881.C6882(c6881);
        C6635.m9823((Object) enabledCipherSuites, "cipherSuitesIntersection");
        c6882.m10040((String[]) Arrays.copyOf(enabledCipherSuites, enabledCipherSuites.length));
        C6635.m9823((Object) enabledProtocols, "tlsVersionsIntersection");
        c6882.m10044((String[]) Arrays.copyOf(enabledProtocols, enabledProtocols.length));
        C6881 c6881M10043 = c6882.m10043();
        if (c6881M10043.m10038() != null) {
            sSLSocket.setEnabledProtocols(c6881M10043.f19967);
        }
        if (c6881M10043.m10036() != null) {
            sSLSocket.setEnabledCipherSuites(c6881M10043.f19966);
        }
        return c6881;
    }
}
