Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/net/ssl/SSLSocket/Tls13PacketSize.java
38853 views
1
/*
2
* Copyright (c) 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
//
25
// Please run in othervm mode. SunJSSE does not support dynamic system
26
// properties, no way to re-use system properties in samevm/agentvm mode.
27
//
28
29
/*
30
* @test
31
* @bug 8221253
32
* @summary TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
33
* @library /javax/net/ssl/templates
34
* @run main/othervm -Djdk.tls.client.protocols="TLSv1.3,TLSv1.2,TLSv1.1,TLSv1,SSLv3" Tls13PacketSize
35
*/
36
import java.io.InputStream;
37
import java.io.OutputStream;
38
import javax.net.ssl.SSLSocket;
39
40
public class Tls13PacketSize extends SSLSocketTemplate {
41
private static final byte[] appData = new byte[16385];
42
static {
43
for (int i = 0; i < appData.length; i++) {
44
appData[i] = (byte)('A' + (i % 26));
45
}
46
}
47
48
// Run the test case.
49
public static void main(String[] args) throws Exception {
50
(new Tls13PacketSize()).run();
51
}
52
53
@Override
54
protected void runServerApplication(SSLSocket socket) throws Exception {
55
// here comes the test logic
56
InputStream sslIS = socket.getInputStream();
57
OutputStream sslOS = socket.getOutputStream();
58
59
sslIS.read();
60
int extra = sslIS.available();
61
System.out.println("Server input bytes: " + extra);
62
// Considering the padding impact, the record plaintext is less
63
// than the TLSPlaintext.fragment length (2^14).
64
if (extra >= 16383) { // 16383: 2^14 - 1 byte read above
65
throw new Exception(
66
"Client record plaintext exceeds 2^14 octets: " + extra);
67
}
68
69
sslOS.write(appData);
70
sslOS.flush();
71
}
72
73
/*
74
* Define the client side application of the test for the specified socket.
75
* This method is used if the returned value of
76
* isCustomizedClientConnection() is false.
77
*
78
* @param socket may be null is no client socket is generated.
79
*
80
* @see #isCustomizedClientConnection()
81
*/
82
protected void runClientApplication(SSLSocket socket) throws Exception {
83
socket.setEnabledProtocols(new String[] {"TLSv1.3"});
84
InputStream sslIS = socket.getInputStream();
85
OutputStream sslOS = socket.getOutputStream();
86
87
sslOS.write(appData);
88
sslOS.flush();
89
90
sslIS.read();
91
int extra = sslIS.available();
92
System.out.println("Client input bytes: " + extra);
93
// Considering the padding impact, the record plaintext is less
94
// than the TLSPlaintext.fragment length (2^14).
95
if (extra >= 16383) { // 16383: 2^14 - 1 byte read above
96
throw new Exception(
97
"Server record plaintext exceeds 2^14 octets: " + extra);
98
}
99
}
100
}
101
102