Skip to content

Commit

Permalink
Use DoH for Nebulos own internal HTTP calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Ch4t4r committed Aug 20, 2021
1 parent c10783e commit b384aee
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ dependencies {
leakCanaryImplementation 'com.squareup.leakcanary:leakcanary-android:2.7'

implementation "com.squareup.okhttp3:okhttp:4.9.1"
implementation 'com.squareup.okhttp3:okhttp-dnsoverhttps:4.9.1'
implementation 'com.github.AppIntro:AppIntro:6.0.0'

storeImplementation 'com.google.android.play:core:1.10.0'
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/java/com/frostnerd/smokescreen/Globals.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ import com.frostnerd.encrypteddnstunnelproxy.quic.AbstractQuicDnsHandle
import com.frostnerd.encrypteddnstunnelproxy.quic.QuicUpstreamAddress
import com.frostnerd.encrypteddnstunnelproxy.tls.AbstractTLSDnsHandle
import kotlinx.android.synthetic.main.dialog_privacypolicy.view.*
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.OkHttpClient
import okhttp3.dnsoverhttps.DnsOverHttps
import okhttp3.internal.toHexString
import java.net.InetAddress
import java.util.*


Expand Down Expand Up @@ -138,4 +142,11 @@ fun createQuicEngineIfInstalled(context: Context, quicOnly:Boolean, vararg addre
return if (QuicEngineImpl.providerInstalled) {
QuicEngineImpl(context, quicOnly, *addresses)
} else null
}

fun okhttpClientWithDoh(): OkHttpClient {
val clientForDoh = OkHttpClient()
val dns = DnsOverHttps.Builder().client(clientForDoh).url("https://1.1.1.1/dns-query".toHttpUrl())
.bootstrapDnsHosts(InetAddress.getByName("1.1.1.1"), InetAddress.getByName("1.0.0.1")).build()
return OkHttpClient.Builder().dns(dns).build()
}
2 changes: 1 addition & 1 deletion app/src/main/java/com/frostnerd/smokescreen/SmokeScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ class SmokeScreen : Application() {
if(configServer.isNotBlank() && configServer.startsWith("http") && !configServer.contains("@")) {
log("Dynamically retrieving Sentry DSN from $configServer")
val request = Request.Builder().url(configServer).build()
OkHttpClient.Builder().build().newCall(request).enqueue(object : Callback {
okhttpClientWithDoh().newCall(request).enqueue(object : Callback {
override fun onFailure(call: Call, e: IOException) {
log("Sentry DSN retrieval failed with error: ${e.message}")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class RuleImportService : IntentService("RuleImportService") {
}

private val httpClient by lazy(LazyThreadSafetyMode.NONE) {
OkHttpClient()
okhttpClientWithDoh()
}

override fun attachBaseContext(newBase: Context) {
Expand Down

3 comments on commit b384aee

@ignoramous
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! :D

@Ch4t4r
Copy link
Owner Author

@Ch4t4r Ch4t4r commented on b384aee Aug 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I was already using DoH for the internal DNS queries, it just isn't as obvious :D This way is more concise though

https://github.com/Ch4t4r/Nebulo/blob/master/app/src/main/java/com/frostnerd/smokescreen/SmokeScreen.kt#L72 (it's called fallback DNS in the code, but is just an internal DNS server)

@ignoramous
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I must say: Concise code is easier to understand... ;)

Please sign in to comment.