test/jdk/javax/net/ssl/DTLS/InvalidRecords.java
branchJDK-8145252-TLS13-branch
changeset 56769 125890684a60
parent 47216 71c04702a3d5
child 58013 d80e4bce4588
equal deleted inserted replaced
56761:001e4e7c0a01 56769:125890684a60
    53         return false;
    53         return false;
    54     }
    54     }
    55 
    55 
    56     @Override
    56     @Override
    57     DatagramPacket createHandshakePacket(byte[] ba, SocketAddress socketAddr) {
    57     DatagramPacket createHandshakePacket(byte[] ba, SocketAddress socketAddr) {
    58         if (needInvalidRecords && (ba.length >= 60) &&
    58         if ((ba.length >= 60) &&
    59                 (ba[0x00] == (byte)0x16) && (ba[0x0D] == (byte)0x01) &&
    59                 (ba[0x00] == (byte)0x16) && (ba[0x0D] == (byte)0x01) &&
    60                 (ba[0x3B] == (byte)0x00) && (ba[0x3C] > 0)) {
    60                 (ba[0x3B] == (byte)0x00) && (ba[0x3C] > 0)) {
    61 
    61 
    62             // ba[0x00]: record type
    62             // ba[0x00]: record type
    63             // ba[0x0D]: handshake type
    63             // ba[0x0D]: handshake type
    64             // ba[0x3B]: length of session ID
    64             // ba[0x3B]: length of session ID
    65             // ba[0x3C]: length of cookie
    65             // ba[0x3C]: length of cookie
       
    66 
       
    67             if (!needInvalidRecords) {
       
    68                 // The 2nd ClientHello with cookie.  The 1st one should be
       
    69                 // rejected as expected.
       
    70                 //
       
    71                 // This may happen if the last few bytes of the packet are
       
    72                 // for supported_version extension.
       
    73                 throw new RuntimeException(
       
    74                     "the crashed handshake message was rejected as expected");
       
    75             }
    66 
    76 
    67             // ClientHello with cookie
    77             // ClientHello with cookie
    68             needInvalidRecords = false;
    78             needInvalidRecords = false;
    69             System.out.println("invalidate ClientHello message");
    79             System.out.println("invalidate ClientHello message");
    70             if (ba[ba.length - 1] == (byte)0xFF) {
    80             if (ba[ba.length - 1] == (byte)0xFF) {