@@ -513,54 +513,46 @@ TCN_IMPLEMENT_CALL(void, SSLContext, setQuietShutdown)(TCN_STDARGS, jlong ctx,
513513}
514514
515515TCN_IMPLEMENT_CALL (jboolean , SSLContext , setCipherSuite )(TCN_STDARGS , jlong ctx ,
516- jstring ciphers )
516+ jstring cipherList )
517517{
518518 tcn_ssl_ctxt_t * c = J2P (ctx , tcn_ssl_ctxt_t * );
519- TCN_ALLOC_CSTRING (ciphers );
519+ TCN_ALLOC_CSTRING (cipherList );
520520 jboolean rv = JNI_TRUE ;
521- int minProtoVer = 0 ;
522- int maxProtoVer = 0 ;
523- int ciphersSet = 0 ;
524521#ifndef HAVE_EXPORT_CIPHERS
525522 size_t len ;
526523 char * buf ;
527524#endif
528-
529525 UNREFERENCED (o );
530- TCN_ASSERT (ctx != 0 );
531- if (!J2S (ciphers ))
526+
527+ if (c == NULL ) {
528+ TCN_FREE_CSTRING (cipherList );
529+ tcn_ThrowException (e , "ssl context is null" );
532530 return JNI_FALSE ;
531+ }
533532
534- minProtoVer = SSL_CTX_get_min_proto_version (c -> ctx );
535- maxProtoVer = SSL_CTX_get_max_proto_version (c -> ctx );
533+ if (!J2S (cipherList )) {
534+ rv = JNI_FALSE ;
535+ goto free_cipherList ;
536+ }
536537
537538#ifndef HAVE_EXPORT_CIPHERS
538539 /*
539540 * Always disable NULL and export ciphers,
540541 * no matter what was given in the config.
541542 */
542- len = strlen (J2S (ciphers )) + strlen (SSL_CIPHERS_ALWAYS_DISABLED ) + 1 ;
543+ len = strlen (J2S (cipherList )) + strlen (SSL_CIPHERS_ALWAYS_DISABLED ) + 1 ;
543544 buf = malloc (len * sizeof (char * ));
544- if (buf == NULL )
545- return JNI_FALSE ;
545+ if (buf == NULL ) {
546+ rv = JNI_FALSE ;
547+ goto free_cipherList ;
548+ }
546549 memcpy (buf , SSL_CIPHERS_ALWAYS_DISABLED , strlen (SSL_CIPHERS_ALWAYS_DISABLED ));
547- memcpy (buf + strlen (SSL_CIPHERS_ALWAYS_DISABLED ), J2S (ciphers ), strlen (J2S (ciphers )));
550+ memcpy (buf + strlen (SSL_CIPHERS_ALWAYS_DISABLED ), J2S (cipherList ), strlen (J2S (cipherList )));
548551 buf [len - 1 ] = '\0' ;
552+ if (!SSL_CTX_set_cipher_list (c -> ctx , buf )) {
549553#else
550- buf = ( char * ) J2S (ciphers );
554+ if (! SSL_CTX_set_cipher_list ( c -> ctx , J2S (cipherList ))) {
551555#endif
552- /* OpenSSL will ignore any unknown cipher, but TLS 1.3 requires a call to SSL_CTX_set_ciphersuites */
553- if (minProtoVer <= TLS1_2_VERSION ) {
554- if (SSL_CTX_set_cipher_list (c -> ctx , buf )) {
555- ciphersSet = 1 ;
556- }
557- }
558- if (maxProtoVer >= TLS1_3_VERSION ) {
559- if (SSL_CTX_set_ciphersuites (c -> ctx , buf )) {
560- ciphersSet = 1 ;
561- }
562- }
563- if (!ciphersSet ) {
564556 char err [TCN_OPENSSL_ERROR_STRING_LENGTH ];
565557 ERR_error_string_n (SSL_ERR_get (), err , TCN_OPENSSL_ERROR_STRING_LENGTH );
566558 tcn_Throw (e , "Unable to configure permitted SSL ciphers (%s)" , err );
@@ -569,7 +561,39 @@ TCN_IMPLEMENT_CALL(jboolean, SSLContext, setCipherSuite)(TCN_STDARGS, jlong ctx,
569561#ifndef HAVE_EXPORT_CIPHERS
570562 free (buf );
571563#endif
572- TCN_FREE_CSTRING (ciphers );
564+ free_cipherList :
565+ TCN_FREE_CSTRING (cipherList );
566+ return rv ;
567+ }
568+
569+ TCN_IMPLEMENT_CALL (jboolean , SSLContext , setCipherSuitesEx )(TCN_STDARGS , jlong ctx ,
570+ jstring cipherSuites )
571+ {
572+ tcn_ssl_ctxt_t * c = J2P (ctx , tcn_ssl_ctxt_t * );
573+ TCN_ALLOC_CSTRING (cipherSuites );
574+ jboolean rv = JNI_TRUE ;
575+ UNREFERENCED (o );
576+
577+ if (c == NULL ) {
578+ TCN_FREE_CSTRING (cipherSuites );
579+ tcn_ThrowException (e , "ssl context is null" );
580+ return JNI_FALSE ;
581+ }
582+
583+ if (!J2S (cipherSuites )) {
584+ rv = JNI_FALSE ;
585+ goto free_cipherSuites ;
586+ }
587+
588+ if (SSL_CTX_set_ciphersuites (c -> ctx , J2S (cipherSuites ))) {
589+ char err [TCN_OPENSSL_ERROR_STRING_LENGTH ];
590+ ERR_error_string_n (SSL_ERR_get (), err , TCN_OPENSSL_ERROR_STRING_LENGTH );
591+ tcn_Throw (e , "Unable to configure permitted SSL cipher suites (%s)" , err );
592+ rv = JNI_FALSE ;
593+ }
594+
595+ free_cipherSuites :
596+ TCN_FREE_CSTRING (cipherSuites );
573597 return rv ;
574598}
575599
0 commit comments