[app] Add DoH (#122)

This commit is contained in:
tehcneko 2021-02-12 23:10:47 +08:00 committed by GitHub
parent 0e38859ed8
commit 905f54d0fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 90 additions and 0 deletions

View File

@ -75,6 +75,7 @@ dependencies {
implementation 'com.takisoft.preferencex:preferencex:1.1.0'
implementation 'com.takisoft.preferencex:preferencex-colorpicker:1.1.0'
implementation 'com.squareup.okhttp3:okhttp:4.9.0'
implementation 'com.squareup.okhttp3:okhttp-dnsoverhttps:4.9.0'
final def markwon_version = '4.6.2'
implementation "io.noties.markwon:core:$markwon_version"
implementation "io.noties.markwon:ext-strikethrough:$markwon_version"

View File

@ -16,6 +16,7 @@ import java.io.StringWriter;
import io.github.lsposed.manager.repo.RepoLoader;
import io.github.lsposed.manager.ui.activity.CrashReportActivity;
import io.github.lsposed.manager.util.DoHDNS;
import okhttp3.Cache;
import okhttp3.OkHttpClient;
@ -78,6 +79,7 @@ public class App extends Application {
if (okHttpClient == null) {
okHttpClient = new OkHttpClient.Builder()
.cache(getOkHttpCache())
.dns(new DoHDNS())
.build();
}
return okHttpClient;

View File

@ -0,0 +1,70 @@
/*
* This file is part of LSPosed.
*
* LSPosed is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LSPosed is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LSPosed. If not, see <https://www.gnu.org/licenses/>.
*
* Copyright (C) 2020 EdXposed Contributors
* Copyright (C) 2021 LSPosed Contributors
*/
package io.github.lsposed.manager.util;
import androidx.annotation.NonNull;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.List;
import io.github.lsposed.manager.App;
import okhttp3.Dns;
import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
import okhttp3.dnsoverhttps.DnsOverHttps;
public class DoHDNS implements Dns {
private static DnsOverHttps dnsOverHttps;
public DoHDNS() {
DnsOverHttps.Builder builder = new DnsOverHttps.Builder()
.client(new OkHttpClient.Builder().build())
.url(HttpUrl.get("https://cloudflare-dns.com/dns-query"));
try {
builder.bootstrapDnsHosts(InetAddress.getByName("162.159.36.1"),
InetAddress.getByName("162.159.46.1"),
InetAddress.getByName("1.1.1.1"),
InetAddress.getByName("1.0.0.1"),
InetAddress.getByName("162.159.132.53"),
InetAddress.getByName("2606:4700:4700::1111"),
InetAddress.getByName("2606:4700:4700::1001"),
InetAddress.getByName("2606:4700:4700::0064"),
InetAddress.getByName("2606:4700:4700::6400"));
} catch (UnknownHostException e) {
e.printStackTrace();
}
dnsOverHttps = builder.post(true).build();
}
@NonNull
@Override
public List<InetAddress> lookup(@NonNull String hostname) throws UnknownHostException {
if (App.getPreferences().getBoolean("doh", false)) {
List<InetAddress> inetAddresses = dnsOverHttps.lookup(hostname);
if (inetAddresses.size() > 0) {
return inetAddresses;
}
}
return SYSTEM.lookup(hostname);
}
}

View File

@ -156,4 +156,7 @@
<string name="module_information_collaborators">Collaborators</string>
<string name="module_release_view_assets">Assets</string>
<string name="menu_open_in_browser">Open in browser</string>
<string name="group_network">Network</string>
<string name="dns_over_http">DNS over HTTPS</string>
<string name="dns_over_http_summary">Workaround DNS poisoning in some nations</string>
</resources>

View File

@ -1,6 +1,20 @@
<?xml version="1.0" encoding="utf-8"?><!--suppress ALL -->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<PreferenceCategory
android:key="group_network"
android:title="@string/group_network"
app:iconSpaceReserved="false">
<SwitchPreferenceCompat
android:defaultValue="false"
android:key="doh"
android:summary="@string/dns_over_http_summary"
android:title="@string/dns_over_http"
android:persistent="false"
app:iconSpaceReserved="false" />
</PreferenceCategory>
<PreferenceCategory
android:title="@string/settings_group_theme"
app:iconSpaceReserved="false">