Path: blob/master/test/jdk/sun/security/ssl/HandshakeHash/HandshakeHashCloneExhaustion.java
41152 views
/*1* Copyright (c) 2016, 2020, 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// Please run in othervm mode. SunJSSE does not support dynamic system25// properties, no way to re-use system properties in samevm/agentvm mode.26//2728/*29* @test30* @bug 8148421 8193683 823472831* @summary Transport Layer Security (TLS) Session Hash and Extended32* Master Secret Extension33* @summary Increase the number of clones in the CloneableDigest34* @library /javax/net/ssl/templates35* @library /test/lib36* @compile DigestBase.java37* @run main/othervm HandshakeHashCloneExhaustion38* TLSv1.3 TLS_AES_128_GCM_SHA25639* @run main/othervm HandshakeHashCloneExhaustion40* TLSv1.2 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA25641* @run main/othervm HandshakeHashCloneExhaustion42* TLSv1.1 TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA43*/4445import java.io.InputStream;46import java.io.OutputStream;47import java.security.MessageDigest;48import java.security.Security;49import javax.net.ssl.SSLSocket;5051import jdk.test.lib.security.SecurityUtils;5253public class HandshakeHashCloneExhaustion extends SSLSocketTemplate {5455private static String[] protocol;56private static String[] ciphersuite;57private static String[] mds = { "SHA", "MD5", "SHA-256" };5859/*60* ==================61* Run the test case.62*/63public static void main(String[] args) throws Exception {64// Add in a non-cloneable MD5/SHA1/SHA-256 implementation65Security.insertProviderAt(new MyProvider(), 1);66// make sure our provider is functioning67for (String s : mds) {68MessageDigest md = MessageDigest.getInstance(s);69String p = md.getProvider().getName();70if (!p.equals("MyProvider")) {71throw new RuntimeException("Unexpected provider: " + p);72}73}7475if (args.length != 2) {76throw new Exception(77"Usage: HandshakeHashCloneExhaustion protocol ciphersuite");78}7980System.out.println("Testing: " + args[0] + " " + args[1]);81protocol = new String [] { args[0] };82ciphersuite = new String[] { args[1] };8384// Re-enable TLSv1.1 when test depends on it.85if (protocol[0].equals("TLSv1.1")) {86SecurityUtils.removeFromDisabledTlsAlgs(protocol[0]);87}88(new HandshakeHashCloneExhaustion()).run();89}9091@Override92protected void runServerApplication(SSLSocket socket) throws Exception {93socket.setNeedClientAuth(true);94socket.setEnabledProtocols(protocol);95socket.setEnabledCipherSuites(ciphersuite);9697// here comes the test logic98InputStream sslIS = socket.getInputStream();99OutputStream sslOS = socket.getOutputStream();100101sslIS.read();102sslOS.write(85);103sslOS.flush();104}105106@Override107protected void runClientApplication(SSLSocket socket) throws Exception {108InputStream sslIS = socket.getInputStream();109OutputStream sslOS = socket.getOutputStream();110111sslOS.write(280);112sslOS.flush();113sslIS.read();114}115}116117118