< prev index next >

test/sun/security/ssl/SSLContextImpl/IllegalProtocolProperty.java

Print this page
rev 14340 : 8202343: Disable TLS 1.0 and 1.1
Reviewed-by: xuelei, dfuchs, coffeys
   1 /*
   2  * Copyright (c) 2013, 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="XSLv3,TLSv1"
  32  *      IllegalProtocolProperty
  33  */
  34 
  35 import javax.net.ssl.*;
  36 import java.security.NoSuchAlgorithmException;
  37 
  38 public class IllegalProtocolProperty {
  39     static enum ContextVersion {
  40         TLS_CV_01("SSL", "TLSv1", "TLSv1.2", true),
  41         TLS_CV_02("TLS", "TLSv1", "TLSv1.2", true),
  42         TLS_CV_03("SSLv3", "TLSv1", "TLSv1.2", false),
  43         TLS_CV_04("TLSv1", "TLSv1", "TLSv1.2", false),
  44         TLS_CV_05("TLSv1.1", "TLSv1.1", "TLSv1.2", false),
  45         TLS_CV_06("TLSv1.2", "TLSv1.2", "TLSv1.2", false),
  46         TLS_CV_07("Default", "TLSv1", "TLSv1.2", true);
  47 
  48         final String contextVersion;
  49         final String defaultProtocolVersion;
  50         final String supportedProtocolVersion;
  51         final boolean impacted;
  52 
  53         ContextVersion(String contextVersion, String defaultProtocolVersion,
  54                 String supportedProtocolVersion, boolean impacted) {
  55             this.contextVersion = contextVersion;
  56             this.defaultProtocolVersion = defaultProtocolVersion;
  57             this.supportedProtocolVersion = supportedProtocolVersion;
  58             this.impacted = impacted;
  59         }
  60     }
  61 
  62     public static void main(String[] args) throws Exception {



  63         for (ContextVersion cv : ContextVersion.values()) {
  64             System.out.println("Checking SSLContext of " + cv.contextVersion);
  65 
  66             SSLContext context;
  67             try {
  68                 context = SSLContext.getInstance(cv.contextVersion);
  69                 if (cv.impacted) {
  70                     throw new Exception(
  71                         "illegal system property jdk.tls.client.protocols: " +
  72                         System.getProperty("jdk.tls.client.protocols"));
  73                 }
  74             } catch (NoSuchAlgorithmException nsae) {
  75                 if (cv.impacted) {
  76                     System.out.println(
  77                         "\tIgnore: illegal system property " +
  78                         "jdk.tls.client.protocols=" +
  79                         System.getProperty("jdk.tls.client.protocols"));
  80                     continue;
  81                 } else {
  82                     throw nsae;


   1 /*
   2  * Copyright (c) 2013, 2020, 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  * @library /lib/security
  32  * @run main/othervm -Djdk.tls.client.protocols="XSLv3,TLSv1"
  33  *      IllegalProtocolProperty
  34  */
  35 
  36 import javax.net.ssl.*;
  37 import java.security.NoSuchAlgorithmException;
  38 
  39 public class IllegalProtocolProperty {
  40     static enum ContextVersion {
  41         TLS_CV_01("SSL", "TLSv1", "TLSv1.2", true),
  42         TLS_CV_02("TLS", "TLSv1", "TLSv1.2", true),
  43         TLS_CV_03("SSLv3", "TLSv1", "TLSv1.2", false),
  44         TLS_CV_04("TLSv1", "TLSv1", "TLSv1.2", false),
  45         TLS_CV_05("TLSv1.1", "TLSv1.1", "TLSv1.2", false),
  46         TLS_CV_06("TLSv1.2", "TLSv1.2", "TLSv1.2", false),
  47         TLS_CV_07("Default", "TLSv1", "TLSv1.2", true);
  48 
  49         final String contextVersion;
  50         final String defaultProtocolVersion;
  51         final String supportedProtocolVersion;
  52         final boolean impacted;
  53 
  54         ContextVersion(String contextVersion, String defaultProtocolVersion,
  55                 String supportedProtocolVersion, boolean impacted) {
  56             this.contextVersion = contextVersion;
  57             this.defaultProtocolVersion = defaultProtocolVersion;
  58             this.supportedProtocolVersion = supportedProtocolVersion;
  59             this.impacted = impacted;
  60         }
  61     }
  62 
  63     public static void main(String[] args) throws Exception {
  64         // Re-enable TLSv1 and TLSv1.1 since test depends on them.
  65         SecurityUtils.removeFromDisabledTlsAlgs("TLSv1", "TLSv1.1");
  66 
  67         for (ContextVersion cv : ContextVersion.values()) {
  68             System.out.println("Checking SSLContext of " + cv.contextVersion);
  69 
  70             SSLContext context;
  71             try {
  72                 context = SSLContext.getInstance(cv.contextVersion);
  73                 if (cv.impacted) {
  74                     throw new Exception(
  75                         "illegal system property jdk.tls.client.protocols: " +
  76                         System.getProperty("jdk.tls.client.protocols"));
  77                 }
  78             } catch (NoSuchAlgorithmException nsae) {
  79                 if (cv.impacted) {
  80                     System.out.println(
  81                         "\tIgnore: illegal system property " +
  82                         "jdk.tls.client.protocols=" +
  83                         System.getProperty("jdk.tls.client.protocols"));
  84                     continue;
  85                 } else {
  86                     throw nsae;


< prev index next >