Skip to content

Commit 9ce3b52

Browse files
committed
asd
1 parent b6407fb commit 9ce3b52

File tree

7 files changed

+467
-453
lines changed

7 files changed

+467
-453
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,11 @@
159159
android:configChanges="screenSize|uiMode"
160160
android:theme="@style/AppTheme.Toolbar"
161161
android:label="@string/filter"/>
162-
<activity
163-
android:name="com.hippo.ehviewer.ui.BlackListActivity"
164-
android:configChanges="screenSize|uiMode"
165-
android:theme="@style/AppTheme.Toolbar"
166-
android:label="@string/blacklist"/>
162+
<!-- <activity-->
163+
<!-- android:name="com.hippo.ehviewer.ui.BlackListActivity"-->
164+
<!-- android:configChanges="screenSize|uiMode"-->
165+
<!-- android:theme="@style/AppTheme.Toolbar"-->
166+
<!-- android:label="@string/blacklist"/>-->
167167
<activity
168168
android:name="com.hippo.ehviewer.ui.SetSecurityActivity"
169169
android:configChanges="screenSize|uiMode"

app/src/main/java/com/hippo/ehviewer/EhApplication.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@
6868
import java.util.List;
6969
import java.util.concurrent.TimeUnit;
7070

71+
import javax.net.ssl.HostnameVerifier;
7172
import javax.net.ssl.SSLContext;
73+
import javax.net.ssl.SSLSession;
7274

7375
import okhttp3.Cache;
7476
import okhttp3.ConnectionSpec;
@@ -319,6 +321,13 @@ public static OkHttpClient getOkHttpClient(@NonNull Context context) {
319321
.writeTimeout(10, TimeUnit.SECONDS)
320322
.cookieJar(getEhCookieStore(application))
321323
.dns(new EhDns(application))
324+
.hostnameVerifier(new HostnameVerifier() {
325+
@Override
326+
public boolean verify(String hostname, SSLSession session) {
327+
//强行返回true 即验证成功
328+
return true;
329+
}
330+
})
322331
.proxySelector(getEhProxySelector(application))
323332
).build();
324333
}
@@ -508,3 +517,4 @@ public static OkHttpClient.Builder enableTls120nPreLollipop(OkHttpClient.Builder
508517
return client;
509518
}
510519
}
520+

app/src/main/java/com/hippo/ehviewer/client/EhDns.java

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -21,51 +21,42 @@
2121
*/
2222

2323
import android.content.Context;
24+
25+
import androidx.annotation.NonNull;
26+
2427
import com.hippo.ehviewer.EhApplication;
2528
import com.hippo.ehviewer.Hosts;
2629
import com.hippo.ehviewer.Settings;
30+
2731
import java.net.InetAddress;
2832
import java.net.UnknownHostException;
2933
import java.util.Arrays;
30-
import java.util.Collections;
3134
import java.util.HashMap;
3235
import java.util.List;
3336
import java.util.Map;
37+
3438
import okhttp3.Dns;
3539
import okhttp3.HttpUrl;
3640
import okhttp3.OkHttpClient;
3741
import okhttp3.dnsoverhttps.DnsOverHttps;
3842

3943
public class EhDns implements Dns {
4044

41-
private static final Map<String, InetAddress> builtInHosts;
45+
private static final Map<String, List<InetAddress>> builtInHosts;
4246

4347
static {
44-
Map<String, InetAddress> map = new HashMap<>();
45-
put(map, "e-hentai.org", "104.20.26.25");
46-
put(map, "exhentai.org", "178.175.132.20");
47-
put(map, "repo.e-hentai.org", "94.100.29.73");
48+
Map<String, List<InetAddress>> map = new HashMap<>();
49+
put(map, "e-hentai.org", "104.20.26.25+104.20.27.25");
50+
put(map, "repo.e-hentai.org", "94.100.28.57");
4851
put(map, "forums.e-hentai.org", "94.100.18.243");
49-
put(map, "ehgt.org", "178.162.139.24");
50-
put(map, "ul.ehgt.org", "94.100.24.82");
51-
put(map, "github.com", "192.30.255.112");
52-
put(map, "raw.githubusercontent.com", "151.101.0.133");
52+
put(map, "ehgt.org", "37.48.89.44+178.162.139.24+178.162.140.212+81.171.10.48");
53+
put(map, "ul.ehgt.org", "94.100.24.82+94.100.24.72");
5354
builtInHosts = map;
5455
}
5556

56-
private static void put(Map<String, InetAddress> map, String host, String ip) {
57-
InetAddress address = Hosts.toInetAddress(host, ip);
58-
if (address != null) {
59-
map.put(host, address);
60-
}
61-
}
62-
6357
private final Hosts hosts;
6458
private static DnsOverHttps dnsOverHttps;
6559

66-
// public EhDns(Context context) {
67-
// hosts = EhApplication.getHosts(context);
68-
// }
6960
public EhDns(Context context) {
7061
hosts = EhApplication.getHosts(context);
7162
DnsOverHttps.Builder builder = new DnsOverHttps.Builder()
@@ -87,24 +78,31 @@ public EhDns(Context context) {
8778
dnsOverHttps = builder.post(true).build();
8879
}
8980

90-
@Override
91-
public List<InetAddress> lookup(String hostname) throws UnknownHostException {
92-
if (hostname == null) throw new UnknownHostException("hostname == null");
93-
94-
InetAddress inetAddress = hosts.get(hostname);
95-
if (inetAddress != null) {
96-
return Collections.singletonList(inetAddress);
81+
private static void put(Map<String, List<InetAddress>> map, String host, String ip_s) {
82+
String[] ip_l = ip_s.split("\\+");
83+
InetAddress[] addr_l = new InetAddress[ip_l.length];
84+
for (int i = 0;i < ip_l.length;i++) {
85+
addr_l[i] = Hosts.toInetAddress(host, ip_l[i]);
9786
}
87+
map.put(host, Arrays.asList(addr_l));
88+
}
9889

90+
@NonNull
91+
@Override
92+
public List<InetAddress> lookup(@NonNull String hostname) throws UnknownHostException {
93+
hostname = hostname.replaceFirst("h.github.io", "hentai.org"); // domain fronting
94+
List<InetAddress> inetAddresses = (List<InetAddress>) hosts.get(hostname);
95+
if (inetAddresses != null) {
96+
return inetAddresses;
97+
}
9998
if (Settings.getBuiltInHosts()) {
100-
inetAddress = builtInHosts.get(hostname);
101-
if (inetAddress != null) {
102-
return Collections.singletonList(inetAddress);
99+
inetAddresses = builtInHosts.get(hostname);
100+
if (inetAddresses != null) {
101+
return inetAddresses;
103102
}
104103
}
105-
106104
if (Settings.getDoH()) {
107-
List<InetAddress> inetAddresses = dnsOverHttps.lookup(hostname);
105+
inetAddresses = dnsOverHttps.lookup(hostname);
108106
if (inetAddresses != null && inetAddresses.size() > 0) {
109107
return inetAddresses;
110108
}
@@ -113,7 +111,7 @@ public List<InetAddress> lookup(String hostname) throws UnknownHostException {
113111
return Arrays.asList(InetAddress.getAllByName(hostname));
114112
} catch (NullPointerException e) {
115113
UnknownHostException unknownHostException =
116-
new UnknownHostException("Broken system behaviour for dns lookup of " + hostname);
114+
new UnknownHostException("Broken system behaviour for dns lookup of " + hostname);
117115
unknownHostException.initCause(e);
118116
throw unknownHostException;
119117
}

0 commit comments

Comments
 (0)