< prev index next >

test/javax/net/ssl/templates/SSLSocketTemplate.java

Print this page
rev 14340 : 8234728: Some security tests should support TLSv1.3
Summary: Tests were updated to support TLSv1.3 and cipher suite order
Reviewed-by: xuelei


 171     protected ContextParameters getClientContextParameters() {
 172         return new ContextParameters("TLS", "PKIX", "NewSunX509");
 173     }
 174 
 175     /*
 176      * Get the server side parameters of SSLContext.
 177      */
 178     protected ContextParameters getServerContextParameters() {
 179         return new ContextParameters("TLS", "PKIX", "NewSunX509");
 180     }
 181 
 182     /*
 183      * Does the client side use customized connection other than
 184      * explicit Socket.connect(), for example, URL.openConnection()?
 185      */
 186     protected boolean isCustomizedClientConnection() {
 187         return false;
 188     }
 189 
 190     /*






 191      * Configure the server side socket.
 192      */
 193     protected void configureServerSocket(SSLServerSocket socket) {
 194 
 195     }
 196 
 197     /*
 198      * =============================================
 199      * Define the client and server side operations.
 200      *
 201      * If the client or server is doing some kind of object creation
 202      * that the other side depends on, and that thread prematurely
 203      * exits, you may experience a hang.  The test harness will
 204      * terminate all hung threads after its timeout has expired,
 205      * currently 3 minutes by default, but you might try to be
 206      * smart about it....
 207      */
 208 
 209     /*
 210      * Is the server ready to serve?
 211      */
 212     private final CountDownLatch serverCondition = new CountDownLatch(1);
 213 
 214     /*


 299                     "The server is not ready yet in 90 seconds. " +
 300                     "Ignore in client side.");
 301             return;
 302         }
 303 
 304         if (isCustomizedClientConnection()) {
 305             // Signal the server, the client is ready to communicate.
 306             clientCondition.countDown();
 307 
 308             // Run the application in client side.
 309             runClientApplication(serverPort);
 310 
 311             return;
 312         }
 313 
 314         SSLContext context = createClientSSLContext();
 315         SSLSocketFactory sslsf = context.getSocketFactory();
 316 
 317         try (SSLSocket sslSocket = (SSLSocket)sslsf.createSocket()) {
 318             try {

 319                 sslSocket.connect(
 320                         new InetSocketAddress("localhost", serverPort), 15000);
 321             } catch (IOException ioe) {
 322                 // The server side may be impacted by naughty test cases or
 323                 // third party routines, and cannot accept connections.
 324                 //
 325                 // Just ignore the test if the connection cannot be
 326                 // established.
 327                 System.out.println(
 328                         "Cannot make a connection in 15 seconds. " +
 329                         "Ignore in client side.");
 330                 return;
 331             }
 332 
 333             // OK, here the client and server get connected.
 334 
 335             // Signal the server, the client is ready to communicate.
 336             clientCondition.countDown();
 337 
 338             // There is still a chance in theory that the server thread may




 171     protected ContextParameters getClientContextParameters() {
 172         return new ContextParameters("TLS", "PKIX", "NewSunX509");
 173     }
 174 
 175     /*
 176      * Get the server side parameters of SSLContext.
 177      */
 178     protected ContextParameters getServerContextParameters() {
 179         return new ContextParameters("TLS", "PKIX", "NewSunX509");
 180     }
 181 
 182     /*
 183      * Does the client side use customized connection other than
 184      * explicit Socket.connect(), for example, URL.openConnection()?
 185      */
 186     protected boolean isCustomizedClientConnection() {
 187         return false;
 188     }
 189 
 190     /*
 191      * Configure the client side socket.
 192      */
 193     protected void configureClientSocket(SSLSocket socket) {
 194     }
 195 
 196     /*
 197      * Configure the server side socket.
 198      */
 199     protected void configureServerSocket(SSLServerSocket socket) {

 200     }
 201 
 202     /*
 203      * =============================================
 204      * Define the client and server side operations.
 205      *
 206      * If the client or server is doing some kind of object creation
 207      * that the other side depends on, and that thread prematurely
 208      * exits, you may experience a hang.  The test harness will
 209      * terminate all hung threads after its timeout has expired,
 210      * currently 3 minutes by default, but you might try to be
 211      * smart about it....
 212      */
 213 
 214     /*
 215      * Is the server ready to serve?
 216      */
 217     private final CountDownLatch serverCondition = new CountDownLatch(1);
 218 
 219     /*


 304                     "The server is not ready yet in 90 seconds. " +
 305                     "Ignore in client side.");
 306             return;
 307         }
 308 
 309         if (isCustomizedClientConnection()) {
 310             // Signal the server, the client is ready to communicate.
 311             clientCondition.countDown();
 312 
 313             // Run the application in client side.
 314             runClientApplication(serverPort);
 315 
 316             return;
 317         }
 318 
 319         SSLContext context = createClientSSLContext();
 320         SSLSocketFactory sslsf = context.getSocketFactory();
 321 
 322         try (SSLSocket sslSocket = (SSLSocket)sslsf.createSocket()) {
 323             try {
 324                 configureClientSocket(sslSocket);
 325                 sslSocket.connect(
 326                         new InetSocketAddress("localhost", serverPort), 15000);
 327             } catch (IOException ioe) {
 328                 // The server side may be impacted by naughty test cases or
 329                 // third party routines, and cannot accept connections.
 330                 //
 331                 // Just ignore the test if the connection cannot be
 332                 // established.
 333                 System.out.println(
 334                         "Cannot make a connection in 15 seconds. " +
 335                         "Ignore in client side.");
 336                 return;
 337             }
 338 
 339             // OK, here the client and server get connected.
 340 
 341             // Signal the server, the client is ready to communicate.
 342             clientCondition.countDown();
 343 
 344             // There is still a chance in theory that the server thread may


< prev index next >