Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/net/ssl/SSLSocket/Tls13PacketSize.java
38853 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// Please run in othervm mode. SunJSSE does not support dynamic system25// properties, no way to re-use system properties in samevm/agentvm mode.26//2728/*29* @test30* @bug 822125331* @summary TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes32* @library /javax/net/ssl/templates33* @run main/othervm -Djdk.tls.client.protocols="TLSv1.3,TLSv1.2,TLSv1.1,TLSv1,SSLv3" Tls13PacketSize34*/35import java.io.InputStream;36import java.io.OutputStream;37import javax.net.ssl.SSLSocket;3839public class Tls13PacketSize extends SSLSocketTemplate {40private static final byte[] appData = new byte[16385];41static {42for (int i = 0; i < appData.length; i++) {43appData[i] = (byte)('A' + (i % 26));44}45}4647// Run the test case.48public static void main(String[] args) throws Exception {49(new Tls13PacketSize()).run();50}5152@Override53protected void runServerApplication(SSLSocket socket) throws Exception {54// here comes the test logic55InputStream sslIS = socket.getInputStream();56OutputStream sslOS = socket.getOutputStream();5758sslIS.read();59int extra = sslIS.available();60System.out.println("Server input bytes: " + extra);61// Considering the padding impact, the record plaintext is less62// than the TLSPlaintext.fragment length (2^14).63if (extra >= 16383) { // 16383: 2^14 - 1 byte read above64throw new Exception(65"Client record plaintext exceeds 2^14 octets: " + extra);66}6768sslOS.write(appData);69sslOS.flush();70}7172/*73* Define the client side application of the test for the specified socket.74* This method is used if the returned value of75* isCustomizedClientConnection() is false.76*77* @param socket may be null is no client socket is generated.78*79* @see #isCustomizedClientConnection()80*/81protected void runClientApplication(SSLSocket socket) throws Exception {82socket.setEnabledProtocols(new String[] {"TLSv1.3"});83InputStream sslIS = socket.getInputStream();84OutputStream sslOS = socket.getOutputStream();8586sslOS.write(appData);87sslOS.flush();8889sslIS.read();90int extra = sslIS.available();91System.out.println("Client input bytes: " + extra);92// Considering the padding impact, the record plaintext is less93// than the TLSPlaintext.fragment length (2^14).94if (extra >= 16383) { // 16383: 2^14 - 1 byte read above95throw new Exception(96"Server record plaintext exceeds 2^14 octets: " + extra);97}98}99}100101102