Path: blob/master/test/jdk/javax/net/ssl/SSLSocket/Tls13PacketSize.java
41152 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* @modules jdk.crypto.ec33* @library /javax/net/ssl/templates34* @run main/othervm Tls13PacketSize35*/36import java.io.InputStream;37import java.io.OutputStream;38import javax.net.ssl.SSLSocket;3940public class Tls13PacketSize extends SSLSocketTemplate {41private static final byte[] appData = new byte[16385];42static {43for (int i = 0; i < appData.length; i++) {44appData[i] = (byte)('A' + (i % 26));45}46}4748// Run the test case.49public static void main(String[] args) throws Exception {50(new Tls13PacketSize()).run();51}5253@Override54protected void runServerApplication(SSLSocket socket) throws Exception {55// Set SO_LINGER in case of slow socket56socket.setSoLinger(true, 10);5758// here comes the test logic59InputStream sslIS = socket.getInputStream();60OutputStream sslOS = socket.getOutputStream();6162sslIS.read();63int extra = sslIS.available();64System.out.println("Server input bytes: " + extra);65// Considering the padding impact, the record plaintext is less66// than the TLSPlaintext.fragment length (2^14).67if (extra >= 16383) { // 16383: 2^14 - 1 byte read above68throw new Exception(69"Client record plaintext exceeds 2^14 octets: " + extra);70}7172sslOS.write(appData);73sslOS.flush();74}7576/*77* Define the client side application of the test for the specified socket.78* This method is used if the returned value of79* isCustomizedClientConnection() is false.80*81* @param socket may be null is no client socket is generated.82*83* @see #isCustomizedClientConnection()84*/85protected void runClientApplication(SSLSocket socket) throws Exception {86// Set SO_LINGER in case of slow socket87socket.setSoLinger(true, 10);8889socket.setEnabledProtocols(new String[] {"TLSv1.3"});90InputStream sslIS = socket.getInputStream();91OutputStream sslOS = socket.getOutputStream();9293sslOS.write(appData);94sslOS.flush();9596sslIS.read();97int extra = sslIS.available();98System.out.println("Client input bytes: " + extra);99// Considering the padding impact, the record plaintext is less100// than the TLSPlaintext.fragment length (2^14).101if (extra >= 16383) { // 16383: 2^14 - 1 byte read above102throw new Exception(103"Server record plaintext exceeds 2^14 octets: " + extra);104}105}106}107108109