< prev index next >

test/jdk/sun/security/ssl/SSLContextImpl/DefaultEnabledProtocols.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 DefaultEnabledProtocols
  32  */
  33 
  34 import javax.net.*;
  35 import javax.net.ssl.*;
  36 import java.util.Arrays;
  37 import java.security.Security;













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


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

















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



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


< prev index next >