Skip to content

Commit 6c1edef

Browse files
committed
fix ssl read error with clash
1 parent 4027644 commit 6c1edef

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

patches/0001-anti-dpi.patch

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -141,39 +141,35 @@ new file mode 100644
141141
index 000000000..1227df551
142142
--- /dev/null
143143
+++ b/app/src/main/kotlin/com/hippo/ehviewer/client/EhSSLSocketFactory.kt
144-
@@ -0,0 +1,41 @@
144+
@@ -0,0 +1,37 @@
145145
+package com.hippo.ehviewer.client
146146
+
147147
+import android.util.Log
148148
+import com.hippo.ehviewer.Settings
149149
+import java.net.InetAddress
150150
+import java.net.Socket
151151
+import java.security.KeyStore
152-
+import javax.net.ssl.SSLContext
153152
+import javax.net.ssl.SSLSocket
154153
+import javax.net.ssl.SSLSocketFactory
155154
+import javax.net.ssl.TrustManagerFactory
156155
+import javax.net.ssl.X509TrustManager
157156
+import okhttp3.OkHttpClient
158157
+
159158
+const val EXCEPTIONAL_DOMAIN = "hath.network"
160-
+private val sslSocketFactory: SSLSocketFactory = SSLContext.getInstance("TLS").apply {
161-
+ init(null, null, null)
162-
+}.socketFactory
159+
+private val sslSocketFactory = SSLSocketFactory.getDefault() as SSLSocketFactory
163160
+
164161
+object EhSSLSocketFactory : SSLSocketFactory() {
165162
+ override fun getDefaultCipherSuites(): Array<String> = sslSocketFactory.defaultCipherSuites
166163
+ override fun getSupportedCipherSuites(): Array<String> = sslSocketFactory.supportedCipherSuites
167-
+ override fun createSocket(s: Socket, host: String, port: Int, autoClose: Boolean): Socket = sslSocketFactory.createSocket(s, resolveHost(s, host), port, autoClose) as SSLSocket
168-
+
164+
+ override fun createSocket(s: Socket, host: String, port: Int, autoClose: Boolean): Socket {
165+
+ val address = s.inetAddress.hostAddress.takeIf { host in dFEnabledDomains || EXCEPTIONAL_DOMAIN in host }
166+
+ Log.d("EhSSLSocketFactory", "Host: $host Address: $address")
167+
+ return sslSocketFactory.createSocket(s, address ?: host, port, autoClose) as SSLSocket
168+
+ }
169169
+ override fun createSocket(host: String, port: Int): Socket = sslSocketFactory.createSocket(host, port)
170170
+ override fun createSocket(host: String, port: Int, localHost: InetAddress, localPort: Int): Socket = sslSocketFactory.createSocket(host, port, localHost, localPort)
171171
+ override fun createSocket(host: InetAddress, port: Int): Socket = sslSocketFactory.createSocket(host, port)
172172
+ override fun createSocket(address: InetAddress, port: Int, localAddress: InetAddress, localPort: Int): Socket = sslSocketFactory.createSocket(address, port, localAddress, localPort)
173-
+
174-
+ private fun resolveHost(socket: Socket, host: String): String = socket.inetAddress.hostAddress.takeIf {
175-
+ host in dFEnabledDomains || EXCEPTIONAL_DOMAIN in host
176-
+ } ?: host
177173
+}
178174
+
179175
+fun OkHttpClient.Builder.install(sslSocketFactory: SSLSocketFactory) = apply {

0 commit comments

Comments
 (0)