1 /* 2 * Copyright (c) 2016, 2019, 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 // SunJSSE does not support dynamic system properties, no way to re-use 25 // system properties in samevm/agentvm mode. 26 27 /* 28 * @test 29 * @bug 8161086 30 * @summary DTLS handshaking fails if some messages were lost 31 * @modules java.base/sun.security.util 32 * @library /test/lib 33 * @build DTLSOverDatagram 34 * 35 * @run main/othervm PacketLossRetransmission client 0 hello_request 36 * @run main/othervm PacketLossRetransmission client 1 client_hello 37 * @run main/othervm PacketLossRetransmission client 2 server_hello 38 * @run main/othervm PacketLossRetransmission client 3 hello_verify_request 39 * @run main/othervm PacketLossRetransmission client 4 new_session_ticket 40 * @run main/othervm PacketLossRetransmission client 11 certificate 41 * @run main/othervm PacketLossRetransmission client 12 server_key_exchange 42 * @run main/othervm PacketLossRetransmission client 13 certificate_request 43 * @run main/othervm PacketLossRetransmission client 14 server_hello_done 44 * @run main/othervm PacketLossRetransmission client 15 certificate_verify 45 * @run main/othervm PacketLossRetransmission client 16 client_key_exchange 46 * @run main/othervm PacketLossRetransmission client 20 finished 47 * @run main/othervm PacketLossRetransmission client 21 certificate_url 48 * @run main/othervm PacketLossRetransmission client 22 certificate_status 49 * @run main/othervm PacketLossRetransmission client 23 supplemental_data 50 * @run main/othervm PacketLossRetransmission client -1 change_cipher_spec 51 * @run main/othervm PacketLossRetransmission server 0 hello_request 52 * @run main/othervm PacketLossRetransmission server 1 client_hello 53 * @run main/othervm PacketLossRetransmission server 2 server_hello 54 * @run main/othervm PacketLossRetransmission server 3 hello_verify_request 55 * @run main/othervm PacketLossRetransmission server 4 new_session_ticket 56 * @run main/othervm PacketLossRetransmission server 11 certificate 57 * @run main/othervm PacketLossRetransmission server 12 server_key_exchange 58 * @run main/othervm PacketLossRetransmission server 13 certificate_request 59 * @run main/othervm PacketLossRetransmission server 14 server_hello_done 60 * @run main/othervm PacketLossRetransmission server 15 certificate_verify 61 * @run main/othervm PacketLossRetransmission server 16 client_key_exchange 62 * @run main/othervm PacketLossRetransmission server 20 finished 63 * @run main/othervm PacketLossRetransmission server 21 certificate_url 64 * @run main/othervm PacketLossRetransmission server 22 certificate_status 65 * @run main/othervm PacketLossRetransmission server 23 supplemental_data 66 * @run main/othervm PacketLossRetransmission server -1 change_cipher_spec 67 */ 68 69 import java.util.List; 70 import java.util.ArrayList; 71 import java.net.DatagramPacket; 72 import java.net.SocketAddress; 73 import javax.net.ssl.SSLEngine; 74 75 /** 76 * Test that DTLS implementation is able to do retransmission internally 77 * automatically if packet get lost. 78 */ 79 public class PacketLossRetransmission extends DTLSOverDatagram { 80 private static boolean isClient; 81 private static byte handshakeType; 82 83 private boolean needPacketLoss = true; 84 85 public static void main(String[] args) throws Exception { 86 isClient = args[0].equals("client"); 87 handshakeType = Byte.valueOf(args[1]); 88 89 PacketLossRetransmission testCase = new PacketLossRetransmission(); 90 testCase.runTest(testCase); 91 } 92 93 @Override 94 boolean produceHandshakePackets(SSLEngine engine, SocketAddress socketAddr, 95 String side, List<DatagramPacket> packets) throws Exception { 96 97 boolean finished = super.produceHandshakePackets( 98 engine, socketAddr, side, packets); 99 100 if (needPacketLoss && (!(isClient ^ engine.getUseClientMode()))) { 101 DatagramPacket packet = getPacket(packets, handshakeType); 102 if (packet != null) { 103 needPacketLoss = false; 104 105 System.out.println("Loss a packet of handshake messahe"); 106 packets.remove(packet); 107 } 108 } 109 110 return finished; 111 } 112 }