1 /* |
1 /* |
2 * Copyright (c) 2013, 2014, 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. |
30 * @summary Enable TLS 1.1 and TLS 1.2 by default in client side of SunJSSE |
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="SSLv3,TLSv1,TLSv1.1" |
31 * @run main/othervm -Djdk.tls.client.protocols="SSLv3,TLSv1,TLSv1.1" |
32 * CustomizedDefaultProtocols |
32 * CustomizedDefaultProtocols |
33 */ |
33 */ |
34 |
34 |
35 import javax.net.*; |
35 import java.security.Security; |
36 import javax.net.ssl.*; |
|
37 import java.util.Arrays; |
36 import java.util.Arrays; |
38 import java.security.Security; |
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; |
39 |
49 |
40 public class CustomizedDefaultProtocols { |
50 public class CustomizedDefaultProtocols { |
41 static enum ContextVersion { |
51 static enum ContextVersion { |
42 TLS_CV_01("SSL", |
52 TLS_CV_01("SSL", |
43 new String[] {"SSLv3", "TLSv1", "TLSv1.1"}), |
53 new String[] {"SSLv3", "TLSv1", "TLSv1.1"}), |
49 new String[] {"SSLv3", "TLSv1"}), |
59 new String[] {"SSLv3", "TLSv1"}), |
50 TLS_CV_05("TLSv1.1", |
60 TLS_CV_05("TLSv1.1", |
51 new String[] {"SSLv3", "TLSv1", "TLSv1.1"}), |
61 new String[] {"SSLv3", "TLSv1", "TLSv1.1"}), |
52 TLS_CV_06("TLSv1.2", |
62 TLS_CV_06("TLSv1.2", |
53 new String[] {"SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2"}), |
63 new String[] {"SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2"}), |
54 TLS_CV_07("Default", |
64 TLS_CV_07("TLSv1.3", |
|
65 new String[] {"SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2", "TLSv1.3"}), |
|
66 TLS_CV_08("Default", |
55 new String[] {"SSLv3", "TLSv1", "TLSv1.1"}); |
67 new String[] {"SSLv3", "TLSv1", "TLSv1.1"}); |
56 |
68 |
57 final String contextVersion; |
69 final String contextVersion; |
58 final String[] enabledProtocols; |
70 final String[] enabledProtocols; |
59 final static String[] supportedProtocols = new String[] { |
71 final static String[] supportedProtocols = new String[] { |
60 "SSLv2Hello", "SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2"}; |
72 "SSLv2Hello", "SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2", "TLSv1.3"}; |
61 |
73 |
62 ContextVersion(String contextVersion, String[] enabledProtocols) { |
74 ContextVersion(String contextVersion, String[] enabledProtocols) { |
63 this.contextVersion = contextVersion; |
75 this.contextVersion = contextVersion; |
64 this.enabledProtocols = enabledProtocols; |
76 this.enabledProtocols = enabledProtocols; |
65 } |
77 } |
70 if (target.length == 0) { |
82 if (target.length == 0) { |
71 System.out.println("\tError: No protocols"); |
83 System.out.println("\tError: No protocols"); |
72 success = false; |
84 success = false; |
73 } |
85 } |
74 |
86 |
75 if (!Arrays.equals(target, expected)) { |
87 if (!protocolEquals(target, expected)) { |
76 System.out.println("\tError: Expected to get protocols " + |
88 System.out.println("\tError: Expected to get protocols " + |
77 Arrays.toString(expected)); |
89 Arrays.toString(expected)); |
78 System.out.println("\tError: The actual protocols " + |
90 System.out.println("\tError: The actual protocols " + |
79 Arrays.toString(target)); |
91 Arrays.toString(target)); |
80 success = false; |
92 success = false; |
81 } |
93 } |
82 |
94 |
83 return success; |
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; |
84 } |
113 } |
85 |
114 |
86 private static boolean checkCipherSuites(String[] target) { |
115 private static boolean checkCipherSuites(String[] target) { |
87 boolean success = true; |
116 boolean success = true; |
88 if (target.length == 0) { |
117 if (target.length == 0) { |