author | xuelei |
Fri, 14 Jun 2019 12:19:14 -0700 | |
changeset 55411 | 328d4a455e4b |
parent 54816 | b27f33bef884 |
permissions | -rw-r--r-- |
54816
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
1 |
/* |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
2 |
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
4 |
* |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
8 |
* |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
13 |
* accompanied this code). |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
14 |
* |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
18 |
* |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
21 |
* questions. |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
22 |
*/ |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
23 |
|
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
24 |
// |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
25 |
// Please run in othervm mode. SunJSSE does not support dynamic system |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
26 |
// properties, no way to re-use system properties in samevm/agentvm mode. |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
27 |
// |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
28 |
|
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
29 |
/* |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
30 |
* @test |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
31 |
* @bug 8221253 |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
32 |
* @summary TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
33 |
* @modules jdk.crypto.ec |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
34 |
* @library /javax/net/ssl/templates |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
35 |
* @run main/othervm Tls13PacketSize |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
36 |
*/ |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
37 |
import java.io.InputStream; |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
38 |
import java.io.OutputStream; |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
39 |
import javax.net.ssl.SSLSocket; |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
40 |
|
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
41 |
public class Tls13PacketSize extends SSLSocketTemplate { |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
42 |
private static final byte[] appData = new byte[16385]; |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
43 |
static { |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
44 |
for (int i = 0; i < appData.length; i++) { |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
45 |
appData[i] = (byte)('A' + (i % 26)); |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
46 |
} |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
47 |
} |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
48 |
|
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
49 |
// Run the test case. |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
50 |
public static void main(String[] args) throws Exception { |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
51 |
(new Tls13PacketSize()).run(); |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
52 |
} |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
53 |
|
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
54 |
@Override |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
55 |
protected void runServerApplication(SSLSocket socket) throws Exception { |
55411
328d4a455e4b
8224829: AsyncSSLSocketClose.java has timing issue
xuelei
parents:
54816
diff
changeset
|
56 |
// Set SO_LINGER in case of slow socket |
328d4a455e4b
8224829: AsyncSSLSocketClose.java has timing issue
xuelei
parents:
54816
diff
changeset
|
57 |
socket.setSoLinger(true, 10); |
328d4a455e4b
8224829: AsyncSSLSocketClose.java has timing issue
xuelei
parents:
54816
diff
changeset
|
58 |
|
54816
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
59 |
// here comes the test logic |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
60 |
InputStream sslIS = socket.getInputStream(); |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
61 |
OutputStream sslOS = socket.getOutputStream(); |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
62 |
|
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
63 |
sslIS.read(); |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
64 |
int extra = sslIS.available(); |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
65 |
System.out.println("Server input bytes: " + extra); |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
66 |
// Considering the padding impact, the record plaintext is less |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
67 |
// than the TLSPlaintext.fragment length (2^14). |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
68 |
if (extra >= 16383) { // 16383: 2^14 - 1 byte read above |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
69 |
throw new Exception( |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
70 |
"Client record plaintext exceeds 2^14 octets: " + extra); |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
71 |
} |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
72 |
|
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
73 |
sslOS.write(appData); |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
74 |
sslOS.flush(); |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
75 |
} |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
76 |
|
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
77 |
/* |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
78 |
* Define the client side application of the test for the specified socket. |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
79 |
* This method is used if the returned value of |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
80 |
* isCustomizedClientConnection() is false. |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
81 |
* |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
82 |
* @param socket may be null is no client socket is generated. |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
83 |
* |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
84 |
* @see #isCustomizedClientConnection() |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
85 |
*/ |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
86 |
protected void runClientApplication(SSLSocket socket) throws Exception { |
55411
328d4a455e4b
8224829: AsyncSSLSocketClose.java has timing issue
xuelei
parents:
54816
diff
changeset
|
87 |
// Set SO_LINGER in case of slow socket |
328d4a455e4b
8224829: AsyncSSLSocketClose.java has timing issue
xuelei
parents:
54816
diff
changeset
|
88 |
socket.setSoLinger(true, 10); |
328d4a455e4b
8224829: AsyncSSLSocketClose.java has timing issue
xuelei
parents:
54816
diff
changeset
|
89 |
|
54816
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
90 |
socket.setEnabledProtocols(new String[] {"TLSv1.3"}); |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
91 |
InputStream sslIS = socket.getInputStream(); |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
92 |
OutputStream sslOS = socket.getOutputStream(); |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
93 |
|
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
94 |
sslOS.write(appData); |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
95 |
sslOS.flush(); |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
96 |
|
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
97 |
sslIS.read(); |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
98 |
int extra = sslIS.available(); |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
99 |
System.out.println("Client input bytes: " + extra); |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
100 |
// Considering the padding impact, the record plaintext is less |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
101 |
// than the TLSPlaintext.fragment length (2^14). |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
102 |
if (extra >= 16383) { // 16383: 2^14 - 1 byte read above |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
103 |
throw new Exception( |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
104 |
"Server record plaintext exceeds 2^14 octets: " + extra); |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
105 |
} |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
106 |
} |
b27f33bef884
8221253: TLSv1.3 may generate TLSInnerPlainText longer than 2^14+1 bytes
xuelei
parents:
diff
changeset
|
107 |
} |