Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/ssl/HandshakeHash/HandshakeHashCloneExhaustion.java
38853 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 /lib/security36* @compile DigestBase.java37* @run main/othervm -Djdk.tls.client.protocols="TLSv1.3,TLSv1.2,TLSv1.1,TLSv1,SSLv3"38* HandshakeHashCloneExhaustion 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;5051public class HandshakeHashCloneExhaustion extends SSLSocketTemplate {5253private static String[] protocol;54private static String[] ciphersuite;55private static String[] mds = { "SHA", "MD5", "SHA-256" };5657/*58* ==================59* Run the test case.60*/61public static void main(String[] args) throws Exception {62// Add in a non-cloneable MD5/SHA1/SHA-256 implementation63Security.insertProviderAt(new MyProvider(), 1);64// make sure our provider is functioning65for (String s : mds) {66MessageDigest md = MessageDigest.getInstance(s);67String p = md.getProvider().getName();68if (!p.equals("MyProvider")) {69throw new RuntimeException("Unexpected provider: " + p);70}71}7273if (args.length != 2) {74throw new Exception(75"Usage: HandshakeHashCloneExhaustion protocol ciphersuite");76}7778System.out.println("Testing: " + args[0] + " " + args[1]);79protocol = new String [] { args[0] };80ciphersuite = new String[] { args[1] };8182// Re-enable TLSv1.1 when test depends on it.83if (protocol[0].equals("TLSv1.1")) {84SecurityUtils.removeFromDisabledTlsAlgs(protocol[0]);85}86(new HandshakeHashCloneExhaustion()).run();87}8889@Override90protected void runServerApplication(SSLSocket socket) throws Exception {91socket.setNeedClientAuth(true);92socket.setEnabledProtocols(protocol);93socket.setEnabledCipherSuites(ciphersuite);9495// here comes the test logic96InputStream sslIS = socket.getInputStream();97OutputStream sslOS = socket.getOutputStream();9899sslIS.read();100sslOS.write(85);101sslOS.flush();102}103104@Override105protected void runClientApplication(SSLSocket socket) throws Exception {106InputStream sslIS = socket.getInputStream();107OutputStream sslOS = socket.getOutputStream();108109sslOS.write(280);110sslOS.flush();111sslIS.read();112}113}114115116