package okhttp3; import com.ironsource.mediationsdk.logger.IronSourceError; import java.io.IOException; import java.security.cert.Certificate; import java.security.cert.X509Certificate; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; import javax.net.ssl.SSLPeerUnverifiedException; import javax.net.ssl.SSLSession; import okhttp3.internal.Util; /* loaded from: classes5.dex */ public final class Handshake { public final CipherSuite cipherSuite; public final List localCertificates; public final List peerCertificates; public final TlsVersion tlsVersion; public CipherSuite cipherSuite() { return this.cipherSuite; } public List localCertificates() { return this.localCertificates; } public List peerCertificates() { return this.peerCertificates; } public TlsVersion tlsVersion() { return this.tlsVersion; } public Handshake(TlsVersion tlsVersion, CipherSuite cipherSuite, List list, List list2) { this.tlsVersion = tlsVersion; this.cipherSuite = cipherSuite; this.peerCertificates = list; this.localCertificates = list2; } public static Handshake get(SSLSession sSLSession) { Certificate[] certificateArr; List emptyList; List emptyList2; String cipherSuite = sSLSession.getCipherSuite(); if (cipherSuite == null) { throw new IllegalStateException("cipherSuite == null"); } if ("SSL_NULL_WITH_NULL_NULL".equals(cipherSuite)) { throw new IOException("cipherSuite == SSL_NULL_WITH_NULL_NULL"); } CipherSuite forJavaName = CipherSuite.forJavaName(cipherSuite); String protocol = sSLSession.getProtocol(); if (protocol == null) { throw new IllegalStateException("tlsVersion == null"); } if ("NONE".equals(protocol)) { throw new IOException("tlsVersion == NONE"); } TlsVersion forJavaName2 = TlsVersion.forJavaName(protocol); try { certificateArr = sSLSession.getPeerCertificates(); } catch (SSLPeerUnverifiedException unused) { certificateArr = null; } if (certificateArr != null) { emptyList = Util.immutableList(certificateArr); } else { emptyList = Collections.emptyList(); } Certificate[] localCertificates = sSLSession.getLocalCertificates(); if (localCertificates != null) { emptyList2 = Util.immutableList(localCertificates); } else { emptyList2 = Collections.emptyList(); } return new Handshake(forJavaName2, forJavaName, emptyList, emptyList2); } public static Handshake get(TlsVersion tlsVersion, CipherSuite cipherSuite, List list, List list2) { if (tlsVersion == null) { throw new NullPointerException("tlsVersion == null"); } if (cipherSuite == null) { throw new NullPointerException("cipherSuite == null"); } return new Handshake(tlsVersion, cipherSuite, Util.immutableList(list), Util.immutableList(list2)); } public boolean equals(Object obj) { if (!(obj instanceof Handshake)) { return false; } Handshake handshake = (Handshake) obj; return this.tlsVersion.equals(handshake.tlsVersion) && this.cipherSuite.equals(handshake.cipherSuite) && this.peerCertificates.equals(handshake.peerCertificates) && this.localCertificates.equals(handshake.localCertificates); } public int hashCode() { return ((((((IronSourceError.ERROR_NON_EXISTENT_INSTANCE + this.tlsVersion.hashCode()) * 31) + this.cipherSuite.hashCode()) * 31) + this.peerCertificates.hashCode()) * 31) + this.localCertificates.hashCode(); } public String toString() { return "Handshake{tlsVersion=" + this.tlsVersion + " cipherSuite=" + this.cipherSuite + " peerCertificates=" + names(this.peerCertificates) + " localCertificates=" + names(this.localCertificates) + '}'; } public final List names(List list) { ArrayList arrayList = new ArrayList(); Iterator it = list.iterator(); while (it.hasNext()) { Certificate certificate = (Certificate) it.next(); if (certificate instanceof X509Certificate) { arrayList.add(String.valueOf(((X509Certificate) certificate).getSubjectDN())); } else { arrayList.add(certificate.getType()); } } return arrayList; } }