Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/net/ssl/interop/ClientHelloBufferUnderflowException.java
38854 views
/*1* Copyright (c) 2019, 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* @run main/othervm ClientHelloBufferUnderflowException33*/3435import sun.misc.HexDumpEncoder;36import javax.net.ssl.SSLHandshakeException;3738public class ClientHelloBufferUnderflowException extends ClientHelloInterOp {39/*40* Main entry point for this test.41*/42public static void main(String args[]) throws Exception {43try {44(new ClientHelloBufferUnderflowException()).run();45} catch (SSLHandshakeException e) {46System.out.println("Correct exception thrown: " + e);47return;48} catch (Exception e) {49System.out.println("Failed: Exception not SSLHandShakeException");50System.out.println(e.getMessage());51throw e;52}5354throw new Exception("No expected exception");55}5657@Override58protected byte[] createClientHelloMessage() {59// The ClientHello message in hex: 16 03 01 00 05 01 00 00 01 0360// Record Header:61// 16 - type is 0x16 (handshake record)62// 03 01 - protocol version is 3.1 (also known as TLS 1.0)63// 00 05 - 0x05 (5) bytes of handshake message follows64// Handshake Header:65// 01 - handshake message type 0x01 (client hello)66// 00 00 01 - 0x01 (1) bytes of client hello follows67// Client Version:68// 03 - incomplete client version69//70// (Based on https://tls.ulfheim.net)71byte[] bytes = {720x16, 0x03, 0x01, 0x00, 0x05, 0x01, 0x00, 0x00, 0x01, 0x03};7374System.out.println("The ClientHello message used");75try {76(new HexDumpEncoder()).encodeBuffer(bytes, System.out);77} catch (Exception e) {78// ignore79}8081return bytes;82}83}848586