29 * @bug 7093640 |
29 * @bug 7093640 |
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 DefaultEnabledProtocols |
31 * @run main/othervm DefaultEnabledProtocols |
32 */ |
32 */ |
33 |
33 |
34 import javax.net.*; |
34 import java.security.Security; |
35 import javax.net.ssl.*; |
|
36 import java.util.Arrays; |
35 import java.util.Arrays; |
37 import java.security.Security; |
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; |
38 |
48 |
39 public class DefaultEnabledProtocols { |
49 public class DefaultEnabledProtocols { |
40 static enum ContextVersion { |
50 static enum ContextVersion { |
41 TLS_CV_01("SSL", |
51 TLS_CV_01("SSL", |
42 new String[] {"SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2"}), |
52 new String[] {"SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2", "TLSv1.3"}), |
43 TLS_CV_02("TLS", |
53 TLS_CV_02("TLS", |
44 new String[] {"SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2"}), |
54 new String[] {"SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2", "TLSv1.3"}), |
45 TLS_CV_03("SSLv3", |
55 TLS_CV_03("SSLv3", |
46 new String[] {"SSLv3", "TLSv1"}), |
56 new String[] {"SSLv3", "TLSv1"}), |
47 TLS_CV_04("TLSv1", |
57 TLS_CV_04("TLSv1", |
48 new String[] {"SSLv3", "TLSv1"}), |
58 new String[] {"SSLv3", "TLSv1"}), |
49 TLS_CV_05("TLSv1.1", |
59 TLS_CV_05("TLSv1.1", |
50 new String[] {"SSLv3", "TLSv1", "TLSv1.1"}), |
60 new String[] {"SSLv3", "TLSv1", "TLSv1.1"}), |
51 TLS_CV_06("TLSv1.2", |
61 TLS_CV_06("TLSv1.2", |
52 new String[] {"SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2"}), |
62 new String[] {"SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2"}), |
53 TLS_CV_07("Default", |
63 TLS_CV_07("TLSv1.3", |
54 new String[] {"SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2"}); |
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"}); |
55 |
67 |
56 final String contextVersion; |
68 final String contextVersion; |
57 final String[] enabledProtocols; |
69 final String[] enabledProtocols; |
58 final static String[] supportedProtocols = new String[] { |
70 final static String[] supportedProtocols = new String[] { |
59 "SSLv2Hello", "SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2"}; |
71 "SSLv2Hello", "SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2", "TLSv1.3"}; |
60 |
72 |
61 ContextVersion(String contextVersion, String[] enabledProtocols) { |
73 ContextVersion(String contextVersion, String[] enabledProtocols) { |
62 this.contextVersion = contextVersion; |
74 this.contextVersion = contextVersion; |
63 this.enabledProtocols = enabledProtocols; |
75 this.enabledProtocols = enabledProtocols; |
64 } |
76 } |
69 if (target.length == 0) { |
81 if (target.length == 0) { |
70 System.out.println("\tError: No protocols"); |
82 System.out.println("\tError: No protocols"); |
71 success = false; |
83 success = false; |
72 } |
84 } |
73 |
85 |
74 if (!Arrays.equals(target, expected)) { |
86 if (!protocolEquals(target, expected)) { |
75 System.out.println("\tError: Expected to get protocols " + |
87 System.out.println("\tError: Expected to get protocols " + |
76 Arrays.toString(expected)); |
88 Arrays.toString(expected)); |
77 System.out.println("\tError: The actual protocols " + |
89 System.out.println("\tError: The actual protocols " + |
78 Arrays.toString(target)); |
90 Arrays.toString(target)); |
79 success = false; |
91 success = false; |
80 } |
92 } |
81 |
93 |
82 return success; |
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; |
83 } |
112 } |
84 |
113 |
85 private static boolean checkCipherSuites(String[] target) { |
114 private static boolean checkCipherSuites(String[] target) { |
86 boolean success = true; |
115 boolean success = true; |
87 if (target.length == 0) { |
116 if (target.length == 0) { |