Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/ssl/DHKeyExchange/UseStrongDHSizes.java
38853 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* @library /javax/net/ssl/templates32* @summary Negotiated Finite Field Diffie-Hellman Ephemeral Parameters for TLS33* @run main/othervm UseStrongDHSizes 204834* @run main/othervm -Djdk.tls.namedGroups=ffdhe2048 UseStrongDHSizes 204835* @run main/othervm -Djdk.tls.namedGroups=ffdhe3072 UseStrongDHSizes 204836* @run main/othervm -Djdk.tls.namedGroups=ffdhe4096 UseStrongDHSizes 204837* @run main/othervm -Djdk.tls.namedGroups=ffdhe6144 UseStrongDHSizes 204838* @run main/othervm -Djdk.tls.namedGroups=ffdhe8192 UseStrongDHSizes 204839* @run main/othervm UseStrongDHSizes 307240* @run main/othervm -Djdk.tls.namedGroups=ffdhe3072 UseStrongDHSizes 307241* @run main/othervm -Djdk.tls.namedGroups=ffdhe4096 UseStrongDHSizes 307242* @run main/othervm -Djdk.tls.namedGroups=ffdhe6144 UseStrongDHSizes 307243* @run main/othervm -Djdk.tls.namedGroups=ffdhe8192 UseStrongDHSizes 307244* @run main/othervm UseStrongDHSizes 409645* @run main/othervm -Djdk.tls.namedGroups=ffdhe4096 UseStrongDHSizes 409646* @run main/othervm -Djdk.tls.namedGroups=ffdhe6144 UseStrongDHSizes 409647* @run main/othervm -Djdk.tls.namedGroups=ffdhe8192 UseStrongDHSizes 409648* @run main/othervm UseStrongDHSizes 614449* @run main/othervm -Djdk.tls.namedGroups=ffdhe6144 UseStrongDHSizes 614450* @run main/othervm -Djdk.tls.namedGroups=ffdhe8192 UseStrongDHSizes 614451* @run main/othervm UseStrongDHSizes 819252* @run main/othervm -Djdk.tls.namedGroups=ffdhe8192 UseStrongDHSizes 819253*/5455import java.io.InputStream;56import java.io.OutputStream;57import java.security.Security;58import javax.net.ssl.SSLSocket;5960public class UseStrongDHSizes extends SSLSocketTemplate {61/*62* Run the test case.63*/64public static void main(String[] args) throws Exception {65// reset the security property to make sure that the algorithms66// and keys used in this test are not disabled unexpectedly.67String constraint = "DH keySize < " + Integer.valueOf(args[0]);68Security.setProperty("jdk.tls.disabledAlgorithms", constraint);69Security.setProperty("jdk.certpath.disabledAlgorithms", "");7071(new UseStrongDHSizes()).run();72}7374@Override75protected void runServerApplication(SSLSocket socket) throws Exception {76String ciphers[] = {77"TLS_DHE_RSA_WITH_AES_128_CBC_SHA",78"TLS_DHE_DSS_WITH_AES_128_CBC_SHA",79"SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA",80"SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA"};8182socket.setEnabledCipherSuites(ciphers);83socket.setWantClientAuth(true);8485InputStream sslIS = socket.getInputStream();86OutputStream sslOS = socket.getOutputStream();8788sslIS.read();89sslOS.write(85);90sslOS.flush();91}9293@Override94protected void runClientApplication(SSLSocket socket) throws Exception {95String ciphers[] = {96"TLS_DHE_RSA_WITH_AES_128_CBC_SHA",97"TLS_DHE_DSS_WITH_AES_128_CBC_SHA",98"SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA",99"SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA"};100socket.setEnabledCipherSuites(ciphers);101socket.setUseClientMode(true);102103InputStream sslIS = socket.getInputStream();104OutputStream sslOS = socket.getOutputStream();105106sslOS.write(280);107sslOS.flush();108sslIS.read();109}110}111112113