Path: blob/master/test/jdk/sun/security/ssl/DHKeyExchange/UseStrongDHSizes.java
41152 views
/*1* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223//24// SunJSSE does not support dynamic system properties, no way to re-use25// system properties in samevm/agentvm mode.26//2728/*29* @test30* @bug 814043631* @modules jdk.crypto.ec32* @library /javax/net/ssl/templates33* @summary Negotiated Finite Field Diffie-Hellman Ephemeral Parameters for TLS34* @run main/othervm UseStrongDHSizes 204835* @run main/othervm -Djdk.tls.namedGroups=ffdhe2048 UseStrongDHSizes 204836* @run main/othervm -Djdk.tls.namedGroups=ffdhe3072 UseStrongDHSizes 204837* @run main/othervm -Djdk.tls.namedGroups=ffdhe4096 UseStrongDHSizes 204838* @run main/othervm -Djdk.tls.namedGroups=ffdhe6144 UseStrongDHSizes 204839* @run main/othervm -Djdk.tls.namedGroups=ffdhe8192 UseStrongDHSizes 204840* @run main/othervm UseStrongDHSizes 307241* @run main/othervm -Djdk.tls.namedGroups=ffdhe3072 UseStrongDHSizes 307242* @run main/othervm -Djdk.tls.namedGroups=ffdhe4096 UseStrongDHSizes 307243* @run main/othervm -Djdk.tls.namedGroups=ffdhe6144 UseStrongDHSizes 307244* @run main/othervm -Djdk.tls.namedGroups=ffdhe8192 UseStrongDHSizes 307245* @run main/othervm UseStrongDHSizes 409646* @run main/othervm -Djdk.tls.namedGroups=ffdhe4096 UseStrongDHSizes 409647* @run main/othervm -Djdk.tls.namedGroups=ffdhe6144 UseStrongDHSizes 409648* @run main/othervm -Djdk.tls.namedGroups=ffdhe8192 UseStrongDHSizes 409649* @run main/othervm UseStrongDHSizes 614450* @run main/othervm -Djdk.tls.namedGroups=ffdhe6144 UseStrongDHSizes 614451* @run main/othervm -Djdk.tls.namedGroups=ffdhe8192 UseStrongDHSizes 614452* @run main/othervm UseStrongDHSizes 819253* @run main/othervm -Djdk.tls.namedGroups=ffdhe8192 UseStrongDHSizes 819254*/5556import java.io.InputStream;57import java.io.OutputStream;58import java.security.Security;59import javax.net.ssl.SSLSocket;6061public class UseStrongDHSizes extends SSLSocketTemplate {62/*63* Run the test case.64*/65public static void main(String[] args) throws Exception {66// reset the security property to make sure that the algorithms67// and keys used in this test are not disabled unexpectedly.68String constraint = "DH keySize < " + Integer.valueOf(args[0]);69Security.setProperty("jdk.tls.disabledAlgorithms", constraint);70Security.setProperty("jdk.certpath.disabledAlgorithms", "");7172(new UseStrongDHSizes()).run();73}7475@Override76protected void runServerApplication(SSLSocket socket) throws Exception {77String ciphers[] = {78"TLS_DHE_RSA_WITH_AES_128_CBC_SHA",79"TLS_DHE_DSS_WITH_AES_128_CBC_SHA",80"SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA",81"SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA"};8283socket.setEnabledCipherSuites(ciphers);84socket.setWantClientAuth(true);8586InputStream sslIS = socket.getInputStream();87OutputStream sslOS = socket.getOutputStream();8889sslIS.read();90sslOS.write(85);91sslOS.flush();92}9394@Override95protected void runClientApplication(SSLSocket socket) throws Exception {96String ciphers[] = {97"TLS_DHE_RSA_WITH_AES_128_CBC_SHA",98"TLS_DHE_DSS_WITH_AES_128_CBC_SHA",99"SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA",100"SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA"};101socket.setEnabledCipherSuites(ciphers);102socket.setUseClientMode(true);103104InputStream sslIS = socket.getInputStream();105OutputStream sslOS = socket.getOutputStream();106107sslOS.write(280);108sslOS.flush();109sslIS.read();110}111}112113114