1
1
/*
2
- * Copyright (c) 2018, 2020 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2018, 2023 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
23
23
24
24
/*
25
25
* @test
26
- * @bug 8164879
26
+ * @bug 8164879 8300285
27
27
* @library ../../
28
28
* @library /test/lib
29
29
* @modules java.base/sun.security.util
30
- * @summary Verify AES/GCM's limits set in the jdk.tls.keyLimits property
31
- * @run main SSLSocketKeyLimit 0 server AES/GCM/NoPadding keyupdate 1000000
32
- * @run main SSLSocketKeyLimit 0 client AES/GCM/NoPadding keyupdate 1000000
33
- * @run main SSLSocketKeyLimit 1 client AES/GCM/NoPadding keyupdate 2^22
30
+ * @summary Verify AEAD TLS cipher suite limits set in the jdk.tls.keyLimits
31
+ * property
32
+ * @run main SSLSocketKeyLimit 0 server TLS_AES_256_GCM_SHA384
33
+ * AES/GCM/NoPadding keyupdate 1000000
34
+ * @run main SSLSocketKeyLimit 0 client TLS_AES_256_GCM_SHA384
35
+ * AES/GCM/NoPadding keyupdate 1000000
36
+ * @run main SSLSocketKeyLimit 1 client TLS_AES_256_GCM_SHA384
37
+ * AES/GCM/NoPadding keyupdate 2^22
38
+ * @run main SSLSocketKeyLimit 0 server TLS_CHACHA20_POLY1305_SHA256
39
+ * AES/GCM/NoPadding keyupdate 1000000, ChaCha20-Poly1305 KeyUpdate 1000000
40
+ * @run main SSLSocketKeyLimit 0 client TLS_CHACHA20_POLY1305_SHA256
41
+ * AES/GCM/NoPadding keyupdate 1000000, ChaCha20-Poly1305 KeyUpdate 1000000
42
+ * @run main SSLSocketKeyLimit 1 client TLS_CHACHA20_POLY1305_SHA256
43
+ * AES/GCM/NoPadding keyupdate 2^22, ChaCha20-Poly1305 KeyUpdate 2^22
34
44
*/
35
45
36
46
/**
@@ -96,7 +106,7 @@ SSLContext initContext() throws Exception {
96
106
}
97
107
98
108
/**
99
- * args should have two values: server|client, <limit size>
109
+ * args should have three values: server|client, cipher suite , <limit size>
100
110
* Prepending 'p' is for internal use only.
101
111
*/
102
112
public static void main (String args []) throws Exception {
@@ -110,7 +120,7 @@ public static void main(String args[]) throws Exception {
110
120
File f = new File ("keyusage." + System .nanoTime ());
111
121
PrintWriter p = new PrintWriter (f );
112
122
p .write ("jdk.tls.keyLimits=" );
113
- for (int i = 2 ; i < args .length ; i ++) {
123
+ for (int i = 3 ; i < args .length ; i ++) {
114
124
p .write (" " + args [i ]);
115
125
}
116
126
p .close ();
@@ -125,10 +135,13 @@ public static void main(String args[]) throws Exception {
125
135
System .getProperty ("test.java.opts" ));
126
136
127
137
ProcessBuilder pb = ProcessTools .createTestJvm (
128
- Utils .addTestJavaOpts ("SSLSocketKeyLimit" , "p" , args [1 ]));
138
+ Utils .addTestJavaOpts ("SSLSocketKeyLimit" , "p" , args [1 ],
139
+ args [2 ]));
129
140
130
141
OutputAnalyzer output = ProcessTools .executeProcess (pb );
131
142
try {
143
+ output .shouldContain (String .format (
144
+ "\" cipher suite\" : \" %s" , args [2 ]));
132
145
if (expectedFail ) {
133
146
output .shouldNotContain ("KeyUpdate: write key updated" );
134
147
output .shouldNotContain ("KeyUpdate: read key updated" );
@@ -150,7 +163,7 @@ public static void main(String args[]) throws Exception {
150
163
return ;
151
164
}
152
165
153
- if (args .length > 0 && args [0 ].compareToIgnoreCase ("client" ) == 0 ) {
166
+ if (args .length > 0 && args [1 ].compareToIgnoreCase ("client" ) == 0 ) {
154
167
serverwrite = false ;
155
168
}
156
169
@@ -162,7 +175,7 @@ public static void main(String args[]) throws Exception {
162
175
System .setProperty ("javax.net.ssl.keyStorePassword" , passwd );
163
176
164
177
Arrays .fill (data , (byte )0x0A );
165
- Thread ts = new Thread (new Server ());
178
+ Thread ts = new Thread (new Server (args [ 2 ] ));
166
179
167
180
ts .start ();
168
181
while (!serverReady ) {
@@ -200,7 +213,8 @@ void read(SSLSocket s) throws Exception {
200
213
int len ;
201
214
byte i = 0 ;
202
215
try {
203
- System .out .println ("Server: connected " + s .getSession ().getCipherSuite ());
216
+ System .out .println ("Server: connected " +
217
+ s .getSession ().getCipherSuite ());
204
218
in = s .getInputStream ();
205
219
out = s .getOutputStream ();
206
220
while (true ) {
@@ -212,7 +226,8 @@ void read(SSLSocket s) throws Exception {
212
226
if (b == 0x0A || b == 0x0D ) {
213
227
continue ;
214
228
}
215
- System .out .println ("\n Data invalid: " + HexPrinter .minimal ().toString (buf ));
229
+ System .out .println ("\n Data invalid: " +
230
+ HexPrinter .minimal ().toString (buf ));
216
231
break ;
217
232
}
218
233
@@ -237,11 +252,14 @@ void read(SSLSocket s) throws Exception {
237
252
static class Server extends SSLSocketKeyLimit implements Runnable {
238
253
private SSLServerSocketFactory ssf ;
239
254
private SSLServerSocket ss ;
240
- Server () {
255
+ Server (String cipherSuite ) {
241
256
super ();
242
257
try {
243
258
ssf = initContext ().getServerSocketFactory ();
244
259
ss = (SSLServerSocket ) ssf .createServerSocket (serverPort );
260
+ if (cipherSuite != null && cipherSuite .length () > 0 ) {
261
+ ss .setEnabledCipherSuites (new String [] { cipherSuite });
262
+ }
245
263
serverPort = ss .getLocalPort ();
246
264
} catch (Exception e ) {
247
265
System .out .println ("server: " + e .getMessage ());
0 commit comments