43 import javax.net.ssl.SSLServerSocket; |
43 import javax.net.ssl.SSLServerSocket; |
44 import javax.net.ssl.SSLServerSocketFactory; |
44 import javax.net.ssl.SSLServerSocketFactory; |
45 import javax.net.ssl.SSLSocket; |
45 import javax.net.ssl.SSLSocket; |
46 import javax.net.ssl.SSLSocketFactory; |
46 import javax.net.ssl.SSLSocketFactory; |
47 import javax.net.ssl.TrustManagerFactory; |
47 import javax.net.ssl.TrustManagerFactory; |
|
48 import java.net.InetAddress; |
48 import java.net.InetSocketAddress; |
49 import java.net.InetSocketAddress; |
49 import java.net.SocketTimeoutException; |
50 import java.net.SocketTimeoutException; |
50 import java.security.KeyStore; |
51 import java.security.KeyStore; |
51 import java.security.PrivateKey; |
52 import java.security.PrivateKey; |
52 import java.security.KeyFactory; |
53 import java.security.KeyFactory; |
220 * What's the server port? Use any free port by default |
221 * What's the server port? Use any free port by default |
221 */ |
222 */ |
222 protected volatile int serverPort = 0; |
223 protected volatile int serverPort = 0; |
223 |
224 |
224 /* |
225 /* |
|
226 * What's the server address? null means binding to the wildcard. |
|
227 */ |
|
228 protected volatile InetAddress serverAddress = null; |
|
229 |
|
230 /* |
225 * Define the server side of the test. |
231 * Define the server side of the test. |
226 */ |
232 */ |
227 protected void doServerSide() throws Exception { |
233 protected void doServerSide() throws Exception { |
228 // kick start the server side service |
234 // kick start the server side service |
229 SSLContext context = createServerSSLContext(); |
235 SSLContext context = createServerSSLContext(); |
230 SSLServerSocketFactory sslssf = context.getServerSocketFactory(); |
236 SSLServerSocketFactory sslssf = context.getServerSocketFactory(); |
231 SSLServerSocket sslServerSocket = |
237 InetAddress serverAddress = this.serverAddress; |
232 (SSLServerSocket)sslssf.createServerSocket(serverPort); |
238 SSLServerSocket sslServerSocket = serverAddress == null ? |
|
239 (SSLServerSocket)sslssf.createServerSocket(serverPort) |
|
240 : (SSLServerSocket)sslssf.createServerSocket(); |
|
241 if (serverAddress != null) { |
|
242 sslServerSocket.bind(new InetSocketAddress(serverAddress, serverPort)); |
|
243 } |
233 configureServerSocket(sslServerSocket); |
244 configureServerSocket(sslServerSocket); |
234 serverPort = sslServerSocket.getLocalPort(); |
245 serverPort = sslServerSocket.getLocalPort(); |
235 |
246 |
236 // Signal the client, the server is ready to accept connection. |
247 // Signal the client, the server is ready to accept connection. |
237 serverCondition.countDown(); |
248 serverCondition.countDown(); |
315 SSLSocketFactory sslsf = context.getSocketFactory(); |
326 SSLSocketFactory sslsf = context.getSocketFactory(); |
316 |
327 |
317 try (SSLSocket sslSocket = (SSLSocket)sslsf.createSocket()) { |
328 try (SSLSocket sslSocket = (SSLSocket)sslsf.createSocket()) { |
318 try { |
329 try { |
319 configureClientSocket(sslSocket); |
330 configureClientSocket(sslSocket); |
320 sslSocket.connect( |
331 InetAddress serverAddress = this.serverAddress; |
321 new InetSocketAddress("localhost", serverPort), 15000); |
332 InetSocketAddress connectAddress = serverAddress == null |
|
333 ? new InetSocketAddress("localhost", serverPort) |
|
334 : new InetSocketAddress(serverAddress, serverPort); |
|
335 sslSocket.connect(connectAddress, 15000); |
322 } catch (IOException ioe) { |
336 } catch (IOException ioe) { |
323 // The server side may be impacted by naughty test cases or |
337 // The server side may be impacted by naughty test cases or |
324 // third party routines, and cannot accept connections. |
338 // third party routines, and cannot accept connections. |
325 // |
339 // |
326 // Just ignore the test if the connection cannot be |
340 // Just ignore the test if the connection cannot be |