2
|
1 |
/*
|
|
2 |
* Copyright 2002-2003 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
21 |
* have any questions.
|
|
22 |
*/
|
|
23 |
|
|
24 |
/*
|
|
25 |
* @test
|
|
26 |
* @bug 4750141 4895631
|
|
27 |
* @summary Check enabled and supported ciphersuites are correct
|
|
28 |
*/
|
|
29 |
|
|
30 |
import java.util.*;
|
|
31 |
|
|
32 |
import javax.net.ssl.*;
|
|
33 |
|
|
34 |
import javax.crypto.Cipher;
|
|
35 |
import javax.crypto.spec.*;
|
|
36 |
|
|
37 |
public class CheckCipherSuites {
|
|
38 |
|
|
39 |
private final static String[] ENABLED_DEFAULT = {
|
|
40 |
"SSL_RSA_WITH_RC4_128_MD5",
|
|
41 |
"SSL_RSA_WITH_RC4_128_SHA",
|
|
42 |
"TLS_RSA_WITH_AES_128_CBC_SHA",
|
|
43 |
"TLS_DHE_RSA_WITH_AES_128_CBC_SHA",
|
|
44 |
"TLS_DHE_DSS_WITH_AES_128_CBC_SHA",
|
|
45 |
"SSL_RSA_WITH_3DES_EDE_CBC_SHA",
|
|
46 |
"SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA",
|
|
47 |
"SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA",
|
|
48 |
"SSL_RSA_WITH_DES_CBC_SHA",
|
|
49 |
"SSL_DHE_RSA_WITH_DES_CBC_SHA",
|
|
50 |
"SSL_DHE_DSS_WITH_DES_CBC_SHA",
|
|
51 |
"SSL_RSA_EXPORT_WITH_RC4_40_MD5",
|
|
52 |
"SSL_RSA_EXPORT_WITH_DES40_CBC_SHA",
|
|
53 |
"SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA",
|
|
54 |
"SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA",
|
|
55 |
};
|
|
56 |
|
|
57 |
private final static String[] ENABLED_UNLIMITED = {
|
|
58 |
"SSL_RSA_WITH_RC4_128_MD5",
|
|
59 |
"SSL_RSA_WITH_RC4_128_SHA",
|
|
60 |
"TLS_RSA_WITH_AES_128_CBC_SHA",
|
|
61 |
"TLS_RSA_WITH_AES_256_CBC_SHA",
|
|
62 |
"TLS_DHE_RSA_WITH_AES_128_CBC_SHA",
|
|
63 |
"TLS_DHE_RSA_WITH_AES_256_CBC_SHA",
|
|
64 |
"TLS_DHE_DSS_WITH_AES_128_CBC_SHA",
|
|
65 |
"TLS_DHE_DSS_WITH_AES_256_CBC_SHA",
|
|
66 |
"SSL_RSA_WITH_3DES_EDE_CBC_SHA",
|
|
67 |
"SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA",
|
|
68 |
"SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA",
|
|
69 |
"SSL_RSA_WITH_DES_CBC_SHA",
|
|
70 |
"SSL_DHE_RSA_WITH_DES_CBC_SHA",
|
|
71 |
"SSL_DHE_DSS_WITH_DES_CBC_SHA",
|
|
72 |
"SSL_RSA_EXPORT_WITH_RC4_40_MD5",
|
|
73 |
"SSL_RSA_EXPORT_WITH_DES40_CBC_SHA",
|
|
74 |
"SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA",
|
|
75 |
"SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA",
|
|
76 |
};
|
|
77 |
|
|
78 |
// supported ciphersuites using default JCE policy jurisdiction files
|
|
79 |
// AES/256 unavailable
|
|
80 |
private final static String[] SUPPORTED_DEFAULT = {
|
|
81 |
"SSL_RSA_WITH_RC4_128_MD5",
|
|
82 |
"SSL_RSA_WITH_RC4_128_SHA",
|
|
83 |
"TLS_RSA_WITH_AES_128_CBC_SHA",
|
|
84 |
"TLS_DHE_RSA_WITH_AES_128_CBC_SHA",
|
|
85 |
"TLS_DHE_DSS_WITH_AES_128_CBC_SHA",
|
|
86 |
"SSL_RSA_WITH_3DES_EDE_CBC_SHA",
|
|
87 |
"SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA",
|
|
88 |
"SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA",
|
|
89 |
"SSL_RSA_WITH_DES_CBC_SHA",
|
|
90 |
"SSL_DHE_RSA_WITH_DES_CBC_SHA",
|
|
91 |
"SSL_DHE_DSS_WITH_DES_CBC_SHA",
|
|
92 |
"SSL_RSA_EXPORT_WITH_RC4_40_MD5",
|
|
93 |
"SSL_RSA_EXPORT_WITH_DES40_CBC_SHA",
|
|
94 |
"SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA",
|
|
95 |
"SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA",
|
|
96 |
"SSL_RSA_WITH_NULL_MD5",
|
|
97 |
"SSL_RSA_WITH_NULL_SHA",
|
|
98 |
"SSL_DH_anon_WITH_RC4_128_MD5",
|
|
99 |
"TLS_DH_anon_WITH_AES_128_CBC_SHA",
|
|
100 |
"SSL_DH_anon_WITH_3DES_EDE_CBC_SHA",
|
|
101 |
"SSL_DH_anon_WITH_DES_CBC_SHA",
|
|
102 |
"SSL_DH_anon_EXPORT_WITH_RC4_40_MD5",
|
|
103 |
"SSL_DH_anon_EXPORT_WITH_DES40_CBC_SHA",
|
|
104 |
"TLS_KRB5_WITH_RC4_128_SHA",
|
|
105 |
"TLS_KRB5_WITH_RC4_128_MD5",
|
|
106 |
"TLS_KRB5_WITH_3DES_EDE_CBC_SHA",
|
|
107 |
"TLS_KRB5_WITH_3DES_EDE_CBC_MD5",
|
|
108 |
"TLS_KRB5_WITH_DES_CBC_SHA",
|
|
109 |
"TLS_KRB5_WITH_DES_CBC_MD5",
|
|
110 |
"TLS_KRB5_EXPORT_WITH_RC4_40_SHA",
|
|
111 |
"TLS_KRB5_EXPORT_WITH_RC4_40_MD5",
|
|
112 |
"TLS_KRB5_EXPORT_WITH_DES_CBC_40_SHA",
|
|
113 |
"TLS_KRB5_EXPORT_WITH_DES_CBC_40_MD5"
|
|
114 |
};
|
|
115 |
|
|
116 |
// supported ciphersuites using unlimited JCE policy jurisdiction files
|
|
117 |
// AES/256 available
|
|
118 |
private final static String[] SUPPORTED_UNLIMITED = {
|
|
119 |
"SSL_RSA_WITH_RC4_128_MD5",
|
|
120 |
"SSL_RSA_WITH_RC4_128_SHA",
|
|
121 |
"TLS_RSA_WITH_AES_128_CBC_SHA",
|
|
122 |
"TLS_RSA_WITH_AES_256_CBC_SHA",
|
|
123 |
"TLS_DHE_RSA_WITH_AES_128_CBC_SHA",
|
|
124 |
"TLS_DHE_RSA_WITH_AES_256_CBC_SHA",
|
|
125 |
"TLS_DHE_DSS_WITH_AES_128_CBC_SHA",
|
|
126 |
"TLS_DHE_DSS_WITH_AES_256_CBC_SHA",
|
|
127 |
"SSL_RSA_WITH_3DES_EDE_CBC_SHA",
|
|
128 |
"SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA",
|
|
129 |
"SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA",
|
|
130 |
"SSL_RSA_WITH_DES_CBC_SHA",
|
|
131 |
"SSL_DHE_RSA_WITH_DES_CBC_SHA",
|
|
132 |
"SSL_DHE_DSS_WITH_DES_CBC_SHA",
|
|
133 |
"SSL_RSA_EXPORT_WITH_RC4_40_MD5",
|
|
134 |
"SSL_RSA_EXPORT_WITH_DES40_CBC_SHA",
|
|
135 |
"SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA",
|
|
136 |
"SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA",
|
|
137 |
"SSL_RSA_WITH_NULL_MD5",
|
|
138 |
"SSL_RSA_WITH_NULL_SHA",
|
|
139 |
"SSL_DH_anon_WITH_RC4_128_MD5",
|
|
140 |
"TLS_DH_anon_WITH_AES_128_CBC_SHA",
|
|
141 |
"TLS_DH_anon_WITH_AES_256_CBC_SHA",
|
|
142 |
"SSL_DH_anon_WITH_3DES_EDE_CBC_SHA",
|
|
143 |
"SSL_DH_anon_WITH_DES_CBC_SHA",
|
|
144 |
"SSL_DH_anon_EXPORT_WITH_RC4_40_MD5",
|
|
145 |
"SSL_DH_anon_EXPORT_WITH_DES40_CBC_SHA",
|
|
146 |
"TLS_KRB5_WITH_RC4_128_SHA",
|
|
147 |
"TLS_KRB5_WITH_RC4_128_MD5",
|
|
148 |
"TLS_KRB5_WITH_3DES_EDE_CBC_SHA",
|
|
149 |
"TLS_KRB5_WITH_3DES_EDE_CBC_MD5",
|
|
150 |
"TLS_KRB5_WITH_DES_CBC_SHA",
|
|
151 |
"TLS_KRB5_WITH_DES_CBC_MD5",
|
|
152 |
"TLS_KRB5_EXPORT_WITH_RC4_40_SHA",
|
|
153 |
"TLS_KRB5_EXPORT_WITH_RC4_40_MD5",
|
|
154 |
"TLS_KRB5_EXPORT_WITH_DES_CBC_40_SHA",
|
|
155 |
"TLS_KRB5_EXPORT_WITH_DES_CBC_40_MD5"
|
|
156 |
};
|
|
157 |
|
|
158 |
private static void showSuites(String[] suites) {
|
|
159 |
if ((suites == null) || (suites.length == 0)) {
|
|
160 |
System.out.println("<none>");
|
|
161 |
}
|
|
162 |
for (int i = 0; i < suites.length; i++) {
|
|
163 |
System.out.println(" " + suites[i]);
|
|
164 |
}
|
|
165 |
}
|
|
166 |
|
|
167 |
public static void main(String[] args) throws Exception {
|
|
168 |
long start = System.currentTimeMillis();
|
|
169 |
|
|
170 |
String[] ENABLED;
|
|
171 |
String[] SUPPORTED;
|
|
172 |
try {
|
|
173 |
Cipher c = Cipher.getInstance("AES/CBC/NoPadding");
|
|
174 |
SecretKeySpec key = new SecretKeySpec(new byte[32], "AES");
|
|
175 |
c.init(Cipher.ENCRYPT_MODE, key);
|
|
176 |
System.out.println("AES/256 is available");
|
|
177 |
ENABLED = ENABLED_UNLIMITED;
|
|
178 |
SUPPORTED = SUPPORTED_UNLIMITED;
|
|
179 |
} catch (Exception e) {
|
|
180 |
System.out.println("AES/256 is NOT available (" + e + ")");
|
|
181 |
ENABLED = ENABLED_DEFAULT;
|
|
182 |
SUPPORTED = SUPPORTED_DEFAULT;
|
|
183 |
}
|
|
184 |
|
|
185 |
SSLSocketFactory factory = (SSLSocketFactory)SSLSocketFactory.getDefault();
|
|
186 |
SSLSocket socket = (SSLSocket)factory.createSocket();
|
|
187 |
String[] enabled = socket.getEnabledCipherSuites();
|
|
188 |
|
|
189 |
System.out.println("Default enabled ciphersuites:");
|
|
190 |
showSuites(enabled);
|
|
191 |
|
|
192 |
if (Arrays.equals(ENABLED, enabled) == false) {
|
|
193 |
System.out.println("*** MISMATCH, should be ***");
|
|
194 |
showSuites(ENABLED);
|
|
195 |
throw new Exception("Enabled ciphersuite mismatch");
|
|
196 |
}
|
|
197 |
System.out.println("OK");
|
|
198 |
System.out.println();
|
|
199 |
|
|
200 |
String[] supported = socket.getSupportedCipherSuites();
|
|
201 |
System.out.println("Supported ciphersuites:");
|
|
202 |
showSuites(supported);
|
|
203 |
|
|
204 |
if (Arrays.equals(SUPPORTED, supported) == false) {
|
|
205 |
System.out.println("*** MISMATCH, should be ***");
|
|
206 |
showSuites(SUPPORTED);
|
|
207 |
throw new Exception("Supported ciphersuite mismatch");
|
|
208 |
}
|
|
209 |
System.out.println("OK");
|
|
210 |
|
|
211 |
long end = System.currentTimeMillis();
|
|
212 |
System.out.println("Done (" + (end - start) + " ms).");
|
|
213 |
}
|
|
214 |
|
|
215 |
}
|