Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/net/ssl/SSLSocket/Tls13PacketSize.java
41152 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
* @modules jdk.crypto.ec
34
* @library /javax/net/ssl/templates
35
* @run main/othervm Tls13PacketSize
36
*/
37
import java.io.InputStream;
38
import java.io.OutputStream;
39
import javax.net.ssl.SSLSocket;
40
41
public class Tls13PacketSize extends SSLSocketTemplate {
42
private static final byte[] appData = new byte[16385];
43
static {
44
for (int i = 0; i < appData.length; i++) {
45
appData[i] = (byte)('A' + (i % 26));
46
}
47
}
48
49
// Run the test case.
50
public static void main(String[] args) throws Exception {
51
(new Tls13PacketSize()).run();
52
}
53
54
@Override
55
protected void runServerApplication(SSLSocket socket) throws Exception {
56
// Set SO_LINGER in case of slow socket
57
socket.setSoLinger(true, 10);
58
59
// here comes the test logic
60
InputStream sslIS = socket.getInputStream();
61
OutputStream sslOS = socket.getOutputStream();
62
63
sslIS.read();
64
int extra = sslIS.available();
65
System.out.println("Server input bytes: " + extra);
66
// Considering the padding impact, the record plaintext is less
67
// than the TLSPlaintext.fragment length (2^14).
68
if (extra >= 16383) { // 16383: 2^14 - 1 byte read above
69
throw new Exception(
70
"Client record plaintext exceeds 2^14 octets: " + extra);
71
}
72
73
sslOS.write(appData);
74
sslOS.flush();
75
}
76
77
/*
78
* Define the client side application of the test for the specified socket.
79
* This method is used if the returned value of
80
* isCustomizedClientConnection() is false.
81
*
82
* @param socket may be null is no client socket is generated.
83
*
84
* @see #isCustomizedClientConnection()
85
*/
86
protected void runClientApplication(SSLSocket socket) throws Exception {
87
// Set SO_LINGER in case of slow socket
88
socket.setSoLinger(true, 10);
89
90
socket.setEnabledProtocols(new String[] {"TLSv1.3"});
91
InputStream sslIS = socket.getInputStream();
92
OutputStream sslOS = socket.getOutputStream();
93
94
sslOS.write(appData);
95
sslOS.flush();
96
97
sslIS.read();
98
int extra = sslIS.available();
99
System.out.println("Client input bytes: " + extra);
100
// Considering the padding impact, the record plaintext is less
101
// than the TLSPlaintext.fragment length (2^14).
102
if (extra >= 16383) { // 16383: 2^14 - 1 byte read above
103
throw new Exception(
104
"Server record plaintext exceeds 2^14 octets: " + extra);
105
}
106
}
107
}
108
109