1 /*
2 * Copyright (c) 2019, 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 import java.util.Arrays;
24 import javax.net.ssl.SSLServerSocket;
25 import javax.net.ssl.SSLSocket;
26
27 /*
28 * @test
29 * @bug 8234728
30 * @library /javax/net/ssl/templates
31 * /javax/net/ssl/TLSCommon
32 * @summary Test TLS ciphersuites order.
33 * Parameter order: <protocol> <client cipher order> <server cipher order>
34 * @run main/othervm TLSCipherSuitesOrder TLSv13 ORDERED default
35 * @run main/othervm TLSCipherSuitesOrder TLSv13 UNORDERED default
36 * @run main/othervm TLSCipherSuitesOrder TLSv13 UNORDERED UNORDERED
37 * @run main/othervm TLSCipherSuitesOrder TLSv13 ORDERED ORDERED
38 * @run main/othervm TLSCipherSuitesOrder TLSv12 ORDERED default
39 * @run main/othervm TLSCipherSuitesOrder TLSv12 UNORDERED default
40 * @run main/othervm TLSCipherSuitesOrder TLSv12 UNORDERED UNORDERED
41 * @run main/othervm TLSCipherSuitesOrder TLSv12 ORDERED ORDERED
42 * @run main/othervm TLSCipherSuitesOrder TLSv11 ORDERED default
43 * @run main/othervm TLSCipherSuitesOrder TLSv11 UNORDERED default
44 * @run main/othervm TLSCipherSuitesOrder TLSv11 UNORDERED UNORDERED
45 * @run main/othervm TLSCipherSuitesOrder TLSv11 ORDERED ORDERED
46 * @run main/othervm TLSCipherSuitesOrder TLSv1 ORDERED default
47 * @run main/othervm TLSCipherSuitesOrder TLSv1 UNORDERED default
48 * @run main/othervm TLSCipherSuitesOrder TLSv1 UNORDERED UNORDERED
49 * @run main/othervm TLSCipherSuitesOrder TLSv1 ORDERED ORDERED
50 */
51 public class TLSCipherSuitesOrder extends SSLSocketTemplate {
52
53 private final String protocol;
54 private final String[] servercipherSuites;
55 private final String[] clientcipherSuites;
56
57 public static void main(String[] args) {
58 PROTOCOL protocol = PROTOCOL.valueOf(args[0]);
59 try {
60 new TLSCipherSuitesOrder(protocol.getProtocol(),
61 protocol.getCipherSuite(args[1]),
62 protocol.getCipherSuite(args[2])).run();
63 } catch (Exception e) {
64 throw new RuntimeException(e);
65 }
66 }
67
68 private TLSCipherSuitesOrder(String protocol, String[] clientcipherSuites,
69 String[] servercipherSuites) {
70 this.protocol = protocol;
71 this.clientcipherSuites = clientcipherSuites;
72 this.servercipherSuites = servercipherSuites;
73 }
74
75 // Servers are configured before clients, increment test case after.
76 @Override
77 protected void configureClientSocket(SSLSocket socket) {
78 socket.setEnabledProtocols(new String[]{protocol});
79 if (clientcipherSuites != null) {
80 socket.setEnabledCipherSuites(clientcipherSuites);
81 }
82 }
83
84 @Override
85 protected void configureServerSocket(SSLServerSocket serverSocket) {
86 serverSocket.setEnabledProtocols(new String[]{protocol});
87 if (servercipherSuites != null) {
88 serverSocket.setEnabledCipherSuites(servercipherSuites);
89 }
|
1 /*
2 * Copyright (c) 2019, 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 import java.util.Arrays;
24 import javax.net.ssl.SSLServerSocket;
25 import javax.net.ssl.SSLSocket;
26
27 /*
28 * @test
29 * @bug 8234728
30 * @library /javax/net/ssl/templates
31 * /javax/net/ssl/TLSCommon
32 * /lib/security
33 * @summary Test TLS ciphersuites order.
34 * Parameter order: <protocol> <client cipher order> <server cipher order>
35 * @run main/othervm TLSCipherSuitesOrder TLSv13 ORDERED default
36 * @run main/othervm TLSCipherSuitesOrder TLSv13 UNORDERED default
37 * @run main/othervm TLSCipherSuitesOrder TLSv13 UNORDERED UNORDERED
38 * @run main/othervm TLSCipherSuitesOrder TLSv13 ORDERED ORDERED
39 * @run main/othervm TLSCipherSuitesOrder TLSv12 ORDERED default
40 * @run main/othervm TLSCipherSuitesOrder TLSv12 UNORDERED default
41 * @run main/othervm TLSCipherSuitesOrder TLSv12 UNORDERED UNORDERED
42 * @run main/othervm TLSCipherSuitesOrder TLSv12 ORDERED ORDERED
43 * @run main/othervm TLSCipherSuitesOrder TLSv11 ORDERED default
44 * @run main/othervm TLSCipherSuitesOrder TLSv11 UNORDERED default
45 * @run main/othervm TLSCipherSuitesOrder TLSv11 UNORDERED UNORDERED
46 * @run main/othervm TLSCipherSuitesOrder TLSv11 ORDERED ORDERED
47 * @run main/othervm TLSCipherSuitesOrder TLSv1 ORDERED default
48 * @run main/othervm TLSCipherSuitesOrder TLSv1 UNORDERED default
49 * @run main/othervm TLSCipherSuitesOrder TLSv1 UNORDERED UNORDERED
50 * @run main/othervm TLSCipherSuitesOrder TLSv1 ORDERED ORDERED
51 */
52 public class TLSCipherSuitesOrder extends SSLSocketTemplate {
53
54 private final String protocol;
55 private final String[] servercipherSuites;
56 private final String[] clientcipherSuites;
57
58 public static void main(String[] args) {
59 PROTOCOL protocol = PROTOCOL.valueOf(args[0]);
60 try {
61 new TLSCipherSuitesOrder(protocol.getProtocol(),
62 protocol.getCipherSuite(args[1]),
63 protocol.getCipherSuite(args[2])).run();
64 } catch (Exception e) {
65 throw new RuntimeException(e);
66 }
67 }
68
69 private TLSCipherSuitesOrder(String protocol, String[] clientcipherSuites,
70 String[] servercipherSuites) {
71 // Re-enable protocol if it is disabled.
72 if (protocol.equals("TLSv1") || protocol.equals("TLSv1.1")) {
73 SecurityUtils.removeFromDisabledTlsAlgs(protocol);
74 }
75 this.protocol = protocol;
76 this.clientcipherSuites = clientcipherSuites;
77 this.servercipherSuites = servercipherSuites;
78 }
79
80 // Servers are configured before clients, increment test case after.
81 @Override
82 protected void configureClientSocket(SSLSocket socket) {
83 socket.setEnabledProtocols(new String[]{protocol});
84 if (clientcipherSuites != null) {
85 socket.setEnabledCipherSuites(clientcipherSuites);
86 }
87 }
88
89 @Override
90 protected void configureServerSocket(SSLServerSocket serverSocket) {
91 serverSocket.setEnabledProtocols(new String[]{protocol});
92 if (servercipherSuites != null) {
93 serverSocket.setEnabledCipherSuites(servercipherSuites);
94 }
|