|
10 | 10 |
|
11 | 11 | package at.bitfire.cert4android |
12 | 12 |
|
13 | | -import androidx.annotation.VisibleForTesting |
14 | | -import kotlinx.coroutines.flow.StateFlow |
15 | 13 | import org.junit.Assume.assumeNotNull |
16 | 14 | import org.junit.Before |
17 | 15 | import org.junit.Test |
18 | 16 | import java.io.IOException |
| 17 | +import java.net.InetSocketAddress |
| 18 | +import java.net.Socket |
19 | 19 | import java.net.URL |
20 | 20 | import java.security.SecureRandom |
21 | 21 | import java.security.cert.CertificateException |
22 | 22 | import java.security.cert.X509Certificate |
23 | | -import java.util.logging.Level |
24 | | -import java.util.logging.Logger |
25 | 23 | import javax.net.ssl.SSLContext |
26 | 24 | import javax.net.ssl.SSLSocket |
27 | 25 | import javax.net.ssl.TrustManager |
@@ -117,9 +115,14 @@ class CustomCertManagerTest { |
117 | 115 | } |
118 | 116 |
|
119 | 117 | // Create an SSL socket and force a TLS handshake |
120 | | - // (HttpsURLConnection performs the handshake lazily and sometimes the handshake is not |
121 | | - // executed before this method gets called) |
122 | | - sslContext.socketFactory.createSocket(host, port).use { socket -> |
| 118 | + val socket = Socket().apply { |
| 119 | + soTimeout = 5000 // read timeout |
| 120 | + connect( |
| 121 | + InetSocketAddress(host, port), |
| 122 | + 5000 // connect timeout |
| 123 | + ) |
| 124 | + } |
| 125 | + sslContext.socketFactory.createSocket(socket, host, port, true).use { socket -> |
123 | 126 | val sslSocket = socket as SSLSocket |
124 | 127 | // Explicitly start the handshake (gets certificate) |
125 | 128 | sslSocket.startHandshake() |
|
0 commit comments