From 7af9faefdbac7dae28be31075b04b3335b6d2480 Mon Sep 17 00:00:00 2001 From: ne3reda Date: Sun, 11 Apr 2021 16:14:14 +0700 Subject: [PATCH] add DNS Over HTTP setting --- Clover/app/build.gradle | 5 ++- .../chan/core/settings/ChanSettings.java | 4 +++ .../chan/core/site/http/HttpCallManager.java | 33 ++++++++++++++++++- .../BehaviourSettingsController.java | 10 ++++++ Clover/app/src/main/res/values/strings.xml | 4 +++ 5 files changed, 54 insertions(+), 2 deletions(-) diff --git a/Clover/app/build.gradle b/Clover/app/build.gradle index e4bc50ff66..ca04c8acff 100644 --- a/Clover/app/build.gradle +++ b/Clover/app/build.gradle @@ -52,6 +52,7 @@ android { // of the format XXYYZZ, where XX is major, YY is minor, ZZ is patch // (watch out for octal notation, never start with a 0) versionCode 30002 + multiDexEnabled true } compileOptions { @@ -151,6 +152,7 @@ android { } dependencies { + implementation 'com.android.support:multidex:1.0.3' implementation 'androidx.legacy:legacy-support-v13:1.0.0' implementation 'androidx.appcompat:appcompat:1.1.0' implementation 'androidx.recyclerview:recyclerview:1.1.0' @@ -165,7 +167,8 @@ dependencies { implementation 'com.google.android.exoplayer:exoplayer-ui:2.11.7' implementation 'com.android.volley:volley:1.1.1' - implementation 'com.squareup.okhttp3:okhttp:3.10.0' + implementation 'com.squareup.okhttp3:okhttp:5.0.0-alpha.2' + implementation 'com.squareup.okhttp3:okhttp-dnsoverhttps:5.0.0-alpha.2' //noinspection GradleDependency implementation 'com.j256.ormlite:ormlite-core:4.48' //noinspection GradleDependency diff --git a/Clover/app/src/main/java/org/floens/chan/core/settings/ChanSettings.java b/Clover/app/src/main/java/org/floens/chan/core/settings/ChanSettings.java index 840377cd62..43da249286 100644 --- a/Clover/app/src/main/java/org/floens/chan/core/settings/ChanSettings.java +++ b/Clover/app/src/main/java/org/floens/chan/core/settings/ChanSettings.java @@ -162,6 +162,8 @@ public String getKey() { public static final BooleanSetting crashReporting; public static final BooleanSetting useNewCaptchaWindow; + public static final BooleanSetting dnsOverHttps; + static { SettingProvider p = new SharedPreferencesSettingProvider(AndroidUtils.getPreferences()); @@ -253,6 +255,8 @@ public String getKey() { crashReporting = new BooleanSetting(p, "preference_crash_reporting", true); useNewCaptchaWindow = new BooleanSetting(p, "use_new_captcha_window", true); + dnsOverHttps = new BooleanSetting(p, "dns_over_https", false); + // Old (but possibly still in some users phone) // preference_board_view_mode default "list" // preference_board_editor_filler default false diff --git a/Clover/app/src/main/java/org/floens/chan/core/site/http/HttpCallManager.java b/Clover/app/src/main/java/org/floens/chan/core/site/http/HttpCallManager.java index 10a6ecb31a..116da73a07 100644 --- a/Clover/app/src/main/java/org/floens/chan/core/site/http/HttpCallManager.java +++ b/Clover/app/src/main/java/org/floens/chan/core/site/http/HttpCallManager.java @@ -21,6 +21,11 @@ import org.floens.chan.core.di.UserAgentProvider; import org.floens.chan.core.site.Site; import org.floens.chan.core.site.SiteRequestModifier; +import org.floens.chan.utils.Logger; +import org.floens.chan.core.settings.ChanSettings; +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.Arrays; import java.util.concurrent.TimeUnit; @@ -29,13 +34,15 @@ import okhttp3.OkHttpClient; import okhttp3.Request; - +import okhttp3.dnsoverhttps.DnsOverHttps; +import okhttp3.HttpUrl; /** * Manages the {@link HttpCall} executions. */ @Singleton public class HttpCallManager { private static final int TIMEOUT = 30000; + private static final String TAG = "HttpCallManager"; private UserAgentProvider userAgentProvider; private OkHttpClient client; @@ -48,6 +55,30 @@ public HttpCallManager(UserAgentProvider userAgentProvider) { .readTimeout(TIMEOUT, TimeUnit.MILLISECONDS) .writeTimeout(TIMEOUT, TimeUnit.MILLISECONDS) .build(); + if(ChanSettings.dnsOverHttps.get()){ + try { + client = client.newBuilder() + .dns(new DnsOverHttps.Builder().client(client) + .url(HttpUrl.parse("https://cloudflare-dns.com/dns-query")) + .bootstrapDnsHosts(Arrays.asList( + 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") + )) + .build()) + .build(); + + } catch (UnknownHostException e) { + Logger.e(TAG, "Error Dns over https", e); + e.printStackTrace(); + } + } } public void makeHttpCall(HttpCall httpCall, HttpCall.HttpCallback callback) { diff --git a/Clover/app/src/main/java/org/floens/chan/ui/controller/BehaviourSettingsController.java b/Clover/app/src/main/java/org/floens/chan/ui/controller/BehaviourSettingsController.java index dabaf0ec4a..af5110636e 100644 --- a/Clover/app/src/main/java/org/floens/chan/ui/controller/BehaviourSettingsController.java +++ b/Clover/app/src/main/java/org/floens/chan/ui/controller/BehaviourSettingsController.java @@ -186,6 +186,16 @@ private void populatePreferences() { groups.add(proxy); } + + // DNS Over HTTP Group + { + SettingsGroup doh = new SettingsGroup(R.string.setting_group_dns_over_https); + + doh.add(new BooleanSettingView(this, ChanSettings.dnsOverHttps, + R.string.setting_group_dns_enable, R.string.setting_group_dns_enable_description)); + + groups.add(doh); + } } private void setupClearThreadHidesSetting(SettingsGroup post) { diff --git a/Clover/app/src/main/res/values/strings.xml b/Clover/app/src/main/res/values/strings.xml index da12abe096..16c5b61051 100644 --- a/Clover/app/src/main/res/values/strings.xml +++ b/Clover/app/src/main/res/values/strings.xml @@ -499,6 +499,10 @@ Crash reports do not collect any personally identifiable information." Proxy server address Proxy server port + + DNS over HTTPS + Enable DOH (Cloudflare) + Requires app restart to take effect Media