test/jdk/sun/security/ssl/SSLSocketImpl/RejectClientRenego.java
changeset 50768 68fa3d4026ea
parent 47216 71c04702a3d5
equal deleted inserted replaced
50767:356eaea05bf0 50768:68fa3d4026ea
     1 /*
     1 /*
     2  * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    26 
    26 
    27 /*
    27 /*
    28  * @test
    28  * @test
    29  * @bug 7188658
    29  * @bug 7188658
    30  * @summary Add possibility to disable client initiated renegotiation
    30  * @summary Add possibility to disable client initiated renegotiation
    31  * @run main/othervm RejectClientRenego true
    31  * @run main/othervm RejectClientRenego true SSLv3
    32  * @run main/othervm RejectClientRenego false
    32  * @run main/othervm RejectClientRenego false SSLv3
       
    33  * @run main/othervm RejectClientRenego true TLSv1
       
    34  * @run main/othervm RejectClientRenego false TLSv1
       
    35  * @run main/othervm RejectClientRenego true TLSv1.1
       
    36  * @run main/othervm RejectClientRenego false TLSv1.1
       
    37  * @run main/othervm RejectClientRenego true TLSv1.2
       
    38  * @run main/othervm RejectClientRenego false TLSv1.2
    33  */
    39  */
    34 
    40 
    35 import java.io.*;
    41 import java.io.*;
    36 import java.net.*;
    42 import java.net.*;
       
    43 import java.security.Security;
    37 import javax.net.ssl.*;
    44 import javax.net.ssl.*;
    38 
    45 
    39 public class RejectClientRenego implements
    46 public class RejectClientRenego implements
    40         HandshakeCompletedListener {
    47         HandshakeCompletedListener {
    41 
    48 
   111          * Signal Client, we're ready for his connect.
   118          * Signal Client, we're ready for his connect.
   112          */
   119          */
   113         serverReady = true;
   120         serverReady = true;
   114 
   121 
   115         SSLSocket sslSocket = (SSLSocket) sslServerSocket.accept();
   122         SSLSocket sslSocket = (SSLSocket) sslServerSocket.accept();
       
   123         sslSocket.setEnabledProtocols(new String[] { tlsProtocol });
   116         sslSocket.addHandshakeCompletedListener(this);
   124         sslSocket.addHandshakeCompletedListener(this);
   117         InputStream sslIS = sslSocket.getInputStream();
   125         InputStream sslIS = sslSocket.getInputStream();
   118         OutputStream sslOS = sslSocket.getOutputStream();
   126         OutputStream sslOS = sslSocket.getOutputStream();
   119 
   127 
   120         for (int i = 0; i < 10; i++) {
   128         for (int i = 0; i < 10; i++) {
   155 
   163 
   156         SSLSocketFactory sslsf =
   164         SSLSocketFactory sslsf =
   157             (SSLSocketFactory) SSLSocketFactory.getDefault();
   165             (SSLSocketFactory) SSLSocketFactory.getDefault();
   158         SSLSocket sslSocket = (SSLSocket)
   166         SSLSocket sslSocket = (SSLSocket)
   159             sslsf.createSocket("localhost", serverPort);
   167             sslsf.createSocket("localhost", serverPort);
       
   168         sslSocket.setEnabledProtocols(new String[] { tlsProtocol });
   160 
   169 
   161         InputStream sslIS = sslSocket.getInputStream();
   170         InputStream sslIS = sslSocket.getInputStream();
   162         OutputStream sslOS = sslSocket.getOutputStream();
   171         OutputStream sslOS = sslSocket.getOutputStream();
   163 
   172 
   164         for (int i = 0; i < 10; i++) {
   173         for (int i = 0; i < 10; i++) {
   200     volatile Exception clientException = null;
   209     volatile Exception clientException = null;
   201 
   210 
   202     // Is it abbreviated handshake?
   211     // Is it abbreviated handshake?
   203     private static boolean isAbbreviated = false;
   212     private static boolean isAbbreviated = false;
   204 
   213 
       
   214     // the specified protocol
       
   215     private static String tlsProtocol;
       
   216 
   205     public static void main(String[] args) throws Exception {
   217     public static void main(String[] args) throws Exception {
   206         String keyFilename =
   218         String keyFilename =
   207             System.getProperty("test.src", "./") + "/" + pathToStores +
   219             System.getProperty("test.src", "./") + "/" + pathToStores +
   208                 "/" + keyStoreFile;
   220                 "/" + keyStoreFile;
   209         String trustFilename =
   221         String trustFilename =
   217 
   229 
   218         // reject client initialized SSL renegotiation.
   230         // reject client initialized SSL renegotiation.
   219         System.setProperty(
   231         System.setProperty(
   220             "jdk.tls.rejectClientInitiatedRenegotiation", "true");
   232             "jdk.tls.rejectClientInitiatedRenegotiation", "true");
   221 
   233 
   222         if (debug)
   234         if (debug) {
   223             System.setProperty("javax.net.debug", "all");
   235             System.setProperty("javax.net.debug", "all");
       
   236         }
       
   237 
       
   238         Security.setProperty("jdk.tls.disabledAlgorithms", "");
   224 
   239 
   225         // Is it abbreviated handshake?
   240         // Is it abbreviated handshake?
   226         if ("true".equals(args[0])) {
   241         if ("true".equals(args[0])) {
   227             isAbbreviated = true;
   242             isAbbreviated = true;
   228         }
   243         }
       
   244 
       
   245         tlsProtocol = args[1];
   229 
   246 
   230         /*
   247         /*
   231          * Start the tests.
   248          * Start the tests.
   232          */
   249          */
   233         new RejectClientRenego();
   250         new RejectClientRenego();