0N/A/*
2362N/A * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/*
0N/A * @test
0N/A * @bug 7174244
0N/A * @summary NPE in Krb5ProxyImpl.getServerKeys()
0N/A *
0N/A * SunJSSE does not support dynamic system properties, no way to re-use
0N/A * system properties in samevm/agentvm mode.
0N/A * @run main/othervm CipherSuitesInOrder
1790N/A */
1790N/A
1790N/Aimport java.util.*;
1790N/Aimport javax.net.ssl.*;
1790N/A
0N/Apublic class CipherSuitesInOrder {
0N/A
0N/A // supported ciphersuites
0N/A private final static List<String> supportedCipherSuites =
0N/A Arrays.<String>asList(
0N/A "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384",
0N/A "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384",
0N/A "TLS_RSA_WITH_AES_256_CBC_SHA256",
0N/A "TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384",
0N/A "TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384",
0N/A "TLS_DHE_RSA_WITH_AES_256_CBC_SHA256",
0N/A "TLS_DHE_DSS_WITH_AES_256_CBC_SHA256",
0N/A "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA",
0N/A "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA",
0N/A "TLS_RSA_WITH_AES_256_CBC_SHA",
0N/A "TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA",
0N/A "TLS_ECDH_RSA_WITH_AES_256_CBC_SHA",
0N/A "TLS_DHE_RSA_WITH_AES_256_CBC_SHA",
0N/A "TLS_DHE_DSS_WITH_AES_256_CBC_SHA",
0N/A "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256",
0N/A "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256",
0N/A "TLS_RSA_WITH_AES_128_CBC_SHA256",
0N/A "TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256",
0N/A "TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256",
0N/A "TLS_DHE_RSA_WITH_AES_128_CBC_SHA256",
0N/A "TLS_DHE_DSS_WITH_AES_128_CBC_SHA256",
0N/A "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA",
0N/A "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA",
0N/A "TLS_RSA_WITH_AES_128_CBC_SHA",
0N/A "TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA",
0N/A "TLS_ECDH_RSA_WITH_AES_128_CBC_SHA",
0N/A "TLS_DHE_RSA_WITH_AES_128_CBC_SHA",
0N/A "TLS_DHE_DSS_WITH_AES_128_CBC_SHA",
0N/A "TLS_ECDHE_ECDSA_WITH_RC4_128_SHA",
0N/A "TLS_ECDHE_RSA_WITH_RC4_128_SHA",
0N/A "SSL_RSA_WITH_RC4_128_SHA",
0N/A "TLS_ECDH_ECDSA_WITH_RC4_128_SHA",
0N/A "TLS_ECDH_RSA_WITH_RC4_128_SHA",
0N/A "TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA",
0N/A "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA",
0N/A "SSL_RSA_WITH_3DES_EDE_CBC_SHA",
0N/A "TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA",
0N/A "TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA",
0N/A "SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA",
0N/A "SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA",
0N/A "SSL_RSA_WITH_RC4_128_MD5",
0N/A
0N/A "TLS_EMPTY_RENEGOTIATION_INFO_SCSV",
0N/A
0N/A "TLS_DH_anon_WITH_AES_256_CBC_SHA256",
0N/A "TLS_ECDH_anon_WITH_AES_256_CBC_SHA",
0N/A "TLS_DH_anon_WITH_AES_256_CBC_SHA",
0N/A "TLS_DH_anon_WITH_AES_128_CBC_SHA256",
0N/A "TLS_ECDH_anon_WITH_AES_128_CBC_SHA",
0N/A "TLS_DH_anon_WITH_AES_128_CBC_SHA",
0N/A "TLS_ECDH_anon_WITH_RC4_128_SHA",
0N/A "SSL_DH_anon_WITH_RC4_128_MD5",
0N/A "TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA",
0N/A "SSL_DH_anon_WITH_3DES_EDE_CBC_SHA",
0N/A "TLS_RSA_WITH_NULL_SHA256",
0N/A "TLS_ECDHE_ECDSA_WITH_NULL_SHA",
0N/A "TLS_ECDHE_RSA_WITH_NULL_SHA",
0N/A "SSL_RSA_WITH_NULL_SHA",
0N/A "TLS_ECDH_ECDSA_WITH_NULL_SHA",
0N/A "TLS_ECDH_RSA_WITH_NULL_SHA",
0N/A "TLS_ECDH_anon_WITH_NULL_SHA",
0N/A "SSL_RSA_WITH_NULL_MD5",
0N/A "SSL_RSA_WITH_DES_CBC_SHA",
469N/A "SSL_DHE_RSA_WITH_DES_CBC_SHA",
469N/A "SSL_DHE_DSS_WITH_DES_CBC_SHA",
0N/A "SSL_DH_anon_WITH_DES_CBC_SHA",
0N/A "SSL_RSA_EXPORT_WITH_RC4_40_MD5",
0N/A "SSL_DH_anon_EXPORT_WITH_RC4_40_MD5",
0N/A "SSL_RSA_EXPORT_WITH_DES40_CBC_SHA",
0N/A "SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA",
0N/A "SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA",
0N/A "SSL_DH_anon_EXPORT_WITH_DES40_CBC_SHA",
0N/A "TLS_KRB5_WITH_RC4_128_SHA",
0N/A "TLS_KRB5_WITH_RC4_128_MD5",
0N/A "TLS_KRB5_WITH_3DES_EDE_CBC_SHA",
0N/A "TLS_KRB5_WITH_3DES_EDE_CBC_MD5",
0N/A "TLS_KRB5_WITH_DES_CBC_SHA",
0N/A "TLS_KRB5_WITH_DES_CBC_MD5",
0N/A "TLS_KRB5_EXPORT_WITH_RC4_40_SHA",
0N/A "TLS_KRB5_EXPORT_WITH_RC4_40_MD5",
0N/A "TLS_KRB5_EXPORT_WITH_DES_CBC_40_SHA",
0N/A "TLS_KRB5_EXPORT_WITH_DES_CBC_40_MD5"
0N/A );
0N/A
0N/A private final static String[] protocols = {
0N/A "", "SSL", "TLS", "SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2"
0N/A };
0N/A
0N/A
0N/A public static void main(String[] args) throws Exception {
0N/A // show all of the supported cipher suites
0N/A showSuites(supportedCipherSuites.toArray(new String[0]),
0N/A "All supported cipher suites");
0N/A
0N/A for (String protocol : protocols) {
0N/A System.out.println("//");
0N/A System.out.println("// " +
0N/A "Testing for SSLContext of " + protocol);
0N/A System.out.println("//");
0N/A checkForProtocols(protocol);
0N/A }
0N/A }
0N/A
0N/A public static void checkForProtocols(String protocol) throws Exception {
0N/A SSLContext context;
0N/A if (protocol.isEmpty()) {
0N/A context = SSLContext.getDefault();
0N/A } else {
0N/A context = SSLContext.getInstance(protocol);
0N/A context.init(null, null, null);
0N/A }
0N/A
0N/A // check the order of default cipher suites of SSLContext
0N/A SSLParameters parameters = context.getDefaultSSLParameters();
0N/A checkSuites(parameters.getCipherSuites(),
0N/A "Default cipher suites in SSLContext");
0N/A
0N/A // check the order of supported cipher suites of SSLContext
0N/A parameters = context.getSupportedSSLParameters();
0N/A checkSuites(parameters.getCipherSuites(),
0N/A "Supported cipher suites in SSLContext");
0N/A
0N/A
0N/A //
0N/A // Check the cipher suites order of SSLEngine
0N/A //
0N/A SSLEngine engine = context.createSSLEngine();
0N/A
0N/A // check the order of endabled cipher suites
0N/A String[] ciphers = engine.getEnabledCipherSuites();
0N/A checkSuites(ciphers,
0N/A "Enabled cipher suites in SSLEngine");
0N/A
0N/A // check the order of supported cipher suites
0N/A ciphers = engine.getSupportedCipherSuites();
0N/A checkSuites(ciphers,
0N/A "Supported cipher suites in SSLEngine");
0N/A
0N/A //
0N/A // Check the cipher suites order of SSLSocket
0N/A //
0N/A SSLSocketFactory factory = context.getSocketFactory();
0N/A try (SSLSocket socket = (SSLSocket)factory.createSocket()) {
0N/A
0N/A // check the order of endabled cipher suites
0N/A ciphers = socket.getEnabledCipherSuites();
0N/A checkSuites(ciphers,
0N/A "Enabled cipher suites in SSLSocket");
0N/A
0N/A // check the order of supported cipher suites
0N/A ciphers = socket.getSupportedCipherSuites();
0N/A checkSuites(ciphers,
0N/A "Supported cipher suites in SSLSocket");
0N/A }
0N/A
0N/A //
0N/A // Check the cipher suites order of SSLServerSocket
0N/A //
0N/A SSLServerSocketFactory serverFactory = context.getServerSocketFactory();
0N/A try (SSLServerSocket serverSocket =
0N/A (SSLServerSocket)serverFactory.createServerSocket()) {
0N/A // check the order of endabled cipher suites
0N/A ciphers = serverSocket.getEnabledCipherSuites();
0N/A checkSuites(ciphers,
0N/A "Enabled cipher suites in SSLServerSocket");
0N/A
0N/A // check the order of supported cipher suites
0N/A ciphers = serverSocket.getSupportedCipherSuites();
0N/A checkSuites(ciphers,
0N/A "Supported cipher suites in SSLServerSocket");
0N/A }
0N/A }
0N/A
0N/A private static void checkSuites(String[] suites, String title) {
0N/A showSuites(suites, title);
0N/A
0N/A int loc = -1;
0N/A int index = 0;
1790N/A for (String suite : suites) {
0N/A index = supportedCipherSuites.indexOf(suite);
0N/A if (index <= loc) {
0N/A throw new RuntimeException(suite + " is not in order");
0N/A }
0N/A
0N/A loc = index;
0N/A }
0N/A }
0N/A
0N/A private static void showSuites(String[] suites, String title) {
0N/A System.out.println(title + "[" + suites.length + "]:");
0N/A for (String suite : suites) {
0N/A System.out.println(" " + suite);
0N/A }
0N/A }
0N/A}
0N/A