< prev index next >

test/jdk/sun/security/ssl/SSLContextImpl/NoOldVersionContext.java

Print this page


   1 /*
   2  * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 // SunJSSE does not support dynamic system properties, no way to re-use
  25 // system properties in samevm/agentvm mode.
  26 
  27 /*
  28  * @test
  29  * @bug 7093640
  30  * @summary Enable TLS 1.1 and TLS 1.2 by default in client side of SunJSSE
  31  * @run main/othervm -Djdk.tls.client.protocols="TLSv1,TLSv1.1,TLSv1.2"
  32  *      NoOldVersionContext
  33  */
  34 
  35 import javax.net.*;
  36 import javax.net.ssl.*;
  37 import java.util.Arrays;
  38 import java.security.Security;













  39 
  40 public class NoOldVersionContext {
  41     static enum ContextVersion {
  42         TLS_CV_01("SSL",
  43                 new String[] {"TLSv1", "TLSv1.1", "TLSv1.2"}),
  44         TLS_CV_02("TLS",
  45                 new String[] {"TLSv1", "TLSv1.1", "TLSv1.2"}),
  46         TLS_CV_03("SSLv3",
  47                 new String[] {"SSLv3", "TLSv1"}),
  48         TLS_CV_04("TLSv1",
  49                 new String[] {"SSLv3", "TLSv1"}),
  50         TLS_CV_05("TLSv1.1",
  51                 new String[] {"SSLv3", "TLSv1", "TLSv1.1"}),
  52         TLS_CV_06("TLSv1.2",
  53                 new String[] {"SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2"}),
  54         TLS_CV_07("Default",


  55                 new String[] {"TLSv1", "TLSv1.1", "TLSv1.2"});
  56 
  57         final String contextVersion;
  58         final String[] enabledProtocols;
  59         final static String[] supportedProtocols = new String[] {
  60                 "SSLv2Hello", "SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2"};
  61 
  62         ContextVersion(String contextVersion, String[] enabledProtocols) {
  63             this.contextVersion = contextVersion;
  64             this.enabledProtocols = enabledProtocols;
  65         }
  66     }
  67 
  68     private static boolean checkProtocols(String[] target, String[] expected) {
  69         boolean success = true;
  70         if (target.length == 0) {
  71             System.out.println("\tError: No protocols");
  72             success = false;
  73         }
  74 
  75         if (!Arrays.equals(target, expected)) {
  76             System.out.println("\tError: Expected to get protocols " +
  77                     Arrays.toString(expected));
  78             System.out.println("\tError: The actual protocols " +
  79                     Arrays.toString(target));
  80             success = false;
  81         }
  82 
  83         return success;

















  84     }
  85 
  86     private static boolean checkCipherSuites(String[] target) {
  87         boolean success = true;
  88         if (target.length == 0) {
  89             System.out.println("\tError: No cipher suites");
  90             success = false;
  91         }
  92 
  93         return success;
  94     }
  95 
  96     public static void main(String[] args) throws Exception {
  97         // reset the security property to make sure that the algorithms
  98         // and keys used in this test are not disabled.
  99         Security.setProperty("jdk.tls.disabledAlgorithms", "");
 100 
 101         boolean failed = false;
 102         for (ContextVersion cv : ContextVersion.values()) {
 103             System.out.println("Checking SSLContext of " + cv.contextVersion);


   1 /*
   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.
   4  *
   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
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 // SunJSSE does not support dynamic system properties, no way to re-use
  25 // system properties in samevm/agentvm mode.
  26 
  27 /*
  28  * @test
  29  * @bug 7093640
  30  * @summary Enable TLS 1.1 and TLS 1.2 by default in client side of SunJSSE
  31  * @run main/othervm -Djdk.tls.client.protocols="TLSv1,TLSv1.1,TLSv1.2"
  32  *      NoOldVersionContext
  33  */
  34 



  35 import java.security.Security;
  36 import java.util.Arrays;
  37 import java.util.HashSet;
  38 import java.util.Set;
  39 
  40 import javax.net.SocketFactory;
  41 import javax.net.ssl.KeyManager;
  42 import javax.net.ssl.SSLContext;
  43 import javax.net.ssl.SSLEngine;
  44 import javax.net.ssl.SSLParameters;
  45 import javax.net.ssl.SSLServerSocket;
  46 import javax.net.ssl.SSLServerSocketFactory;
  47 import javax.net.ssl.SSLSocket;
  48 import javax.net.ssl.TrustManager;
  49 
  50 public class NoOldVersionContext {
  51     static enum ContextVersion {
  52         TLS_CV_01("SSL",
  53                 new String[] {"TLSv1", "TLSv1.1", "TLSv1.2"}),
  54         TLS_CV_02("TLS",
  55                 new String[] {"TLSv1", "TLSv1.1", "TLSv1.2"}),
  56         TLS_CV_03("SSLv3",
  57                 new String[] {"SSLv3", "TLSv1"}),
  58         TLS_CV_04("TLSv1",
  59                 new String[] {"SSLv3", "TLSv1"}),
  60         TLS_CV_05("TLSv1.1",
  61                 new String[] {"SSLv3", "TLSv1", "TLSv1.1"}),
  62         TLS_CV_06("TLSv1.2",
  63                 new String[] {"SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2"}),
  64         TLS_CV_07("TLSv1.3",
  65                 new String[] {"SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2", "TLSv1.3"}),
  66         TLS_CV_08("Default",
  67                 new String[] {"TLSv1", "TLSv1.1", "TLSv1.2"});
  68 
  69         final String contextVersion;
  70         final String[] enabledProtocols;
  71         final static String[] supportedProtocols = new String[] {
  72                 "SSLv2Hello", "SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2", "TLSv1.3"};
  73 
  74         ContextVersion(String contextVersion, String[] enabledProtocols) {
  75             this.contextVersion = contextVersion;
  76             this.enabledProtocols = enabledProtocols;
  77         }
  78     }
  79 
  80     private static boolean checkProtocols(String[] target, String[] expected) {
  81         boolean success = true;
  82         if (target.length == 0) {
  83             System.out.println("\tError: No protocols");
  84             success = false;
  85         }
  86 
  87         if (!protocolEquals(target, expected)) {
  88             System.out.println("\tError: Expected to get protocols " +
  89                     Arrays.toString(expected));
  90             System.out.println("\tError: The actual protocols " +
  91                     Arrays.toString(target));
  92             success = false;
  93         }
  94 
  95         return success;
  96     }
  97 
  98     private static boolean protocolEquals(
  99             String[] actualProtocols,
 100             String[] expectedProtocols) {
 101         if (actualProtocols.length != expectedProtocols.length) {
 102             return false;
 103         }
 104 
 105         Set<String> set = new HashSet<>(Arrays.asList(expectedProtocols));
 106         for (String actual : actualProtocols) {
 107             if (set.add(actual)) {
 108                 return false;
 109             }
 110         }
 111 
 112         return true;
 113     }
 114 
 115     private static boolean checkCipherSuites(String[] target) {
 116         boolean success = true;
 117         if (target.length == 0) {
 118             System.out.println("\tError: No cipher suites");
 119             success = false;
 120         }
 121 
 122         return success;
 123     }
 124 
 125     public static void main(String[] args) throws Exception {
 126         // reset the security property to make sure that the algorithms
 127         // and keys used in this test are not disabled.
 128         Security.setProperty("jdk.tls.disabledAlgorithms", "");
 129 
 130         boolean failed = false;
 131         for (ContextVersion cv : ContextVersion.values()) {
 132             System.out.println("Checking SSLContext of " + cv.contextVersion);


< prev index next >