1 /* 2 * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 // 25 // Please run in othervm mode. SunJSSE does not support dynamic system 26 // properties, no way to re-use system properties in samevm/agentvm mode. 27 // 28 29 /* 30 * @test 31 * @bug 8148421 8193683 32 * @summary Transport Layer Security (TLS) Session Hash and Extended 33 * Master Secret Extension 34 * @summary Increase the number of clones in the CloneableDigest 35 * @library /javax/net/ssl/templates 36 * @compile DigestBase.java 37 * @run main/othervm HandshakeHashCloneExhaustion 38 * TLSv1.2 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 39 * @run main/othervm HandshakeHashCloneExhaustion 40 * TLSv1.1 TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA 41 */ 42 43 import java.io.InputStream; 44 import java.io.OutputStream; 45 import java.security.Security; 46 import javax.net.ssl.SSLSocket; 47 48 public class HandshakeHashCloneExhaustion extends SSLSocketTemplate { 49 50 private static String[] protocol; 51 private static String[] ciphersuite; 52 53 /* 54 * ================== 55 * Run the test case. 56 */ 57 public static void main(String[] args) throws Exception { 58 // Add in a non-cloneable MD5/SHA1/SHA-256 implementation 59 Security.insertProviderAt(new MyProvider(), 1); 60 61 if (args.length != 2) { 62 throw new Exception( 63 "Usage: HandshakeHashCloneExhaustion protocol ciphersuite"); 64 } 65 66 System.out.println("Testing: " + args[0] + " " + args[1]); 67 protocol = new String [] { args[0] }; 68 ciphersuite = new String[] { args[1] }; 69 70 (new HandshakeHashCloneExhaustion()).run(); 71 } 72 73 @Override 74 protected void runServerApplication(SSLSocket socket) throws Exception { 75 socket.setNeedClientAuth(true); 76 socket.setEnabledProtocols(protocol); 77 socket.setEnabledCipherSuites(ciphersuite); 78 79 // here comes the test logic 80 InputStream sslIS = socket.getInputStream(); 81 OutputStream sslOS = socket.getOutputStream(); 82 83 sslIS.read(); 84 sslOS.write(85); 85 sslOS.flush(); 86 } 87 88 @Override 89 protected void runClientApplication(SSLSocket socket) throws Exception { 90 InputStream sslIS = socket.getInputStream(); 91 OutputStream sslOS = socket.getOutputStream(); 92 93 sslOS.write(280); 94 sslOS.flush(); 95 sslIS.read(); 96 } 97 }