Path: blob/master/test/jdk/javax/net/ssl/interop/ClientHelloBufferUnderflowException.java
41152 views
/*1* Copyright (c) 2019, 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// SunJSSE does not support dynamic system properties, no way to re-use25// system properties in samevm/agentvm mode.26//2728/*29* @test30* @bug 8215790 821938931* @summary Verify exception32* @library /test/lib33* @modules java.base/sun.security.util34* @run main/othervm ClientHelloBufferUnderflowException35*/3637import javax.net.ssl.SSLHandshakeException;3839import jdk.test.lib.hexdump.HexPrinter;4041public class ClientHelloBufferUnderflowException extends ClientHelloInterOp {42/*43* Main entry point for this test.44*/45public static void main(String args[]) throws Exception {46try {47(new ClientHelloBufferUnderflowException()).run();48} catch (SSLHandshakeException e) {49System.out.println("Correct exception thrown: " + e);50return;51} catch (Exception e) {52System.out.println("Failed: Exception not SSLHandShakeException");53System.out.println(e.getMessage());54throw e;55}5657throw new Exception("No expected exception");58}5960@Override61protected byte[] createClientHelloMessage() {62// The ClientHello message in hex: 16 03 01 00 05 01 00 00 01 0363// Record Header:64// 16 - type is 0x16 (handshake record)65// 03 01 - protocol version is 3.1 (also known as TLS 1.0)66// 00 05 - 0x05 (5) bytes of handshake message follows67// Handshake Header:68// 01 - handshake message type 0x01 (client hello)69// 00 00 01 - 0x01 (1) bytes of client hello follows70// Client Version:71// 03 - incomplete client version72//73// (Based on https://tls.ulfheim.net)74byte[] bytes = {750x16, 0x03, 0x01, 0x00, 0x05, 0x01, 0x00, 0x00, 0x01, 0x03};7677System.out.println("The ClientHello message used");78try {79HexPrinter.simple().format(bytes);80} catch (Exception e) {81// ignore82}8384return bytes;85}86}878889