2929import java .io .IOException ;
3030import java .io .InputStream ;
3131import java .security .cert .CertificateException ;
32+ import java .util .Arrays ;
3233import java .util .Properties ;
3334import org .apache .rocketmq .common .constant .LoggerName ;
3435import org .apache .rocketmq .logging .org .slf4j .Logger ;
3536import org .apache .rocketmq .logging .org .slf4j .LoggerFactory ;
3637
38+ import static org .apache .rocketmq .remoting .netty .TlsSystemConfig .TLS_CIPHERS ;
3739import static org .apache .rocketmq .remoting .netty .TlsSystemConfig .TLS_CLIENT_AUTHSERVER ;
3840import static org .apache .rocketmq .remoting .netty .TlsSystemConfig .TLS_CLIENT_CERTPATH ;
3941import static org .apache .rocketmq .remoting .netty .TlsSystemConfig .TLS_CLIENT_KEYPASSWORD ;
4042import static org .apache .rocketmq .remoting .netty .TlsSystemConfig .TLS_CLIENT_KEYPATH ;
4143import static org .apache .rocketmq .remoting .netty .TlsSystemConfig .TLS_CLIENT_TRUSTCERTPATH ;
44+ import static org .apache .rocketmq .remoting .netty .TlsSystemConfig .TLS_PROTOCOLS ;
4245import static org .apache .rocketmq .remoting .netty .TlsSystemConfig .TLS_SERVER_AUTHCLIENT ;
4346import static org .apache .rocketmq .remoting .netty .TlsSystemConfig .TLS_SERVER_CERTPATH ;
4447import static org .apache .rocketmq .remoting .netty .TlsSystemConfig .TLS_SERVER_KEYPASSWORD ;
4548import static org .apache .rocketmq .remoting .netty .TlsSystemConfig .TLS_SERVER_KEYPATH ;
4649import static org .apache .rocketmq .remoting .netty .TlsSystemConfig .TLS_SERVER_NEED_CLIENT_AUTH ;
4750import static org .apache .rocketmq .remoting .netty .TlsSystemConfig .TLS_SERVER_TRUSTCERTPATH ;
4851import static org .apache .rocketmq .remoting .netty .TlsSystemConfig .TLS_TEST_MODE_ENABLE ;
52+ import static org .apache .rocketmq .remoting .netty .TlsSystemConfig .tlsCiphers ;
4953import static org .apache .rocketmq .remoting .netty .TlsSystemConfig .tlsClientAuthServer ;
5054import static org .apache .rocketmq .remoting .netty .TlsSystemConfig .tlsClientCertPath ;
5155import static org .apache .rocketmq .remoting .netty .TlsSystemConfig .tlsClientKeyPassword ;
5256import static org .apache .rocketmq .remoting .netty .TlsSystemConfig .tlsClientKeyPath ;
5357import static org .apache .rocketmq .remoting .netty .TlsSystemConfig .tlsClientTrustCertPath ;
58+ import static org .apache .rocketmq .remoting .netty .TlsSystemConfig .tlsProtocols ;
5459import static org .apache .rocketmq .remoting .netty .TlsSystemConfig .tlsServerAuthClient ;
5560import static org .apache .rocketmq .remoting .netty .TlsSystemConfig .tlsServerCertPath ;
5661import static org .apache .rocketmq .remoting .netty .TlsSystemConfig .tlsServerKeyPassword ;
@@ -102,15 +107,15 @@ public static SslContext buildSslContext(boolean forClient) throws IOException,
102107 LOGGER .info ("Using JDK SSL provider" );
103108 }
104109
110+ SslContextBuilder sslContextBuilder = null ;
105111 if (forClient ) {
106112 if (tlsTestModeEnable ) {
107- return SslContextBuilder
113+ sslContextBuilder = SslContextBuilder
108114 .forClient ()
109115 .sslProvider (SslProvider .JDK )
110- .trustManager (InsecureTrustManagerFactory .INSTANCE )
111- .build ();
116+ .trustManager (InsecureTrustManagerFactory .INSTANCE );
112117 } else {
113- SslContextBuilder sslContextBuilder = SslContextBuilder .forClient ().sslProvider (SslProvider .JDK );
118+ sslContextBuilder = SslContextBuilder .forClient ().sslProvider (SslProvider .JDK );
114119
115120
116121 if (!tlsClientAuthServer ) {
@@ -121,23 +126,21 @@ public static SslContext buildSslContext(boolean forClient) throws IOException,
121126 }
122127 }
123128
124- return sslContextBuilder .keyManager (
129+ sslContextBuilder = sslContextBuilder .keyManager (
125130 !isNullOrEmpty (tlsClientCertPath ) ? new FileInputStream (tlsClientCertPath ) : null ,
126131 !isNullOrEmpty (tlsClientKeyPath ) ? decryptionStrategy .decryptPrivateKey (tlsClientKeyPath , true ) : null ,
127- !isNullOrEmpty (tlsClientKeyPassword ) ? tlsClientKeyPassword : null )
128- .build ();
132+ !isNullOrEmpty (tlsClientKeyPassword ) ? tlsClientKeyPassword : null );
129133 }
130134 } else {
131135
132136 if (tlsTestModeEnable ) {
133137 SelfSignedCertificate selfSignedCertificate = new SelfSignedCertificate ();
134- return SslContextBuilder
138+ sslContextBuilder = SslContextBuilder
135139 .forServer (selfSignedCertificate .certificate (), selfSignedCertificate .privateKey ())
136140 .sslProvider (provider )
137- .clientAuth (ClientAuth .OPTIONAL )
138- .build ();
141+ .clientAuth (ClientAuth .OPTIONAL );
139142 } else {
140- SslContextBuilder sslContextBuilder = SslContextBuilder .forServer (
143+ sslContextBuilder = SslContextBuilder .forServer (
141144 !isNullOrEmpty (tlsServerCertPath ) ? new FileInputStream (tlsServerCertPath ) : null ,
142145 !isNullOrEmpty (tlsServerKeyPath ) ? decryptionStrategy .decryptPrivateKey (tlsServerKeyPath , false ) : null ,
143146 !isNullOrEmpty (tlsServerKeyPassword ) ? tlsServerKeyPassword : null )
@@ -152,11 +155,20 @@ public static SslContext buildSslContext(boolean forClient) throws IOException,
152155 }
153156
154157 sslContextBuilder .clientAuth (parseClientAuthMode (tlsServerNeedClientAuth ));
155- return sslContextBuilder .build ();
156158 }
157159 }
160+ moreTlsConfig (sslContextBuilder );
161+ return sslContextBuilder .build ();
158162 }
159163
164+ protected static void moreTlsConfig (SslContextBuilder sslContextBuilder ) {
165+ if (tlsCiphers != null ) {
166+ sslContextBuilder .ciphers (Arrays .asList (tlsCiphers .split ("," )));
167+ }
168+ if (tlsProtocols != null ) {
169+ sslContextBuilder .protocols (tlsProtocols .split ("," ));
170+ }
171+ }
160172 private static void extractTlsConfigFromFile (final File configFile ) {
161173 if (!(configFile .exists () && configFile .isFile () && configFile .canRead ())) {
162174 LOGGER .info ("Tls config file doesn't exist, skip it" );
@@ -192,6 +204,9 @@ private static void extractTlsConfigFromFile(final File configFile) {
192204 tlsClientCertPath = properties .getProperty (TLS_CLIENT_CERTPATH , tlsClientCertPath );
193205 tlsClientAuthServer = Boolean .parseBoolean (properties .getProperty (TLS_CLIENT_AUTHSERVER , String .valueOf (tlsClientAuthServer )));
194206 tlsClientTrustCertPath = properties .getProperty (TLS_CLIENT_TRUSTCERTPATH , tlsClientTrustCertPath );
207+
208+ tlsCiphers = properties .getProperty (TLS_CIPHERS , tlsCiphers );
209+ tlsProtocols = properties .getProperty (TLS_PROTOCOLS , tlsProtocols );
195210 }
196211
197212 private static void logTheFinalUsedTlsConfig () {
@@ -207,6 +222,9 @@ private static void logTheFinalUsedTlsConfig() {
207222 LOGGER .debug ("{} = {}" , TLS_CLIENT_CERTPATH , tlsClientCertPath );
208223 LOGGER .debug ("{} = {}" , TLS_CLIENT_AUTHSERVER , tlsClientAuthServer );
209224 LOGGER .debug ("{} = {}" , TLS_CLIENT_TRUSTCERTPATH , tlsClientTrustCertPath );
225+
226+ LOGGER .debug ("{} = {}" , TLS_CIPHERS , tlsCiphers );
227+ LOGGER .debug ("{} = {}" , TLS_PROTOCOLS , tlsProtocols );
210228 }
211229
212230 private static ClientAuth parseClientAuthMode (String authMode ) {
0 commit comments