OkHostnameVerifier.java
5.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
package com.squareup.okhttp.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 java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLException;
import javax.net.ssl.SSLSession;
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 static final Pattern VERIFY_AS_IP_ADDRESS = Pattern.compile("([0-9a-fA-F]*:[0-9a-fA-F:.]*)|([\\d.]+)");
public static List<String> allSubjectAltNames(X509Certificate paramX509Certificate)
{
List localList = getSubjectAltNames(paramX509Certificate, 7);
paramX509Certificate = getSubjectAltNames(paramX509Certificate, 2);
ArrayList localArrayList = new ArrayList(localList.size() + paramX509Certificate.size());
localArrayList.addAll(localList);
localArrayList.addAll(paramX509Certificate);
return localArrayList;
}
private static List<String> getSubjectAltNames(X509Certificate paramX509Certificate, int paramInt)
{
localArrayList = new ArrayList();
try
{
paramX509Certificate = paramX509Certificate.getSubjectAlternativeNames();
if (paramX509Certificate == null) {
return Collections.emptyList();
}
paramX509Certificate = paramX509Certificate.iterator();
while (paramX509Certificate.hasNext())
{
Object localObject = (List)paramX509Certificate.next();
if ((localObject != null) && (((List)localObject).size() >= 2))
{
Integer localInteger = (Integer)((List)localObject).get(0);
if ((localInteger != null) && (localInteger.intValue() == paramInt))
{
localObject = (String)((List)localObject).get(1);
if (localObject != null) {
localArrayList.add(localObject);
}
}
}
}
return localArrayList;
}
catch (CertificateParsingException paramX509Certificate)
{
return Collections.emptyList();
}
}
static boolean verifyAsIpAddress(String paramString)
{
return VERIFY_AS_IP_ADDRESS.matcher(paramString).matches();
}
private boolean verifyHostName(String paramString1, String paramString2)
{
if ((paramString1 == null) || (paramString1.length() == 0) || (paramString1.startsWith(".")) || (paramString1.endsWith(".."))) {}
String str;
int i;
do
{
do
{
do
{
do
{
return false;
} while ((paramString2 == null) || (paramString2.length() == 0) || (paramString2.startsWith(".")) || (paramString2.endsWith("..")));
str = paramString1;
if (!paramString1.endsWith(".")) {
str = paramString1 + '.';
}
paramString1 = paramString2;
if (!paramString2.endsWith(".")) {
paramString1 = paramString2 + '.';
}
paramString1 = paramString1.toLowerCase(Locale.US);
if (!paramString1.contains("*")) {
return str.equals(paramString1);
}
} while ((!paramString1.startsWith("*.")) || (paramString1.indexOf('*', 1) != -1) || (str.length() < paramString1.length()) || ("*.".equals(paramString1)));
paramString1 = paramString1.substring(1);
} while (!str.endsWith(paramString1));
i = str.length() - paramString1.length();
} while ((i > 0) && (str.lastIndexOf('.', i - 1) != -1));
return true;
}
private boolean verifyHostName(String paramString, X509Certificate paramX509Certificate)
{
paramString = paramString.toLowerCase(Locale.US);
List localList = getSubjectAltNames(paramX509Certificate, 2);
int k = localList.size();
int j = 0;
for (int i = 0; j < k; i = 1)
{
if (verifyHostName(paramString, (String)localList.get(j))) {
return true;
}
j += 1;
}
if (i == 0)
{
paramX509Certificate = new DistinguishedNameParser(paramX509Certificate.getSubjectX500Principal()).findMostSpecific("cn");
if (paramX509Certificate != null) {
return verifyHostName(paramString, paramX509Certificate);
}
}
return false;
}
private boolean verifyIpAddress(String paramString, X509Certificate paramX509Certificate)
{
paramX509Certificate = getSubjectAltNames(paramX509Certificate, 7);
int j = paramX509Certificate.size();
int i = 0;
while (i < j)
{
if (paramString.equalsIgnoreCase((String)paramX509Certificate.get(i))) {
return true;
}
i += 1;
}
return false;
}
public final boolean verify(String paramString, X509Certificate paramX509Certificate)
{
if (verifyAsIpAddress(paramString)) {
return verifyIpAddress(paramString, paramX509Certificate);
}
return verifyHostName(paramString, paramX509Certificate);
}
public final boolean verify(String paramString, SSLSession paramSSLSession)
{
try
{
boolean bool = verify(paramString, (X509Certificate)paramSSLSession.getPeerCertificates()[0]);
return bool;
}
catch (SSLException paramString) {}
return false;
}
}
/* Location: /home/merong/decompile/hackery-dex2jar.jar!/com/squareup/okhttp/internal/tls/OkHostnameVerifier.class
* Java compiler version: 6 (50.0)
* JD-Core Version: 0.7.1
*/