@@ -179,7 +179,7 @@ public static void testSetupSocketFactory() throws NoSuchProviderException,
179179 try {
180180 tf = new WolfSSLTestFactory ();
181181 } catch (WolfSSLException e ) {
182- // TODO Auto-generated catch block
182+ /* TODO Auto-generated catch block */
183183 e .printStackTrace ();
184184 }
185185
@@ -321,6 +321,99 @@ public void testGetSetEnabledCipherSuites()
321321 System .out .println ("\t ... passed" );
322322 }
323323
324+ @ Test
325+ public void testServerUsesClientCipherSuitePreference () throws Exception {
326+
327+ System .out .print ("\t Testing client suite preference" );
328+
329+ this .ctx = tf .createSSLContext ("TLS" , "wolfJSSE" );
330+
331+ String [] serverSuites = {
332+ "TLS_AES_256_GCM_SHA384" ,
333+ "TLS_AES_128_GCM_SHA256"
334+ };
335+
336+ String [] clientSuites = {
337+ "TLS_AES_128_GCM_SHA256" ,
338+ "TLS_AES_256_GCM_SHA384"
339+ };
340+
341+ /* --- Case 1: default (server order) --- */
342+ SSLServerSocket ss1 = (SSLServerSocket )ctx .getServerSocketFactory ()
343+ .createServerSocket (0 );
344+ ss1 .setEnabledCipherSuites (serverSuites );
345+
346+ SSLSocket cs1 = (SSLSocket )ctx .getSocketFactory ().createSocket ();
347+ cs1 .setEnabledCipherSuites (clientSuites );
348+ cs1 .connect (new InetSocketAddress (ss1 .getLocalPort ()));
349+
350+ final SSLSocket server1 = (SSLSocket )ss1 .accept ();
351+
352+ ExecutorService es = Executors .newSingleThreadExecutor ();
353+ Future <Void > f1 = es .submit (() -> {
354+ server1 .startHandshake ();
355+ return null ;
356+ });
357+
358+ cs1 .startHandshake ();
359+ f1 .get ();
360+
361+ String chosen1 = cs1 .getSession ().getCipherSuite ();
362+ /* Note: WolfSSL may report TLS 1.3 ciphers in IANA standard or wolfSSL
363+ * alias depending on wolfSSL configuration. */
364+ if (!"TLS_AES_256_GCM_SHA384" .equals (chosen1 ) &&
365+ !"TLS13-AES256-GCM-SHA384" .equals (chosen1 )) {
366+ System .out .println ("\t ... failed" );
367+ fail ("Expected server preference cipher (AES_256), got "
368+ + chosen1 );
369+ }
370+
371+ cs1 .close ();
372+ server1 .close ();
373+ ss1 .close ();
374+
375+ /* --- Case 2: server honors client order --- */
376+ SSLServerSocket ss2 = (SSLServerSocket )ctx .getServerSocketFactory ()
377+ .createServerSocket (0 );
378+ ss2 .setEnabledCipherSuites (serverSuites );
379+
380+ /* Do not honor local cipher suites preference */
381+ SSLParameters ss2Params = ss2 .getSSLParameters ();
382+ ss2Params .setUseCipherSuitesOrder (false );
383+ ss2 .setSSLParameters (ss2Params );
384+
385+ SSLSocket cs2 = (SSLSocket )ctx .getSocketFactory ().createSocket ();
386+ cs2 .setEnabledCipherSuites (clientSuites );
387+ cs2 .connect (new InetSocketAddress (ss2 .getLocalPort ()));
388+
389+ final SSLSocket server2 = (SSLSocket )ss2 .accept ();
390+
391+ Future <Void > f2 = es .submit (() -> {
392+ server2 .startHandshake ();
393+ return null ;
394+ });
395+
396+ cs2 .startHandshake ();
397+ f2 .get ();
398+
399+ String chosen2 = cs2 .getSession ().getCipherSuite ();
400+ /* Note: WolfSSL may report TLS 1.3 ciphers in IANA standard or wolfSSL
401+ * alias depending on wolfSSL configuration. */
402+ if (!"TLS_AES_128_GCM_SHA256" .equals (chosen2 ) &&
403+ !"TLS13-AES128-GCM-SHA256" .equals (chosen2 )) {
404+ System .out .println ("\t ... failed" );
405+ fail ("Expected client preference cipher (AES_128), got "
406+ + chosen2 );
407+ }
408+
409+ cs2 .close ();
410+ server2 .close ();
411+ ss2 .close ();
412+ es .shutdown ();
413+
414+ System .out .println ("\t ... passed" );
415+ }
416+
324417 @ Test
325418 public void testGetSupportedProtocols ()
326419 throws NoSuchProviderException , NoSuchAlgorithmException {
@@ -659,7 +752,7 @@ public void testEnabledSupportedCurvesProperty() throws Exception {
659752
660753 try {
661754 client .join (1000 );
662- // server.join(1000);
755+ /* server.join(1000); */
663756
664757 } catch (InterruptedException e ) {
665758 System .out .println ("interrupt happened" );
@@ -3402,14 +3495,14 @@ public void testAutoSNIProperty() throws Exception {
34023495 public void testSNIMatchers () throws Exception {
34033496
34043497 System .out .print ("\t Testing SNI Matchers" );
3405-
3498+
34063499 /* create new CTX */
34073500 this .ctx = tf .createSSLContext ("TLS" , ctxProvider );
3408-
3501+
34093502 /* create SSLServerSocket first to get ephemeral port */
34103503 final SSLServerSocket ss = (SSLServerSocket )ctx .getServerSocketFactory ()
34113504 .createServerSocket (0 );
3412-
3505+
34133506 /* Configure SNI matcher for server*/
34143507 SNIMatcher matcher = SNIHostName .createSNIMatcher ("www\\ .example\\ .com" );
34153508 Collection <SNIMatcher > matchers = new ArrayList <>();
@@ -3436,7 +3529,7 @@ public void testSNIMatchers() throws Exception {
34363529 cs .setSSLParameters (cp );
34373530
34383531 final SSLSocket serverMatched = (SSLSocket )ss .accept ();
3439-
3532+
34403533 ExecutorService es = Executors .newSingleThreadExecutor ();
34413534 Future <Void > serverFuture = es .submit (new Callable <Void >() {
34423535 @ Override
@@ -3451,10 +3544,10 @@ public Void call() throws Exception {
34513544 return null ;
34523545 }
34533546 });
3454-
3547+
34553548 cs .startHandshake ();
34563549 cs .close ();
3457-
3550+
34583551 es .shutdown ();
34593552 serverFuture .get ();
34603553
@@ -3473,7 +3566,7 @@ public Void call() throws Exception {
34733566 cs .setSSLParameters (cp );
34743567
34753568 final SSLSocket serverUnmatched = (SSLSocket )ss .accept ();
3476-
3569+
34773570 es = Executors .newSingleThreadExecutor ();
34783571 serverFuture = es .submit (() -> {
34793572 try {
0 commit comments