Path: blob/master/test/jdk/javax/net/ssl/DTLS/PacketLossRetransmission.java
41152 views
/*1* Copyright (c) 2016, 2021, 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// SunJSSE does not support dynamic system properties, no way to re-use24// system properties in samevm/agentvm mode.2526/*27* @test28* @bug 816108629* @summary DTLS handshaking fails if some messages were lost30* @modules java.base/sun.security.util31* @library /test/lib32* @build DTLSOverDatagram33*34* @run main/othervm PacketLossRetransmission client 0 hello_request35* @run main/othervm PacketLossRetransmission client 1 client_hello36* @run main/othervm PacketLossRetransmission client 2 server_hello37* @run main/othervm PacketLossRetransmission client 3 hello_verify_request38* @run main/othervm -Djdk.tls.client.enableSessionTicketExtension=false PacketLossRetransmission client 4 new_session_ticket39* @run main/othervm PacketLossRetransmission client 11 certificate40* @run main/othervm PacketLossRetransmission client 12 server_key_exchange41* @run main/othervm PacketLossRetransmission client 13 certificate_request42* @run main/othervm PacketLossRetransmission client 14 server_hello_done43* @run main/othervm PacketLossRetransmission client 15 certificate_verify44* @run main/othervm PacketLossRetransmission client 16 client_key_exchange45* @run main/othervm PacketLossRetransmission client 20 finished46* @run main/othervm PacketLossRetransmission client 21 certificate_url47* @run main/othervm PacketLossRetransmission client 22 certificate_status48* @run main/othervm PacketLossRetransmission client 23 supplemental_data49* @run main/othervm PacketLossRetransmission client -1 change_cipher_spec50* @run main/othervm PacketLossRetransmission server 0 hello_request51* @run main/othervm PacketLossRetransmission server 1 client_hello52* @run main/othervm PacketLossRetransmission server 2 server_hello53* @run main/othervm PacketLossRetransmission server 3 hello_verify_request54* @run main/othervm -Djdk.tls.client.enableSessionTicketExtension=false PacketLossRetransmission server 4 new_session_ticket55* @run main/othervm PacketLossRetransmission server 11 certificate56* @run main/othervm PacketLossRetransmission server 12 server_key_exchange57* @run main/othervm PacketLossRetransmission server 13 certificate_request58* @run main/othervm PacketLossRetransmission server 14 server_hello_done59* @run main/othervm PacketLossRetransmission server 15 certificate_verify60* @run main/othervm PacketLossRetransmission server 16 client_key_exchange61* @run main/othervm PacketLossRetransmission server 20 finished62* @run main/othervm PacketLossRetransmission server 21 certificate_url63* @run main/othervm PacketLossRetransmission server 22 certificate_status64* @run main/othervm PacketLossRetransmission server 23 supplemental_data65* @run main/othervm PacketLossRetransmission server -1 change_cipher_spec66*/6768import java.util.List;69import java.util.ArrayList;70import java.net.DatagramPacket;71import java.net.SocketAddress;72import javax.net.ssl.SSLEngine;7374/**75* Test that DTLS implementation is able to do retransmission internally76* automatically if packet get lost.77*/78public class PacketLossRetransmission extends DTLSOverDatagram {79private static boolean isClient;80private static byte handshakeType;8182private boolean needPacketLoss = true;8384public static void main(String[] args) throws Exception {85isClient = args[0].equals("client");86handshakeType = Byte.parseByte(args[1]);8788PacketLossRetransmission testCase = new PacketLossRetransmission();89testCase.runTest(testCase);90}9192@Override93boolean produceHandshakePackets(SSLEngine engine, SocketAddress socketAddr,94String side, List<DatagramPacket> packets) throws Exception {9596boolean finished = super.produceHandshakePackets(97engine, socketAddr, side, packets);9899if (needPacketLoss && (isClient == engine.getUseClientMode())) {100DatagramPacket packet = getPacket(packets, handshakeType);101if (packet != null) {102needPacketLoss = false;103104System.out.println("Loss a packet of handshake messahe");105packets.remove(packet);106}107}108109return finished;110}111}112113114