Skip to content

Commit

Permalink
update okhttp
Browse files Browse the repository at this point in the history
use doh
  • Loading branch information
chenjia404 committed Jun 29, 2023
1 parent 32dccdc commit 66b52e8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ glideVersion=4.11.0
kovenantVersion=3.3.0
curve25519Version=0.6.0
protobufVersion=2.5.0
okhttpVersion=3.12.1
okhttpVersion=4.11.0
jacksonDatabindVersion=2.9.8
appcompatVersion=1.5.1
materialVersion=1.7.0
Expand Down
34 changes: 24 additions & 10 deletions libsignal/src/main/java/org/session/libsignal/utilities/HTTP.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import okhttp3.Request
import okhttp3.RequestBody
import okhttp3.Response
import okhttp3.dnsoverhttps.DnsOverHttps
import java.net.InetAddress
import java.security.SecureRandom
import java.security.cert.X509Certificate
import java.util.concurrent.TimeUnit
Expand All @@ -16,8 +17,17 @@ import javax.net.ssl.X509TrustManager
object HTTP {
var isConnectedToNetwork: (() -> Boolean) = { false }




private val seedNodeConnection by lazy {
OkHttpClient().newBuilder()
val bootstrapClient = OkHttpClient.Builder().build()
val dns =DnsOverHttps.Builder().client(bootstrapClient)
.url("https://1.1.1.1/dns-query".toHttpUrl())
.bootstrapDnsHosts(InetAddress.getByName("8.8.4.4"), InetAddress.getByName("8.8.8.8"))
.build()
bootstrapClient.newBuilder()
.dns(dns)
.callTimeout(timeout, TimeUnit.SECONDS)
.connectTimeout(timeout, TimeUnit.SECONDS)
.readTimeout(timeout, TimeUnit.SECONDS)
Expand All @@ -27,10 +37,6 @@ object HTTP {

private val defaultConnection by lazy {

val dns = DnsOverHttps.Builder()
.url("https://1.1.1.1/dns-query".toHttpUrl())
.build()

// Snode to snode communication uses self-signed certificates but clients can safely ignore this
val trustManager = object : X509TrustManager {

Expand All @@ -40,7 +46,13 @@ object HTTP {
}
val sslContext = SSLContext.getInstance("SSL")
sslContext.init(null, arrayOf( trustManager ), SecureRandom())
OkHttpClient().newBuilder()

val bootstrapClient = OkHttpClient.Builder().build()
val dns =DnsOverHttps.Builder().client(bootstrapClient)
.url("https://1.1.1.1/dns-query".toHttpUrl())
.bootstrapDnsHosts(InetAddress.getByName("8.8.4.4"), InetAddress.getByName("8.8.8.8"))
.build()
bootstrapClient.newBuilder()
.dns(dns)
.sslSocketFactory(sslContext.socketFactory, trustManager)
.hostnameVerifier { _, _ -> true }
Expand All @@ -62,12 +74,14 @@ object HTTP {
val sslContext = SSLContext.getInstance("SSL")
sslContext.init(null, arrayOf( trustManager ), SecureRandom())

val dns = DnsOverHttps.Builder()
val bootstrapClient = OkHttpClient.Builder().build()
val dns =DnsOverHttps.Builder().client(bootstrapClient)
.url("https://1.1.1.1/dns-query".toHttpUrl())
.bootstrapDnsHosts(InetAddress.getByName("8.8.4.4"), InetAddress.getByName("8.8.8.8"))
.build()


return OkHttpClient().newBuilder()
bootstrapClient.newBuilder()
.dns(dns)
return bootstrapClient.newBuilder()
.dns(dns)
.sslSocketFactory(sslContext.socketFactory, trustManager)
.hostnameVerifier { _, _ -> true }
Expand Down

0 comments on commit 66b52e8

Please sign in to comment.