|
10 | 10 |
|
11 | 11 | package at.bitfire.cert4android |
12 | 12 |
|
13 | | -import android.net.SSLCertificateSocketFactory |
14 | 13 | import org.apache.http.conn.ssl.AllowAllHostnameVerifier |
15 | 14 | import org.junit.Assume.assumeNotNull |
16 | 15 | import org.junit.Before |
17 | 16 | import org.junit.Test |
18 | 17 | import java.io.IOException |
19 | 18 | import java.net.URL |
| 19 | +import java.security.SecureRandom |
20 | 20 | import java.security.cert.CertificateException |
21 | 21 | import java.security.cert.X509Certificate |
22 | 22 | import javax.net.ssl.HttpsURLConnection |
| 23 | +import javax.net.ssl.SSLContext |
| 24 | +import javax.net.ssl.TrustManager |
23 | 25 | import javax.net.ssl.X509TrustManager |
24 | 26 |
|
25 | 27 | class CustomCertManagerTest { |
@@ -99,21 +101,17 @@ class CustomCertManagerTest { |
99 | 101 | val conn = url.openConnection() as HttpsURLConnection |
100 | 102 | try { |
101 | 103 | conn.hostnameVerifier = AllowAllHostnameVerifier() |
102 | | - conn.sslSocketFactory = object : SSLCertificateSocketFactory(1000) { |
103 | | - init { |
104 | | - setTrustManagers(arrayOf(object : X509TrustManager { |
105 | | - override fun checkClientTrusted( |
106 | | - chain: Array<out X509Certificate?>?, |
107 | | - authType: String? |
108 | | - ) { /* OK */ } |
109 | | - override fun checkServerTrusted( |
110 | | - chain: Array<out X509Certificate?>?, |
111 | | - authType: String? |
112 | | - ) { /* OK */ } |
113 | | - override fun getAcceptedIssuers(): Array<out X509Certificate?>? = emptyArray() |
114 | | - })) |
115 | | - } |
116 | | - } |
| 104 | + conn.sslSocketFactory = SSLContext.getInstance("TLS").apply { |
| 105 | + init( |
| 106 | + null, |
| 107 | + arrayOf<TrustManager>(object : X509TrustManager { |
| 108 | + override fun checkClientTrusted(chain: Array<out X509Certificate>?, authType: String?) {} |
| 109 | + override fun checkServerTrusted(chain: Array<out X509Certificate>?, authType: String?) {} |
| 110 | + override fun getAcceptedIssuers(): Array<X509Certificate> = emptyArray() |
| 111 | + }), |
| 112 | + SecureRandom() |
| 113 | + ) |
| 114 | + }.socketFactory |
117 | 115 | conn.inputStream.read() |
118 | 116 | val certs = mutableListOf<X509Certificate>() |
119 | 117 | conn.serverCertificates.forEach { certs += it as X509Certificate } |
|
0 commit comments