package okhttp3;

import J4.a;
import java.io.IOException;
import java.security.cert.Certificate;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.net.ssl.SSLPeerUnverifiedException;
import javax.net.ssl.SSLSession;
import kotlin.jvm.internal.o;
import m1.g;
import okhttp3.TlsVersion;
import okhttp3.internal.Util;
import w4.p;
import x4.AbstractC3253s;
import x4.y;

/* JADX INFO: loaded from: classes3.dex */
public final class Handshake {

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public static final Companion f22012e = new Companion(0);

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final TlsVersion f22013a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final CipherSuite f22014b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final List f22015c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final p f22016d;

    public static final class Companion {
        public /* synthetic */ Companion(int i6) {
            this();
        }

        public static Handshake a(SSLSession sSLSession) throws IOException {
            Certificate[] peerCertificates;
            List listK = y.f26065a;
            String cipherSuite = sSLSession.getCipherSuite();
            if (cipherSuite == null) {
                throw new IllegalStateException("cipherSuite == null");
            }
            if (cipherSuite.equals("TLS_NULL_WITH_NULL_NULL") ? true : cipherSuite.equals("SSL_NULL_WITH_NULL_NULL")) {
                throw new IOException("cipherSuite == ".concat(cipherSuite));
            }
            CipherSuite cipherSuiteB = CipherSuite.f21956b.b(cipherSuite);
            String protocol = sSLSession.getProtocol();
            if (protocol == null) {
                throw new IllegalStateException("tlsVersion == null");
            }
            if ("NONE".equals(protocol)) {
                throw new IOException("tlsVersion == NONE");
            }
            TlsVersion.f22171b.getClass();
            TlsVersion tlsVersionA = TlsVersion.Companion.a(protocol);
            try {
                peerCertificates = sSLSession.getPeerCertificates();
            } catch (SSLPeerUnverifiedException unused) {
            }
            List listK2 = peerCertificates != null ? Util.k(Arrays.copyOf(peerCertificates, peerCertificates.length)) : listK;
            Certificate[] localCertificates = sSLSession.getLocalCertificates();
            if (localCertificates != null) {
                listK = Util.k(Arrays.copyOf(localCertificates, localCertificates.length));
            }
            return new Handshake(tlsVersionA, cipherSuiteB, listK, new Handshake$Companion$handshake$1(listK2));
        }

        private Companion() {
        }
    }

    public Handshake(TlsVersion tlsVersion, CipherSuite cipherSuite, List list, a aVar) {
        this.f22013a = tlsVersion;
        this.f22014b = cipherSuite;
        this.f22015c = list;
        this.f22016d = g.k(new Handshake$peerCertificates$2(aVar));
    }

    public final List a() {
        return (List) this.f22016d.getValue();
    }

    public final boolean equals(Object obj) {
        if (!(obj instanceof Handshake)) {
            return false;
        }
        Handshake handshake = (Handshake) obj;
        return handshake.f22013a == this.f22013a && o.c(handshake.f22014b, this.f22014b) && o.c(handshake.a(), a()) && o.c(handshake.f22015c, this.f22015c);
    }

    public final int hashCode() {
        return this.f22015c.hashCode() + ((a().hashCode() + ((this.f22014b.hashCode() + ((this.f22013a.hashCode() + 527) * 31)) * 31)) * 31);
    }

    public final String toString() {
        String type;
        String type2;
        List<Certificate> listA = a();
        ArrayList arrayList = new ArrayList(AbstractC3253s.G(listA, 10));
        for (Certificate certificate : listA) {
            if (certificate instanceof X509Certificate) {
                type2 = ((X509Certificate) certificate).getSubjectDN().toString();
            } else {
                type2 = certificate.getType();
                o.g(type2, "type");
            }
            arrayList.add(type2);
        }
        String string = arrayList.toString();
        StringBuilder sb = new StringBuilder("Handshake{tlsVersion=");
        sb.append(this.f22013a);
        sb.append(" cipherSuite=");
        sb.append(this.f22014b);
        sb.append(" peerCertificates=");
        sb.append(string);
        sb.append(" localCertificates=");
        List<Certificate> list = this.f22015c;
        ArrayList arrayList2 = new ArrayList(AbstractC3253s.G(list, 10));
        for (Certificate certificate2 : list) {
            if (certificate2 instanceof X509Certificate) {
                type = ((X509Certificate) certificate2).getSubjectDN().toString();
            } else {
                type = certificate2.getType();
                o.g(type, "type");
            }
            arrayList2.add(type);
        }
        sb.append(arrayList2);
        sb.append('}');
        return sb.toString();
    }
}
