2424import org .elasticsearch .common .io .stream .NamedWriteableRegistry ;
2525import org .elasticsearch .common .network .NetworkService ;
2626import org .elasticsearch .common .settings .Settings ;
27- import org .elasticsearch .common .ssl .SslConfiguration ;
2827import org .elasticsearch .common .unit .ByteSizeValue ;
2928import org .elasticsearch .common .util .PageCacheRecycler ;
3029import org .elasticsearch .common .util .concurrent .ThreadContext ;
4746import org .elasticsearch .xpack .core .security .transport .ProfileConfigurations ;
4847import org .elasticsearch .xpack .core .security .transport .SecurityTransportExceptionHandler ;
4948import org .elasticsearch .xpack .core .ssl .SSLService ;
49+ import org .elasticsearch .xpack .core .ssl .SslProfile ;
5050import org .elasticsearch .xpack .security .authc .CrossClusterAccessAuthenticationService ;
5151
5252import java .net .InetSocketAddress ;
@@ -73,11 +73,11 @@ public class SecurityNetty4Transport extends Netty4Transport {
7373
7474 private final SecurityTransportExceptionHandler exceptionHandler ;
7575 private final SSLService sslService ;
76- private final SslConfiguration defaultSslConfiguration ;
77- private final Map <String , SslConfiguration > profileConfigurations ;
76+ private final SslProfile defaultSslProfile ;
77+ private final Map <String , SslProfile > profiles ;
7878 private final boolean transportSslEnabled ;
7979 private final boolean remoteClusterServerSslEnabled ;
80- private final SslConfiguration remoteClusterClientSslConfiguration ;
80+ private final SslProfile remoteClusterClientSslProfile ;
8181 private final RemoteClusterClientBootstrapOptions remoteClusterClientBootstrapOptions ;
8282 private final CrossClusterAccessAuthenticationService crossClusterAccessAuthenticationService ;
8383
@@ -108,16 +108,16 @@ public SecurityNetty4Transport(
108108 this .sslService = sslService ;
109109 this .transportSslEnabled = XPackSettings .TRANSPORT_SSL_ENABLED .get (settings );
110110 this .remoteClusterServerSslEnabled = REMOTE_CLUSTER_SERVER_SSL_ENABLED .get (settings );
111- this .profileConfigurations = Collections .unmodifiableMap (ProfileConfigurations .get (settings , sslService , true ));
112- this .defaultSslConfiguration = this .profileConfigurations .get (TransportSettings .DEFAULT_PROFILE );
113- assert this .transportSslEnabled == false || this .defaultSslConfiguration != null ;
111+ this .profiles = Collections .unmodifiableMap (ProfileConfigurations .get (settings , sslService , true ));
112+ this .defaultSslProfile = this .profiles .get (TransportSettings .DEFAULT_PROFILE );
113+ assert this .transportSslEnabled == false || this .defaultSslProfile != null ;
114114
115115 // Client configuration does not depend on whether the remote access port is enabled
116116 if (REMOTE_CLUSTER_CLIENT_SSL_ENABLED .get (settings )) {
117- this .remoteClusterClientSslConfiguration = sslService .getSSLConfiguration (REMOTE_CLUSTER_CLIENT_SSL_PREFIX );
118- assert this .remoteClusterClientSslConfiguration != null ;
117+ this .remoteClusterClientSslProfile = sslService .profile (REMOTE_CLUSTER_CLIENT_SSL_PREFIX );
118+ assert this .remoteClusterClientSslProfile != null ;
119119 } else {
120- this .remoteClusterClientSslConfiguration = null ;
120+ this .remoteClusterClientSslProfile = null ;
121121 }
122122 this .remoteClusterClientBootstrapOptions = RemoteClusterClientBootstrapOptions .fromSettings (settings );
123123 }
@@ -131,20 +131,20 @@ protected void doStart() {
131131 public final ChannelHandler getServerChannelInitializer (String name ) {
132132 if (remoteClusterPortEnabled && REMOTE_CLUSTER_PROFILE .equals (name )) {
133133 if (remoteClusterServerSslEnabled ) {
134- final SslConfiguration remoteClusterSslConfiguration = profileConfigurations .get (name );
135- if (remoteClusterSslConfiguration == null ) {
134+ final SslProfile remoteClusterSslProfile = profiles .get (name );
135+ if (remoteClusterSslProfile == null ) {
136136 throw new IllegalStateException ("remote cluster SSL is enabled but no configuration is found" );
137137 }
138- return getSslChannelInitializer (name , remoteClusterSslConfiguration );
138+ return getSslChannelInitializer (name , remoteClusterSslProfile );
139139 } else {
140140 return getNoSslChannelInitializer (name );
141141 }
142142 } else if (transportSslEnabled ) {
143- SslConfiguration configuration = profileConfigurations .get (name );
144- if (configuration == null ) {
143+ SslProfile profile = profiles .get (name );
144+ if (profile == null ) {
145145 throw new IllegalStateException ("unknown profile: " + name );
146146 }
147- return getSslChannelInitializer (name , configuration );
147+ return getSslChannelInitializer (name , profile );
148148 } else {
149149 return getNoSslChannelInitializer (name );
150150 }
@@ -228,27 +228,27 @@ public void onException(TcpChannel channel, Exception e) {
228228 }
229229
230230 public class SslChannelInitializer extends ServerChannelInitializer {
231- private final SslConfiguration configuration ;
231+ private final SslProfile profile ;
232232
233- public SslChannelInitializer (String name , SslConfiguration configuration ) {
233+ public SslChannelInitializer (String name , SslProfile profile ) {
234234 super (name );
235- this .configuration = configuration ;
235+ this .profile = profile ;
236236 }
237237
238238 @ Override
239239 protected void initChannel (Channel ch ) throws Exception {
240- SSLEngine serverEngine = sslService . createSSLEngine ( configuration , null , -1 );
240+ SSLEngine serverEngine = profile . engine ( null , -1 );
241241 serverEngine .setUseClientMode (false );
242242 final SslHandler sslHandler = new SslHandler (serverEngine );
243- sslHandler .setHandshakeTimeoutMillis (configuration .handshakeTimeoutMillis ());
243+ sslHandler .setHandshakeTimeoutMillis (profile . configuration () .handshakeTimeoutMillis ());
244244 ch .pipeline ().addFirst ("sslhandler" , sslHandler );
245245 super .initChannel (ch );
246246 assert ch .pipeline ().first () == sslHandler : "SSL handler must be first handler in pipeline" ;
247247 }
248248 }
249249
250- protected ServerChannelInitializer getSslChannelInitializer (final String name , final SslConfiguration configuration ) {
251- return new SslChannelInitializer (name , configuration );
250+ protected ServerChannelInitializer getSslChannelInitializer (final String name , final SslProfile profile ) {
251+ return new SslChannelInitializer (name , profile );
252252 }
253253
254254 @ Override
@@ -260,21 +260,23 @@ private class SecurityClientChannelInitializer extends ClientChannelInitializer
260260
261261 private final boolean hostnameVerificationEnabled ;
262262 private final SNIHostName serverName ;
263- private final SslConfiguration channelSslConfiguration ;
263+ private final SslProfile channelSslProfile ;
264264
265265 SecurityClientChannelInitializer (DiscoveryNode node , ConnectionProfile connectionProfile ) {
266266 final String transportProfile = connectionProfile .getTransportProfile ();
267267 logger .trace ("initiating security client channel with transport profile [{}]" , transportProfile );
268268 // Only client connections to a new RCS remote cluster can have transport profile of _remote_cluster
269269 // All other client connections use the default transport profile regardless of the transport profile used on the server side.
270270 if (REMOTE_CLUSTER_PROFILE .equals (transportProfile )) {
271- this .channelSslConfiguration = remoteClusterClientSslConfiguration ;
271+ this .channelSslProfile = remoteClusterClientSslProfile ;
272272 } else {
273273 assert TransportSettings .DEFAULT_PROFILE .equals (transportProfile );
274- this .channelSslConfiguration = defaultSslConfiguration ;
274+ this .channelSslProfile = defaultSslProfile ;
275275 }
276- if (this .channelSslConfiguration != null ) {
277- this .hostnameVerificationEnabled = this .channelSslConfiguration .verificationMode ().isHostnameVerificationEnabled ();
276+ if (this .channelSslProfile != null ) {
277+ this .hostnameVerificationEnabled = this .channelSslProfile .configuration ()
278+ .verificationMode ()
279+ .isHostnameVerificationEnabled ();
278280 } else {
279281 this .hostnameVerificationEnabled = false ;
280282 }
@@ -293,29 +295,27 @@ private class SecurityClientChannelInitializer extends ClientChannelInitializer
293295 @ Override
294296 protected void initChannel (Channel ch ) throws Exception {
295297 super .initChannel (ch );
296- if (channelSslConfiguration != null ) {
298+ if (channelSslProfile != null ) {
297299 ch .pipeline ()
298- .addFirst (
299- new ClientSslHandlerInitializer (channelSslConfiguration , sslService , hostnameVerificationEnabled , serverName )
300- );
300+ .addFirst (new ClientSslHandlerInitializer (channelSslProfile , sslService , hostnameVerificationEnabled , serverName ));
301301 }
302302 }
303303 }
304304
305305 private static class ClientSslHandlerInitializer extends ChannelOutboundHandlerAdapter {
306306
307307 private final boolean hostnameVerificationEnabled ;
308- private final SslConfiguration sslConfiguration ;
308+ private final SslProfile sslProfile ;
309309 private final SSLService sslService ;
310310 private final SNIServerName serverName ;
311311
312312 private ClientSslHandlerInitializer (
313- SslConfiguration sslConfiguration ,
313+ SslProfile sslProfile ,
314314 SSLService sslService ,
315315 boolean hostnameVerificationEnabled ,
316316 SNIServerName serverName
317317 ) {
318- this .sslConfiguration = sslConfiguration ;
318+ this .sslProfile = sslProfile ;
319319 this .hostnameVerificationEnabled = hostnameVerificationEnabled ;
320320 this .sslService = sslService ;
321321 this .serverName = serverName ;
@@ -328,9 +328,9 @@ public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, Sock
328328 if (hostnameVerificationEnabled ) {
329329 InetSocketAddress inetSocketAddress = (InetSocketAddress ) remoteAddress ;
330330 // we create the socket based on the name given. don't reverse DNS
331- sslEngine = sslService . createSSLEngine ( sslConfiguration , inetSocketAddress .getHostString (), inetSocketAddress .getPort ());
331+ sslEngine = sslProfile . engine ( inetSocketAddress .getHostString (), inetSocketAddress .getPort ());
332332 } else {
333- sslEngine = sslService . createSSLEngine ( sslConfiguration , null , -1 );
333+ sslEngine = sslProfile . engine ( null , -1 );
334334 }
335335
336336 sslEngine .setUseClientMode (true );
@@ -341,7 +341,7 @@ public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, Sock
341341 }
342342 final ChannelPromise connectPromise = ctx .newPromise ();
343343 final SslHandler sslHandler = new SslHandler (sslEngine );
344- sslHandler .setHandshakeTimeoutMillis (sslConfiguration .handshakeTimeoutMillis ());
344+ sslHandler .setHandshakeTimeoutMillis (sslProfile . configuration () .handshakeTimeoutMillis ());
345345 ctx .pipeline ().replace (this , "ssl" , sslHandler );
346346 final Future <?> handshakePromise = sslHandler .handshakeFuture ();
347347 Netty4Utils .addListener (connectPromise , result -> {
0 commit comments