11/*
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.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
2323
2424/*
2525 * @test
26- * @bug 8164879
26+ * @bug 8164879 8300285
2727 * @library ../../
2828 * @library /test/lib
2929 * @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
3444 */
3545
3646 /**
@@ -96,7 +106,7 @@ SSLContext initContext() throws Exception {
96106 }
97107
98108 /**
99- * args should have two values: server|client, <limit size>
109+ * args should have three values: server|client, cipher suite , <limit size>
100110 * Prepending 'p' is for internal use only.
101111 */
102112 public static void main (String args []) throws Exception {
@@ -110,7 +120,7 @@ public static void main(String args[]) throws Exception {
110120 File f = new File ("keyusage." + System .nanoTime ());
111121 PrintWriter p = new PrintWriter (f );
112122 p .write ("jdk.tls.keyLimits=" );
113- for (int i = 2 ; i < args .length ; i ++) {
123+ for (int i = 3 ; i < args .length ; i ++) {
114124 p .write (" " + args [i ]);
115125 }
116126 p .close ();
@@ -125,10 +135,13 @@ public static void main(String args[]) throws Exception {
125135 System .getProperty ("test.java.opts" ));
126136
127137 ProcessBuilder pb = ProcessTools .createTestJvm (
128- Utils .addTestJavaOpts ("SSLSocketKeyLimit" , "p" , args [1 ]));
138+ Utils .addTestJavaOpts ("SSLSocketKeyLimit" , "p" , args [1 ],
139+ args [2 ]));
129140
130141 OutputAnalyzer output = ProcessTools .executeProcess (pb );
131142 try {
143+ output .shouldContain (String .format (
144+ "\" cipher suite\" : \" %s" , args [2 ]));
132145 if (expectedFail ) {
133146 output .shouldNotContain ("KeyUpdate: write key updated" );
134147 output .shouldNotContain ("KeyUpdate: read key updated" );
@@ -150,7 +163,7 @@ public static void main(String args[]) throws Exception {
150163 return ;
151164 }
152165
153- if (args .length > 0 && args [0 ].compareToIgnoreCase ("client" ) == 0 ) {
166+ if (args .length > 0 && args [1 ].compareToIgnoreCase ("client" ) == 0 ) {
154167 serverwrite = false ;
155168 }
156169
@@ -162,7 +175,7 @@ public static void main(String args[]) throws Exception {
162175 System .setProperty ("javax.net.ssl.keyStorePassword" , passwd );
163176
164177 Arrays .fill (data , (byte )0x0A );
165- Thread ts = new Thread (new Server ());
178+ Thread ts = new Thread (new Server (args [ 2 ] ));
166179
167180 ts .start ();
168181 while (!serverReady ) {
@@ -200,7 +213,8 @@ void read(SSLSocket s) throws Exception {
200213 int len ;
201214 byte i = 0 ;
202215 try {
203- System .out .println ("Server: connected " + s .getSession ().getCipherSuite ());
216+ System .out .println ("Server: connected " +
217+ s .getSession ().getCipherSuite ());
204218 in = s .getInputStream ();
205219 out = s .getOutputStream ();
206220 while (true ) {
@@ -212,7 +226,8 @@ void read(SSLSocket s) throws Exception {
212226 if (b == 0x0A || b == 0x0D ) {
213227 continue ;
214228 }
215- System .out .println ("\n Data invalid: " + HexPrinter .minimal ().toString (buf ));
229+ System .out .println ("\n Data invalid: " +
230+ HexPrinter .minimal ().toString (buf ));
216231 break ;
217232 }
218233
@@ -237,11 +252,14 @@ void read(SSLSocket s) throws Exception {
237252 static class Server extends SSLSocketKeyLimit implements Runnable {
238253 private SSLServerSocketFactory ssf ;
239254 private SSLServerSocket ss ;
240- Server () {
255+ Server (String cipherSuite ) {
241256 super ();
242257 try {
243258 ssf = initContext ().getServerSocketFactory ();
244259 ss = (SSLServerSocket ) ssf .createServerSocket (serverPort );
260+ if (cipherSuite != null && cipherSuite .length () > 0 ) {
261+ ss .setEnabledCipherSuites (new String [] { cipherSuite });
262+ }
245263 serverPort = ss .getLocalPort ();
246264 } catch (Exception e ) {
247265 System .out .println ("server: " + e .getMessage ());
0 commit comments