Skip to content

Commit 36d66d0

Browse files
committed
Accept only valid hostnames and certificates
1 parent e7a62c4 commit 36d66d0

File tree

1 file changed

+0
-17
lines changed

1 file changed

+0
-17
lines changed

lib/src/test/java/at/bitfire/cert4android/CustomCertManagerTest.kt

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,9 @@ import org.junit.BeforeClass
1616
import org.junit.Test
1717
import java.io.IOException
1818
import java.net.URL
19-
import java.security.SecureRandom
2019
import java.security.cert.CertificateException
2120
import java.security.cert.X509Certificate
22-
import javax.net.ssl.HostnameVerifier
2321
import javax.net.ssl.HttpsURLConnection
24-
import javax.net.ssl.SSLContext
25-
import javax.net.ssl.TrustManager
26-
import javax.net.ssl.X509TrustManager
2722

2823
class CustomCertManagerTest {
2924

@@ -101,18 +96,6 @@ class CustomCertManagerTest {
10196
try {
10297
conn.connectTimeout = 5000
10398
conn.readTimeout = 5000
104-
conn.hostnameVerifier = HostnameVerifier { _, _ -> true }
105-
conn.sslSocketFactory = SSLContext.getInstance("TLS").apply {
106-
init(
107-
null,
108-
arrayOf<TrustManager>(object : X509TrustManager {
109-
override fun checkClientTrusted(chain: Array<out X509Certificate>?, authType: String?) {}
110-
override fun checkServerTrusted(chain: Array<out X509Certificate>?, authType: String?) {}
111-
override fun getAcceptedIssuers(): Array<X509Certificate> = emptyArray()
112-
}),
113-
SecureRandom()
114-
)
115-
}.socketFactory
11699
conn.inputStream.use { stream ->
117100
stream.read()
118101
val certs = mutableListOf<X509Certificate>()

0 commit comments

Comments
 (0)