Initial commit
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
package okhttp3.internal.tls;
|
||||
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.security.cert.Certificate;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import javax.net.ssl.SSLPeerUnverifiedException;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public final class BasicCertificateChainCleaner extends CertificateChainCleaner {
|
||||
private static final int MAX_SIGNERS = 9;
|
||||
private final TrustRootIndex trustRootIndex;
|
||||
|
||||
public BasicCertificateChainCleaner(TrustRootIndex trustRootIndex) {
|
||||
this.trustRootIndex = trustRootIndex;
|
||||
}
|
||||
|
||||
private boolean verifySignature(X509Certificate x509Certificate, X509Certificate x509Certificate2) {
|
||||
if (!x509Certificate.getIssuerDN().equals(x509Certificate2.getSubjectDN())) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
x509Certificate.verify(x509Certificate2.getPublicKey());
|
||||
return true;
|
||||
} catch (GeneralSecurityException unused) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override // okhttp3.internal.tls.CertificateChainCleaner
|
||||
public List<Certificate> clean(List<Certificate> list, String str) throws SSLPeerUnverifiedException {
|
||||
ArrayDeque arrayDeque = new ArrayDeque(list);
|
||||
ArrayList arrayList = new ArrayList();
|
||||
arrayList.add(arrayDeque.removeFirst());
|
||||
boolean z = false;
|
||||
for (int i = 0; i < 9; i++) {
|
||||
X509Certificate x509Certificate = (X509Certificate) arrayList.get(arrayList.size() - 1);
|
||||
X509Certificate findByIssuerAndSignature = this.trustRootIndex.findByIssuerAndSignature(x509Certificate);
|
||||
if (findByIssuerAndSignature == null) {
|
||||
Iterator it = arrayDeque.iterator();
|
||||
while (it.hasNext()) {
|
||||
X509Certificate x509Certificate2 = (X509Certificate) it.next();
|
||||
if (verifySignature(x509Certificate, x509Certificate2)) {
|
||||
it.remove();
|
||||
arrayList.add(x509Certificate2);
|
||||
}
|
||||
}
|
||||
if (z) {
|
||||
return arrayList;
|
||||
}
|
||||
throw new SSLPeerUnverifiedException("Failed to find a trusted cert that signed " + x509Certificate);
|
||||
}
|
||||
if (arrayList.size() > 1 || !x509Certificate.equals(findByIssuerAndSignature)) {
|
||||
arrayList.add(findByIssuerAndSignature);
|
||||
}
|
||||
if (verifySignature(findByIssuerAndSignature, findByIssuerAndSignature)) {
|
||||
return arrayList;
|
||||
}
|
||||
z = true;
|
||||
}
|
||||
throw new SSLPeerUnverifiedException("Certificate chain too long: " + arrayList);
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == this) {
|
||||
return true;
|
||||
}
|
||||
return (obj instanceof BasicCertificateChainCleaner) && ((BasicCertificateChainCleaner) obj).trustRootIndex.equals(this.trustRootIndex);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return this.trustRootIndex.hashCode();
|
||||
}
|
||||
}
|
52
sources/okhttp3/internal/tls/BasicTrustRootIndex.java
Normal file
52
sources/okhttp3/internal/tls/BasicTrustRootIndex.java
Normal file
@@ -0,0 +1,52 @@
|
||||
package okhttp3.internal.tls;
|
||||
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import javax.security.auth.x500.X500Principal;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public final class BasicTrustRootIndex implements TrustRootIndex {
|
||||
private final Map<X500Principal, Set<X509Certificate>> subjectToCaCerts = new LinkedHashMap();
|
||||
|
||||
public BasicTrustRootIndex(X509Certificate... x509CertificateArr) {
|
||||
for (X509Certificate x509Certificate : x509CertificateArr) {
|
||||
X500Principal subjectX500Principal = x509Certificate.getSubjectX500Principal();
|
||||
Set<X509Certificate> set = this.subjectToCaCerts.get(subjectX500Principal);
|
||||
if (set == null) {
|
||||
set = new LinkedHashSet<>(1);
|
||||
this.subjectToCaCerts.put(subjectX500Principal, set);
|
||||
}
|
||||
set.add(x509Certificate);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == this) {
|
||||
return true;
|
||||
}
|
||||
return (obj instanceof BasicTrustRootIndex) && ((BasicTrustRootIndex) obj).subjectToCaCerts.equals(this.subjectToCaCerts);
|
||||
}
|
||||
|
||||
@Override // okhttp3.internal.tls.TrustRootIndex
|
||||
public X509Certificate findByIssuerAndSignature(X509Certificate x509Certificate) {
|
||||
Set<X509Certificate> set = this.subjectToCaCerts.get(x509Certificate.getIssuerX500Principal());
|
||||
if (set == null) {
|
||||
return null;
|
||||
}
|
||||
for (X509Certificate x509Certificate2 : set) {
|
||||
try {
|
||||
x509Certificate.verify(x509Certificate2.getPublicKey());
|
||||
return x509Certificate2;
|
||||
} catch (Exception unused) {
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return this.subjectToCaCerts.hashCode();
|
||||
}
|
||||
}
|
21
sources/okhttp3/internal/tls/CertificateChainCleaner.java
Normal file
21
sources/okhttp3/internal/tls/CertificateChainCleaner.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package okhttp3.internal.tls;
|
||||
|
||||
import java.security.cert.Certificate;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.List;
|
||||
import javax.net.ssl.SSLPeerUnverifiedException;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
import okhttp3.internal.platform.Platform;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public abstract class CertificateChainCleaner {
|
||||
public static CertificateChainCleaner get(X509TrustManager x509TrustManager) {
|
||||
return Platform.get().buildCertificateChainCleaner(x509TrustManager);
|
||||
}
|
||||
|
||||
public abstract List<Certificate> clean(List<Certificate> list, String str) throws SSLPeerUnverifiedException;
|
||||
|
||||
public static CertificateChainCleaner get(X509Certificate... x509CertificateArr) {
|
||||
return new BasicCertificateChainCleaner(new BasicTrustRootIndex(x509CertificateArr));
|
||||
}
|
||||
}
|
419
sources/okhttp3/internal/tls/DistinguishedNameParser.java
Normal file
419
sources/okhttp3/internal/tls/DistinguishedNameParser.java
Normal file
@@ -0,0 +1,419 @@
|
||||
package okhttp3.internal.tls;
|
||||
|
||||
import javax.security.auth.x500.X500Principal;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
final class DistinguishedNameParser {
|
||||
private int beg;
|
||||
private char[] chars;
|
||||
private int cur;
|
||||
private final String dn;
|
||||
private int end;
|
||||
private final int length;
|
||||
private int pos;
|
||||
|
||||
DistinguishedNameParser(X500Principal x500Principal) {
|
||||
this.dn = x500Principal.getName("RFC2253");
|
||||
this.length = this.dn.length();
|
||||
}
|
||||
|
||||
/* JADX WARN: Code restructure failed: missing block: B:24:0x00a7, code lost:
|
||||
|
||||
return new java.lang.String(r1, r2, r8.cur - r2);
|
||||
*/
|
||||
/*
|
||||
Code decompiled incorrectly, please refer to instructions dump.
|
||||
To view partially-correct code enable 'Show inconsistent code' option in preferences
|
||||
*/
|
||||
private java.lang.String escapedAV() {
|
||||
/*
|
||||
r8 = this;
|
||||
int r0 = r8.pos
|
||||
r8.beg = r0
|
||||
r8.end = r0
|
||||
L6:
|
||||
int r0 = r8.pos
|
||||
int r1 = r8.length
|
||||
if (r0 < r1) goto L19
|
||||
java.lang.String r0 = new java.lang.String
|
||||
char[] r1 = r8.chars
|
||||
int r2 = r8.beg
|
||||
int r3 = r8.end
|
||||
int r3 = r3 - r2
|
||||
r0.<init>(r1, r2, r3)
|
||||
return r0
|
||||
L19:
|
||||
char[] r1 = r8.chars
|
||||
char r2 = r1[r0]
|
||||
r3 = 44
|
||||
r4 = 43
|
||||
r5 = 59
|
||||
r6 = 32
|
||||
if (r2 == r6) goto L60
|
||||
if (r2 == r5) goto L53
|
||||
r5 = 92
|
||||
if (r2 == r5) goto L40
|
||||
if (r2 == r4) goto L53
|
||||
if (r2 == r3) goto L53
|
||||
int r2 = r8.end
|
||||
int r3 = r2 + 1
|
||||
r8.end = r3
|
||||
char r3 = r1[r0]
|
||||
r1[r2] = r3
|
||||
int r0 = r0 + 1
|
||||
r8.pos = r0
|
||||
goto L6
|
||||
L40:
|
||||
int r0 = r8.end
|
||||
int r2 = r0 + 1
|
||||
r8.end = r2
|
||||
char r2 = r8.getEscaped()
|
||||
r1[r0] = r2
|
||||
int r0 = r8.pos
|
||||
int r0 = r0 + 1
|
||||
r8.pos = r0
|
||||
goto L6
|
||||
L53:
|
||||
java.lang.String r0 = new java.lang.String
|
||||
char[] r1 = r8.chars
|
||||
int r2 = r8.beg
|
||||
int r3 = r8.end
|
||||
int r3 = r3 - r2
|
||||
r0.<init>(r1, r2, r3)
|
||||
return r0
|
||||
L60:
|
||||
int r2 = r8.end
|
||||
r8.cur = r2
|
||||
int r0 = r0 + 1
|
||||
r8.pos = r0
|
||||
int r0 = r2 + 1
|
||||
r8.end = r0
|
||||
r1[r2] = r6
|
||||
L6e:
|
||||
int r0 = r8.pos
|
||||
int r1 = r8.length
|
||||
if (r0 >= r1) goto L87
|
||||
char[] r1 = r8.chars
|
||||
char r2 = r1[r0]
|
||||
if (r2 != r6) goto L87
|
||||
int r2 = r8.end
|
||||
int r7 = r2 + 1
|
||||
r8.end = r7
|
||||
r1[r2] = r6
|
||||
int r0 = r0 + 1
|
||||
r8.pos = r0
|
||||
goto L6e
|
||||
L87:
|
||||
int r0 = r8.pos
|
||||
int r1 = r8.length
|
||||
if (r0 == r1) goto L9b
|
||||
char[] r1 = r8.chars
|
||||
char r2 = r1[r0]
|
||||
if (r2 == r3) goto L9b
|
||||
char r2 = r1[r0]
|
||||
if (r2 == r4) goto L9b
|
||||
char r0 = r1[r0]
|
||||
if (r0 != r5) goto L6
|
||||
L9b:
|
||||
java.lang.String r0 = new java.lang.String
|
||||
char[] r1 = r8.chars
|
||||
int r2 = r8.beg
|
||||
int r3 = r8.cur
|
||||
int r3 = r3 - r2
|
||||
r0.<init>(r1, r2, r3)
|
||||
return r0
|
||||
*/
|
||||
throw new UnsupportedOperationException("Method not decompiled: okhttp3.internal.tls.DistinguishedNameParser.escapedAV():java.lang.String");
|
||||
}
|
||||
|
||||
private int getByte(int i) {
|
||||
int i2;
|
||||
int i3;
|
||||
int i4 = i + 1;
|
||||
if (i4 >= this.length) {
|
||||
throw new IllegalStateException("Malformed DN: " + this.dn);
|
||||
}
|
||||
char c = this.chars[i];
|
||||
if (c >= '0' && c <= '9') {
|
||||
i2 = c - '0';
|
||||
} else if (c >= 'a' && c <= 'f') {
|
||||
i2 = c - 'W';
|
||||
} else {
|
||||
if (c < 'A' || c > 'F') {
|
||||
throw new IllegalStateException("Malformed DN: " + this.dn);
|
||||
}
|
||||
i2 = c - '7';
|
||||
}
|
||||
char c2 = this.chars[i4];
|
||||
if (c2 >= '0' && c2 <= '9') {
|
||||
i3 = c2 - '0';
|
||||
} else if (c2 >= 'a' && c2 <= 'f') {
|
||||
i3 = c2 - 'W';
|
||||
} else {
|
||||
if (c2 < 'A' || c2 > 'F') {
|
||||
throw new IllegalStateException("Malformed DN: " + this.dn);
|
||||
}
|
||||
i3 = c2 - '7';
|
||||
}
|
||||
return (i2 << 4) + i3;
|
||||
}
|
||||
|
||||
private char getEscaped() {
|
||||
this.pos++;
|
||||
int i = this.pos;
|
||||
if (i == this.length) {
|
||||
throw new IllegalStateException("Unexpected end of DN: " + this.dn);
|
||||
}
|
||||
char c = this.chars[i];
|
||||
if (c != ' ' && c != '%' && c != '\\' && c != '_' && c != '\"' && c != '#') {
|
||||
switch (c) {
|
||||
case '*':
|
||||
case '+':
|
||||
case ',':
|
||||
break;
|
||||
default:
|
||||
switch (c) {
|
||||
case ';':
|
||||
case '<':
|
||||
case '=':
|
||||
case '>':
|
||||
break;
|
||||
default:
|
||||
return getUTF8();
|
||||
}
|
||||
}
|
||||
}
|
||||
return this.chars[this.pos];
|
||||
}
|
||||
|
||||
private char getUTF8() {
|
||||
int i;
|
||||
int i2;
|
||||
int i3 = getByte(this.pos);
|
||||
this.pos++;
|
||||
if (i3 < 128) {
|
||||
return (char) i3;
|
||||
}
|
||||
if (i3 < 192 || i3 > 247) {
|
||||
return '?';
|
||||
}
|
||||
if (i3 <= 223) {
|
||||
i2 = i3 & 31;
|
||||
i = 1;
|
||||
} else if (i3 <= 239) {
|
||||
i = 2;
|
||||
i2 = i3 & 15;
|
||||
} else {
|
||||
i = 3;
|
||||
i2 = i3 & 7;
|
||||
}
|
||||
for (int i4 = 0; i4 < i; i4++) {
|
||||
this.pos++;
|
||||
int i5 = this.pos;
|
||||
if (i5 == this.length || this.chars[i5] != '\\') {
|
||||
return '?';
|
||||
}
|
||||
this.pos = i5 + 1;
|
||||
int i6 = getByte(this.pos);
|
||||
this.pos++;
|
||||
if ((i6 & 192) != 128) {
|
||||
return '?';
|
||||
}
|
||||
i2 = (i2 << 6) + (i6 & 63);
|
||||
}
|
||||
return (char) i2;
|
||||
}
|
||||
|
||||
private String hexAV() {
|
||||
int i = this.pos;
|
||||
if (i + 4 >= this.length) {
|
||||
throw new IllegalStateException("Unexpected end of DN: " + this.dn);
|
||||
}
|
||||
this.beg = i;
|
||||
this.pos = i + 1;
|
||||
while (true) {
|
||||
int i2 = this.pos;
|
||||
if (i2 == this.length) {
|
||||
break;
|
||||
}
|
||||
char[] cArr = this.chars;
|
||||
if (cArr[i2] == '+' || cArr[i2] == ',' || cArr[i2] == ';') {
|
||||
break;
|
||||
}
|
||||
if (cArr[i2] == ' ') {
|
||||
this.end = i2;
|
||||
this.pos = i2 + 1;
|
||||
while (true) {
|
||||
int i3 = this.pos;
|
||||
if (i3 >= this.length || this.chars[i3] != ' ') {
|
||||
break;
|
||||
}
|
||||
this.pos = i3 + 1;
|
||||
}
|
||||
} else {
|
||||
if (cArr[i2] >= 'A' && cArr[i2] <= 'F') {
|
||||
cArr[i2] = (char) (cArr[i2] + ' ');
|
||||
}
|
||||
this.pos++;
|
||||
}
|
||||
}
|
||||
this.end = this.pos;
|
||||
int i4 = this.end;
|
||||
int i5 = this.beg;
|
||||
int i6 = i4 - i5;
|
||||
if (i6 < 5 || (i6 & 1) == 0) {
|
||||
throw new IllegalStateException("Unexpected end of DN: " + this.dn);
|
||||
}
|
||||
byte[] bArr = new byte[i6 / 2];
|
||||
int i7 = i5 + 1;
|
||||
for (int i8 = 0; i8 < bArr.length; i8++) {
|
||||
bArr[i8] = (byte) getByte(i7);
|
||||
i7 += 2;
|
||||
}
|
||||
return new String(this.chars, this.beg, i6);
|
||||
}
|
||||
|
||||
private String nextAT() {
|
||||
while (true) {
|
||||
int i = this.pos;
|
||||
if (i >= this.length || this.chars[i] != ' ') {
|
||||
break;
|
||||
}
|
||||
this.pos = i + 1;
|
||||
}
|
||||
int i2 = this.pos;
|
||||
if (i2 == this.length) {
|
||||
return null;
|
||||
}
|
||||
this.beg = i2;
|
||||
this.pos = i2 + 1;
|
||||
while (true) {
|
||||
int i3 = this.pos;
|
||||
if (i3 >= this.length) {
|
||||
break;
|
||||
}
|
||||
char[] cArr = this.chars;
|
||||
if (cArr[i3] == '=' || cArr[i3] == ' ') {
|
||||
break;
|
||||
}
|
||||
this.pos = i3 + 1;
|
||||
}
|
||||
int i4 = this.pos;
|
||||
if (i4 >= this.length) {
|
||||
throw new IllegalStateException("Unexpected end of DN: " + this.dn);
|
||||
}
|
||||
this.end = i4;
|
||||
if (this.chars[i4] == ' ') {
|
||||
while (true) {
|
||||
int i5 = this.pos;
|
||||
if (i5 >= this.length) {
|
||||
break;
|
||||
}
|
||||
char[] cArr2 = this.chars;
|
||||
if (cArr2[i5] == '=' || cArr2[i5] != ' ') {
|
||||
break;
|
||||
}
|
||||
this.pos = i5 + 1;
|
||||
}
|
||||
char[] cArr3 = this.chars;
|
||||
int i6 = this.pos;
|
||||
if (cArr3[i6] != '=' || i6 == this.length) {
|
||||
throw new IllegalStateException("Unexpected end of DN: " + this.dn);
|
||||
}
|
||||
}
|
||||
this.pos++;
|
||||
while (true) {
|
||||
int i7 = this.pos;
|
||||
if (i7 >= this.length || this.chars[i7] != ' ') {
|
||||
break;
|
||||
}
|
||||
this.pos = i7 + 1;
|
||||
}
|
||||
int i8 = this.end;
|
||||
int i9 = this.beg;
|
||||
if (i8 - i9 > 4) {
|
||||
char[] cArr4 = this.chars;
|
||||
if (cArr4[i9 + 3] == '.' && (cArr4[i9] == 'O' || cArr4[i9] == 'o')) {
|
||||
char[] cArr5 = this.chars;
|
||||
int i10 = this.beg;
|
||||
if (cArr5[i10 + 1] == 'I' || cArr5[i10 + 1] == 'i') {
|
||||
char[] cArr6 = this.chars;
|
||||
int i11 = this.beg;
|
||||
if (cArr6[i11 + 2] == 'D' || cArr6[i11 + 2] == 'd') {
|
||||
this.beg += 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
char[] cArr7 = this.chars;
|
||||
int i12 = this.beg;
|
||||
return new String(cArr7, i12, this.end - i12);
|
||||
}
|
||||
|
||||
private String quotedAV() {
|
||||
this.pos++;
|
||||
this.beg = this.pos;
|
||||
this.end = this.beg;
|
||||
while (true) {
|
||||
int i = this.pos;
|
||||
if (i == this.length) {
|
||||
throw new IllegalStateException("Unexpected end of DN: " + this.dn);
|
||||
}
|
||||
char[] cArr = this.chars;
|
||||
if (cArr[i] == '\"') {
|
||||
this.pos = i + 1;
|
||||
while (true) {
|
||||
int i2 = this.pos;
|
||||
if (i2 >= this.length || this.chars[i2] != ' ') {
|
||||
break;
|
||||
}
|
||||
this.pos = i2 + 1;
|
||||
}
|
||||
char[] cArr2 = this.chars;
|
||||
int i3 = this.beg;
|
||||
return new String(cArr2, i3, this.end - i3);
|
||||
}
|
||||
if (cArr[i] == '\\') {
|
||||
cArr[this.end] = getEscaped();
|
||||
} else {
|
||||
cArr[this.end] = cArr[i];
|
||||
}
|
||||
this.pos++;
|
||||
this.end++;
|
||||
}
|
||||
}
|
||||
|
||||
public String findMostSpecific(String str) {
|
||||
this.pos = 0;
|
||||
this.beg = 0;
|
||||
this.end = 0;
|
||||
this.cur = 0;
|
||||
this.chars = this.dn.toCharArray();
|
||||
String nextAT = nextAT();
|
||||
if (nextAT == null) {
|
||||
return null;
|
||||
}
|
||||
do {
|
||||
int i = this.pos;
|
||||
if (i == this.length) {
|
||||
return null;
|
||||
}
|
||||
char c = this.chars[i];
|
||||
String escapedAV = c != '\"' ? c != '#' ? (c == '+' || c == ',' || c == ';') ? "" : escapedAV() : hexAV() : quotedAV();
|
||||
if (str.equalsIgnoreCase(nextAT)) {
|
||||
return escapedAV;
|
||||
}
|
||||
int i2 = this.pos;
|
||||
if (i2 >= this.length) {
|
||||
return null;
|
||||
}
|
||||
char[] cArr = this.chars;
|
||||
if (cArr[i2] != ',' && cArr[i2] != ';' && cArr[i2] != '+') {
|
||||
throw new IllegalStateException("Malformed DN: " + this.dn);
|
||||
}
|
||||
this.pos++;
|
||||
nextAT = nextAT();
|
||||
} while (nextAT != null);
|
||||
throw new IllegalStateException("Malformed DN: " + this.dn);
|
||||
}
|
||||
}
|
116
sources/okhttp3/internal/tls/OkHostnameVerifier.java
Normal file
116
sources/okhttp3/internal/tls/OkHostnameVerifier.java
Normal file
@@ -0,0 +1,116 @@
|
||||
package okhttp3.internal.tls;
|
||||
|
||||
import java.security.cert.CertificateParsingException;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.SSLException;
|
||||
import javax.net.ssl.SSLSession;
|
||||
import okhttp3.internal.Util;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public final class OkHostnameVerifier implements HostnameVerifier {
|
||||
private static final int ALT_DNS_NAME = 2;
|
||||
private static final int ALT_IPA_NAME = 7;
|
||||
public static final OkHostnameVerifier INSTANCE = new OkHostnameVerifier();
|
||||
|
||||
private OkHostnameVerifier() {
|
||||
}
|
||||
|
||||
public static List<String> allSubjectAltNames(X509Certificate x509Certificate) {
|
||||
List<String> subjectAltNames = getSubjectAltNames(x509Certificate, 7);
|
||||
List<String> subjectAltNames2 = getSubjectAltNames(x509Certificate, 2);
|
||||
ArrayList arrayList = new ArrayList(subjectAltNames.size() + subjectAltNames2.size());
|
||||
arrayList.addAll(subjectAltNames);
|
||||
arrayList.addAll(subjectAltNames2);
|
||||
return arrayList;
|
||||
}
|
||||
|
||||
private static List<String> getSubjectAltNames(X509Certificate x509Certificate, int i) {
|
||||
Integer num;
|
||||
String str;
|
||||
ArrayList arrayList = new ArrayList();
|
||||
try {
|
||||
Collection<List<?>> subjectAlternativeNames = x509Certificate.getSubjectAlternativeNames();
|
||||
if (subjectAlternativeNames == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
for (List<?> list : subjectAlternativeNames) {
|
||||
if (list != null && list.size() >= 2 && (num = (Integer) list.get(0)) != null && num.intValue() == i && (str = (String) list.get(1)) != null) {
|
||||
arrayList.add(str);
|
||||
}
|
||||
}
|
||||
return arrayList;
|
||||
} catch (CertificateParsingException unused) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean verifyHostname(String str, X509Certificate x509Certificate) {
|
||||
String lowerCase = str.toLowerCase(Locale.US);
|
||||
Iterator<String> it = getSubjectAltNames(x509Certificate, 2).iterator();
|
||||
while (it.hasNext()) {
|
||||
if (verifyHostname(lowerCase, it.next())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean verifyIpAddress(String str, X509Certificate x509Certificate) {
|
||||
List<String> subjectAltNames = getSubjectAltNames(x509Certificate, 7);
|
||||
int size = subjectAltNames.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (str.equalsIgnoreCase(subjectAltNames.get(i))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override // javax.net.ssl.HostnameVerifier
|
||||
public boolean verify(String str, SSLSession sSLSession) {
|
||||
try {
|
||||
return verify(str, (X509Certificate) sSLSession.getPeerCertificates()[0]);
|
||||
} catch (SSLException unused) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean verify(String str, X509Certificate x509Certificate) {
|
||||
if (Util.verifyAsIpAddress(str)) {
|
||||
return verifyIpAddress(str, x509Certificate);
|
||||
}
|
||||
return verifyHostname(str, x509Certificate);
|
||||
}
|
||||
|
||||
public boolean verifyHostname(String str, String str2) {
|
||||
if (str != null && str.length() != 0 && !str.startsWith(".") && !str.endsWith("..") && str2 != null && str2.length() != 0 && !str2.startsWith(".") && !str2.endsWith("..")) {
|
||||
if (!str.endsWith(".")) {
|
||||
str = str + '.';
|
||||
}
|
||||
if (!str2.endsWith(".")) {
|
||||
str2 = str2 + '.';
|
||||
}
|
||||
String lowerCase = str2.toLowerCase(Locale.US);
|
||||
if (!lowerCase.contains("*")) {
|
||||
return str.equals(lowerCase);
|
||||
}
|
||||
if (!lowerCase.startsWith("*.") || lowerCase.indexOf(42, 1) != -1 || str.length() < lowerCase.length() || "*.".equals(lowerCase)) {
|
||||
return false;
|
||||
}
|
||||
String substring = lowerCase.substring(1);
|
||||
if (!str.endsWith(substring)) {
|
||||
return false;
|
||||
}
|
||||
int length = str.length() - substring.length();
|
||||
return length <= 0 || str.lastIndexOf(46, length - 1) == -1;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
8
sources/okhttp3/internal/tls/TrustRootIndex.java
Normal file
8
sources/okhttp3/internal/tls/TrustRootIndex.java
Normal file
@@ -0,0 +1,8 @@
|
||||
package okhttp3.internal.tls;
|
||||
|
||||
import java.security.cert.X509Certificate;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public interface TrustRootIndex {
|
||||
X509Certificate findByIssuerAndSignature(X509Certificate x509Certificate);
|
||||
}
|
Reference in New Issue
Block a user