12874
|
1 |
/*
|
|
2 |
* Copyright (c) 2012, 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 |
/*
|
|
25 |
* @test
|
|
26 |
* @bug 7174244
|
|
27 |
* @summary NPE in Krb5ProxyImpl.getServerKeys()
|
16067
|
28 |
*
|
|
29 |
* SunJSSE does not support dynamic system properties, no way to re-use
|
|
30 |
* system properties in samevm/agentvm mode.
|
12874
|
31 |
* @run main/othervm CipherSuitesInOrder
|
|
32 |
*/
|
|
33 |
|
|
34 |
import java.util.*;
|
|
35 |
import javax.net.ssl.*;
|
|
36 |
|
|
37 |
public class CipherSuitesInOrder {
|
|
38 |
|
|
39 |
// supported ciphersuites
|
|
40 |
private final static List<String> supportedCipherSuites =
|
|
41 |
Arrays.<String>asList(
|
|
42 |
"TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384",
|
|
43 |
"TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384",
|
|
44 |
"TLS_RSA_WITH_AES_256_CBC_SHA256",
|
|
45 |
"TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384",
|
|
46 |
"TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384",
|
|
47 |
"TLS_DHE_RSA_WITH_AES_256_CBC_SHA256",
|
|
48 |
"TLS_DHE_DSS_WITH_AES_256_CBC_SHA256",
|
|
49 |
"TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA",
|
|
50 |
"TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA",
|
|
51 |
"TLS_RSA_WITH_AES_256_CBC_SHA",
|
|
52 |
"TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA",
|
|
53 |
"TLS_ECDH_RSA_WITH_AES_256_CBC_SHA",
|
|
54 |
"TLS_DHE_RSA_WITH_AES_256_CBC_SHA",
|
|
55 |
"TLS_DHE_DSS_WITH_AES_256_CBC_SHA",
|
|
56 |
"TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256",
|
|
57 |
"TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256",
|
|
58 |
"TLS_RSA_WITH_AES_128_CBC_SHA256",
|
|
59 |
"TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256",
|
|
60 |
"TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256",
|
|
61 |
"TLS_DHE_RSA_WITH_AES_128_CBC_SHA256",
|
|
62 |
"TLS_DHE_DSS_WITH_AES_128_CBC_SHA256",
|
|
63 |
"TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA",
|
|
64 |
"TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA",
|
|
65 |
"TLS_RSA_WITH_AES_128_CBC_SHA",
|
|
66 |
"TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA",
|
|
67 |
"TLS_ECDH_RSA_WITH_AES_128_CBC_SHA",
|
|
68 |
"TLS_DHE_RSA_WITH_AES_128_CBC_SHA",
|
|
69 |
"TLS_DHE_DSS_WITH_AES_128_CBC_SHA",
|
|
70 |
"TLS_ECDHE_ECDSA_WITH_RC4_128_SHA",
|
|
71 |
"TLS_ECDHE_RSA_WITH_RC4_128_SHA",
|
|
72 |
"SSL_RSA_WITH_RC4_128_SHA",
|
|
73 |
"TLS_ECDH_ECDSA_WITH_RC4_128_SHA",
|
|
74 |
"TLS_ECDH_RSA_WITH_RC4_128_SHA",
|
|
75 |
"TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA",
|
|
76 |
"TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA",
|
|
77 |
"SSL_RSA_WITH_3DES_EDE_CBC_SHA",
|
|
78 |
"TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA",
|
|
79 |
"TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA",
|
|
80 |
"SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA",
|
|
81 |
"SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA",
|
|
82 |
"SSL_RSA_WITH_RC4_128_MD5",
|
|
83 |
|
|
84 |
"TLS_EMPTY_RENEGOTIATION_INFO_SCSV",
|
|
85 |
|
|
86 |
"TLS_DH_anon_WITH_AES_256_CBC_SHA256",
|
|
87 |
"TLS_ECDH_anon_WITH_AES_256_CBC_SHA",
|
|
88 |
"TLS_DH_anon_WITH_AES_256_CBC_SHA",
|
|
89 |
"TLS_DH_anon_WITH_AES_128_CBC_SHA256",
|
|
90 |
"TLS_ECDH_anon_WITH_AES_128_CBC_SHA",
|
|
91 |
"TLS_DH_anon_WITH_AES_128_CBC_SHA",
|
|
92 |
"TLS_ECDH_anon_WITH_RC4_128_SHA",
|
|
93 |
"SSL_DH_anon_WITH_RC4_128_MD5",
|
|
94 |
"TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA",
|
|
95 |
"SSL_DH_anon_WITH_3DES_EDE_CBC_SHA",
|
|
96 |
"TLS_RSA_WITH_NULL_SHA256",
|
|
97 |
"TLS_ECDHE_ECDSA_WITH_NULL_SHA",
|
|
98 |
"TLS_ECDHE_RSA_WITH_NULL_SHA",
|
|
99 |
"SSL_RSA_WITH_NULL_SHA",
|
|
100 |
"TLS_ECDH_ECDSA_WITH_NULL_SHA",
|
|
101 |
"TLS_ECDH_RSA_WITH_NULL_SHA",
|
|
102 |
"TLS_ECDH_anon_WITH_NULL_SHA",
|
|
103 |
"SSL_RSA_WITH_NULL_MD5",
|
|
104 |
"SSL_RSA_WITH_DES_CBC_SHA",
|
|
105 |
"SSL_DHE_RSA_WITH_DES_CBC_SHA",
|
|
106 |
"SSL_DHE_DSS_WITH_DES_CBC_SHA",
|
|
107 |
"SSL_DH_anon_WITH_DES_CBC_SHA",
|
|
108 |
"SSL_RSA_EXPORT_WITH_RC4_40_MD5",
|
|
109 |
"SSL_DH_anon_EXPORT_WITH_RC4_40_MD5",
|
|
110 |
"SSL_RSA_EXPORT_WITH_DES40_CBC_SHA",
|
|
111 |
"SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA",
|
|
112 |
"SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA",
|
|
113 |
"SSL_DH_anon_EXPORT_WITH_DES40_CBC_SHA",
|
|
114 |
"TLS_KRB5_WITH_RC4_128_SHA",
|
|
115 |
"TLS_KRB5_WITH_RC4_128_MD5",
|
|
116 |
"TLS_KRB5_WITH_3DES_EDE_CBC_SHA",
|
|
117 |
"TLS_KRB5_WITH_3DES_EDE_CBC_MD5",
|
|
118 |
"TLS_KRB5_WITH_DES_CBC_SHA",
|
|
119 |
"TLS_KRB5_WITH_DES_CBC_MD5",
|
|
120 |
"TLS_KRB5_EXPORT_WITH_RC4_40_SHA",
|
|
121 |
"TLS_KRB5_EXPORT_WITH_RC4_40_MD5",
|
|
122 |
"TLS_KRB5_EXPORT_WITH_DES_CBC_40_SHA",
|
|
123 |
"TLS_KRB5_EXPORT_WITH_DES_CBC_40_MD5"
|
|
124 |
);
|
|
125 |
|
|
126 |
private final static String[] protocols = {
|
|
127 |
"", "SSL", "TLS", "SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2"
|
|
128 |
};
|
|
129 |
|
|
130 |
|
|
131 |
public static void main(String[] args) throws Exception {
|
|
132 |
// show all of the supported cipher suites
|
|
133 |
showSuites(supportedCipherSuites.toArray(new String[0]),
|
|
134 |
"All supported cipher suites");
|
|
135 |
|
|
136 |
for (String protocol : protocols) {
|
|
137 |
System.out.println("//");
|
|
138 |
System.out.println("// " +
|
|
139 |
"Testing for SSLContext of " + protocol);
|
|
140 |
System.out.println("//");
|
|
141 |
checkForProtocols(protocol);
|
|
142 |
}
|
|
143 |
}
|
|
144 |
|
|
145 |
public static void checkForProtocols(String protocol) throws Exception {
|
|
146 |
SSLContext context;
|
|
147 |
if (protocol.isEmpty()) {
|
|
148 |
context = SSLContext.getDefault();
|
|
149 |
} else {
|
|
150 |
context = SSLContext.getInstance(protocol);
|
|
151 |
context.init(null, null, null);
|
|
152 |
}
|
|
153 |
|
|
154 |
// check the order of default cipher suites of SSLContext
|
|
155 |
SSLParameters parameters = context.getDefaultSSLParameters();
|
|
156 |
checkSuites(parameters.getCipherSuites(),
|
|
157 |
"Default cipher suites in SSLContext");
|
|
158 |
|
|
159 |
// check the order of supported cipher suites of SSLContext
|
|
160 |
parameters = context.getSupportedSSLParameters();
|
|
161 |
checkSuites(parameters.getCipherSuites(),
|
|
162 |
"Supported cipher suites in SSLContext");
|
|
163 |
|
|
164 |
|
|
165 |
//
|
|
166 |
// Check the cipher suites order of SSLEngine
|
|
167 |
//
|
|
168 |
SSLEngine engine = context.createSSLEngine();
|
|
169 |
|
|
170 |
// check the order of endabled cipher suites
|
|
171 |
String[] ciphers = engine.getEnabledCipherSuites();
|
|
172 |
checkSuites(ciphers,
|
|
173 |
"Enabled cipher suites in SSLEngine");
|
|
174 |
|
|
175 |
// check the order of supported cipher suites
|
|
176 |
ciphers = engine.getSupportedCipherSuites();
|
|
177 |
checkSuites(ciphers,
|
|
178 |
"Supported cipher suites in SSLEngine");
|
|
179 |
|
|
180 |
//
|
|
181 |
// Check the cipher suites order of SSLSocket
|
|
182 |
//
|
|
183 |
SSLSocketFactory factory = context.getSocketFactory();
|
|
184 |
try (SSLSocket socket = (SSLSocket)factory.createSocket()) {
|
|
185 |
|
|
186 |
// check the order of endabled cipher suites
|
|
187 |
ciphers = socket.getEnabledCipherSuites();
|
|
188 |
checkSuites(ciphers,
|
|
189 |
"Enabled cipher suites in SSLSocket");
|
|
190 |
|
|
191 |
// check the order of supported cipher suites
|
|
192 |
ciphers = socket.getSupportedCipherSuites();
|
|
193 |
checkSuites(ciphers,
|
|
194 |
"Supported cipher suites in SSLSocket");
|
|
195 |
}
|
|
196 |
|
|
197 |
//
|
|
198 |
// Check the cipher suites order of SSLServerSocket
|
|
199 |
//
|
|
200 |
SSLServerSocketFactory serverFactory = context.getServerSocketFactory();
|
|
201 |
try (SSLServerSocket serverSocket =
|
|
202 |
(SSLServerSocket)serverFactory.createServerSocket()) {
|
|
203 |
// check the order of endabled cipher suites
|
|
204 |
ciphers = serverSocket.getEnabledCipherSuites();
|
|
205 |
checkSuites(ciphers,
|
|
206 |
"Enabled cipher suites in SSLServerSocket");
|
|
207 |
|
|
208 |
// check the order of supported cipher suites
|
|
209 |
ciphers = serverSocket.getSupportedCipherSuites();
|
|
210 |
checkSuites(ciphers,
|
|
211 |
"Supported cipher suites in SSLServerSocket");
|
|
212 |
}
|
|
213 |
}
|
|
214 |
|
|
215 |
private static void checkSuites(String[] suites, String title) {
|
|
216 |
showSuites(suites, title);
|
|
217 |
|
|
218 |
int loc = -1;
|
|
219 |
int index = 0;
|
|
220 |
for (String suite : suites) {
|
|
221 |
index = supportedCipherSuites.indexOf(suite);
|
|
222 |
if (index <= loc) {
|
|
223 |
throw new RuntimeException(suite + " is not in order");
|
|
224 |
}
|
|
225 |
|
|
226 |
loc = index;
|
|
227 |
}
|
|
228 |
}
|
|
229 |
|
|
230 |
private static void showSuites(String[] suites, String title) {
|
|
231 |
System.out.println(title + "[" + suites.length + "]:");
|
|
232 |
for (String suite : suites) {
|
|
233 |
System.out.println(" " + suite);
|
|
234 |
}
|
|
235 |
}
|
|
236 |
}
|