107 lines
4.0 KiB
Java
107 lines
4.0 KiB
Java
package okhttp3;
|
|
|
|
import java.io.IOException;
|
|
import java.security.Principal;
|
|
import java.security.cert.Certificate;
|
|
import java.security.cert.X509Certificate;
|
|
import java.util.Collections;
|
|
import java.util.List;
|
|
import javax.net.ssl.SSLPeerUnverifiedException;
|
|
import javax.net.ssl.SSLSession;
|
|
import okhttp3.internal.Util;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public final class Handshake {
|
|
private final CipherSuite cipherSuite;
|
|
private final List<Certificate> localCertificates;
|
|
private final List<Certificate> peerCertificates;
|
|
private final TlsVersion tlsVersion;
|
|
|
|
private Handshake(TlsVersion tlsVersion, CipherSuite cipherSuite, List<Certificate> list, List<Certificate> list2) {
|
|
this.tlsVersion = tlsVersion;
|
|
this.cipherSuite = cipherSuite;
|
|
this.peerCertificates = list;
|
|
this.localCertificates = list2;
|
|
}
|
|
|
|
public static Handshake get(SSLSession sSLSession) throws IOException {
|
|
Certificate[] certificateArr;
|
|
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;
|
|
}
|
|
List immutableList = certificateArr != null ? Util.immutableList(certificateArr) : Collections.emptyList();
|
|
Certificate[] localCertificates = sSLSession.getLocalCertificates();
|
|
return new Handshake(forJavaName2, forJavaName, immutableList, localCertificates != null ? Util.immutableList(localCertificates) : Collections.emptyList());
|
|
}
|
|
|
|
public CipherSuite cipherSuite() {
|
|
return this.cipherSuite;
|
|
}
|
|
|
|
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 ((((((527 + this.tlsVersion.hashCode()) * 31) + this.cipherSuite.hashCode()) * 31) + this.peerCertificates.hashCode()) * 31) + this.localCertificates.hashCode();
|
|
}
|
|
|
|
public List<Certificate> localCertificates() {
|
|
return this.localCertificates;
|
|
}
|
|
|
|
public Principal localPrincipal() {
|
|
if (this.localCertificates.isEmpty()) {
|
|
return null;
|
|
}
|
|
return ((X509Certificate) this.localCertificates.get(0)).getSubjectX500Principal();
|
|
}
|
|
|
|
public List<Certificate> peerCertificates() {
|
|
return this.peerCertificates;
|
|
}
|
|
|
|
public Principal peerPrincipal() {
|
|
if (this.peerCertificates.isEmpty()) {
|
|
return null;
|
|
}
|
|
return ((X509Certificate) this.peerCertificates.get(0)).getSubjectX500Principal();
|
|
}
|
|
|
|
public TlsVersion tlsVersion() {
|
|
return this.tlsVersion;
|
|
}
|
|
|
|
public static Handshake get(TlsVersion tlsVersion, CipherSuite cipherSuite, List<Certificate> list, List<Certificate> list2) {
|
|
if (tlsVersion == null) {
|
|
throw new NullPointerException("tlsVersion == null");
|
|
}
|
|
if (cipherSuite != null) {
|
|
return new Handshake(tlsVersion, cipherSuite, Util.immutableList(list), Util.immutableList(list2));
|
|
}
|
|
throw new NullPointerException("cipherSuite == null");
|
|
}
|
|
}
|