Path: blob/master/test/jdk/javax/net/ssl/DTLS/RespondToRetransmit.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 8161086 825891429* @key intermittent30* @summary DTLS handshaking fails if some messages were lost31* @modules java.base/sun.security.util32* @library /test/lib33* @build DTLSOverDatagram34*35* @run main/othervm RespondToRetransmit client 0 hello_request36* @run main/othervm RespondToRetransmit client 1 client_hello37* @run main/othervm RespondToRetransmit client 2 server_hello38* @run main/othervm RespondToRetransmit client 3 hello_verify_request39* @run main/othervm RespondToRetransmit client 4 new_session_ticket40* @run main/othervm RespondToRetransmit client 11 certificate41* @run main/othervm RespondToRetransmit client 12 server_key_exchange42* @run main/othervm RespondToRetransmit client 13 certificate_request43* @run main/othervm RespondToRetransmit client 14 server_hello_done44* @run main/othervm RespondToRetransmit client 15 certificate_verify45* @run main/othervm RespondToRetransmit client 16 client_key_exchange46* @run main/othervm RespondToRetransmit client 20 finished47* @run main/othervm RespondToRetransmit client 21 certificate_url48* @run main/othervm RespondToRetransmit client 22 certificate_status49* @run main/othervm RespondToRetransmit client 23 supplemental_data50* @run main/othervm RespondToRetransmit client -1 change_cipher_spec51* @run main/othervm RespondToRetransmit server 0 hello_request52* @run main/othervm RespondToRetransmit server 1 client_hello53* @run main/othervm RespondToRetransmit server 2 server_hello54* @run main/othervm RespondToRetransmit server 3 hello_verify_request55* @run main/othervm RespondToRetransmit server 4 new_session_ticket56* @run main/othervm RespondToRetransmit server 11 certificate57* @run main/othervm RespondToRetransmit server 12 server_key_exchange58* @run main/othervm RespondToRetransmit server 13 certificate_request59* @run main/othervm RespondToRetransmit server 14 server_hello_done60* @run main/othervm RespondToRetransmit server 15 certificate_verify61* @run main/othervm RespondToRetransmit server 16 client_key_exchange62* @run main/othervm RespondToRetransmit server 20 finished63* @run main/othervm RespondToRetransmit server 21 certificate_url64* @run main/othervm RespondToRetransmit server 22 certificate_status65* @run main/othervm RespondToRetransmit server 23 supplemental_data66* @run main/othervm RespondToRetransmit server -1 change_cipher_spec67*/6869import java.util.List;70import java.util.ArrayList;71import java.net.DatagramPacket;72import java.net.SocketAddress;73import javax.net.ssl.SSLEngine;7475/**76* Test that DTLS implementation is able to do retransmission internally77* automatically if packet get lost.78*/79public class RespondToRetransmit extends DTLSOverDatagram {80private static boolean isClient;81private static byte handshakeType;8283private boolean needPacketDuplicate = true;8485public static void main(String[] args) throws Exception {86isClient = args[0].equals("client");87handshakeType = Byte.parseByte(args[1]);8889RespondToRetransmit testCase = new RespondToRetransmit();90testCase.runTest(testCase);91}9293@Override94boolean produceHandshakePackets(SSLEngine engine, SocketAddress socketAddr,95String side, List<DatagramPacket> packets) throws Exception {9697boolean finished = super.produceHandshakePackets(98engine, socketAddr, side, packets);99100if (needPacketDuplicate && (isClient == engine.getUseClientMode())) {101DatagramPacket packet = getPacket(packets, handshakeType);102if (packet != null) {103needPacketDuplicate = false;104105System.out.println("Duplicate the flight.");106List<DatagramPacket> duplicates = new ArrayList<>();107finished = super.produceHandshakePackets(108engine, socketAddr, side, duplicates);109packets.addAll(duplicates);110}111}112113return finished;114}115}116117118