@@ -163,28 +163,16 @@ public void testThatCustomTruststoreCanBeSpecified() throws Exception {
163163 .build ();
164164
165165 SslConfiguration configuration = SslSettingsLoader .load (customTruststoreSettings , null , env );
166- SSLEngine sslEngineWithTruststore = sslService .createSSLEngine (configuration , null , -1 );
166+ SslProfile profile = sslService .profile ("transport.profiles.foo.xpack.security.ssl" );
167+ assertThat (profile .configuration (), equalTo (configuration ));
168+ assertThat (profile .configuration ().getDependentFiles (), contains (testClientStore ));
169+ SSLEngine sslEngineWithTruststore = profile .engine (null , -1 );
167170 assertThat (sslEngineWithTruststore , is (not (nullValue ())));
168171
169- SslConfiguration defaultConfig = sslService .getSSLConfiguration ("xpack.security.transport.ssl" );
170- SSLEngine sslEngine = sslService . createSSLEngine ( defaultConfig , null , -1 );
172+ SslProfile defaultProfile = sslService .profile ("xpack.security.transport.ssl" );
173+ SSLEngine sslEngine = defaultProfile . engine ( null , -1 );
171174 assertThat (sslEngineWithTruststore , is (not (sameInstance (sslEngine ))));
172-
173- final SslConfiguration profileConfiguration = sslService .getSSLConfiguration ("transport.profiles.foo.xpack.security.ssl" );
174- assertThat (profileConfiguration , notNullValue ());
175- assertThat (profileConfiguration .getDependentFiles (), contains (testClientStore ));
176-
177- final SslProfile defaultSslProfile = sslService .profile (
178- randomFrom ("xpack.security.transport.ssl" , "xpack.security.transport.ssl." )
179- );
180- assertThat (defaultSslProfile , notNullValue ());
181- assertThat (defaultSslProfile .configuration ().trustConfig ().getDependentFiles (), containsInAnyOrder (testnodeStore ));
182-
183- final SslProfile fooSslProfile = sslService .profile (
184- randomFrom ("transport.profiles.foo.xpack.security.ssl" , "transport.profiles.foo.xpack.security.ssl." )
185- );
186- assertThat (fooSslProfile , notNullValue ());
187- assertThat (fooSslProfile .configuration ().trustConfig ().getDependentFiles (), containsInAnyOrder (testClientStore ));
175+ assertThat (defaultProfile .configuration ().getDependentFiles (), contains (testnodeStore ));
188176 }
189177
190178 public void testThatSslContextCachingWorks () throws Exception {
@@ -230,10 +218,7 @@ public void testThatKeyStoreAndKeyCanHaveDifferentPasswords() throws Exception {
230218 .build ();
231219
232220 final SSLService sslService = new SSLService (TestEnvironment .newEnvironment (buildEnvSettings (settings )));
233- SslConfiguration configuration = sslService .getSSLConfiguration ("xpack.security.transport.ssl" );
234- sslService .createSSLEngine (configuration , null , -1 );
235-
236- final SslProfile profile = sslService .profile ("xpack.security.transport.ssl." );
221+ final SslProfile profile = sslService .profile ("xpack.security.transport.ssl" );
237222 profile .engine (null , -1 );
238223 }
239224
@@ -250,8 +235,8 @@ public void testIncorrectKeyPasswordThrowsException() throws Exception {
250235 .setSecureSettings (secureSettings )
251236 .build ();
252237 final SSLService sslService = new SSLService (TestEnvironment .newEnvironment (buildEnvSettings (settings )));
253- SslConfiguration configuration = sslService .getSSLConfiguration ("xpack.security.transport.ssl" );
254- sslService . createSSLEngine ( configuration , null , -1 );
238+ SslProfile profile = sslService .profile ("xpack.security.transport.ssl" );
239+ profile . engine ( null , -1 );
255240 fail ("expected an exception" );
256241 } catch (ElasticsearchException e ) {
257242 assertThat (e , throwableWithMessage (startsWith ("failed to load SSL configuration [xpack.security.transport.ssl] - " )));
@@ -268,10 +253,7 @@ public void testThatSSLv3IsNotEnabled() throws Exception {
268253 .put ("xpack.security.transport.ssl.key" , testnodeKey )
269254 .setSecureSettings (secureSettings )
270255 .build ();
271- SSLService sslService = new SSLService (TestEnvironment .newEnvironment (buildEnvSettings (settings )));
272- SslConfiguration configuration = sslService .getSSLConfiguration ("xpack.security.transport.ssl" );
273- SSLEngine engine = sslService .createSSLEngine (configuration , null , -1 );
274- assertThat (Arrays .asList (engine .getEnabledProtocols ()), not (hasItem ("SSLv3" )));
256+ final SSLService sslService = new SSLService (TestEnvironment .newEnvironment (buildEnvSettings (settings )));
275257
276258 final SslProfile profile = sslService .profile ("xpack.security.transport.ssl." );
277259 final String [] profileProtocols = profile .engine (null , -1 ).getEnabledProtocols ();
@@ -281,11 +263,9 @@ public void testThatSSLv3IsNotEnabled() throws Exception {
281263
282264 public void testThatCreateClientSSLEngineWithoutAnySettingsWorks () throws Exception {
283265 SSLService sslService = new SSLService (env );
284- SslConfiguration configuration = sslService .getSSLConfiguration ("xpack.security.transport.ssl" );
285- SSLEngine sslEngine = sslService .createSSLEngine (configuration , null , -1 );
286- assertThat (sslEngine , notNullValue ());
287-
288- assertThat (sslService .profile ("xpack.security.transport.ssl." ).engine (null , -1 ), notNullValue ());
266+ final SslProfile profile = sslService .profile ("xpack.security.transport.ssl" );
267+ final SSLEngine engine = profile .engine (null , -1 );
268+ assertThat (engine , notNullValue ());
289269 }
290270
291271 public void testThatCreateSSLEngineWithOnlyTruststoreWorks () throws Exception {
@@ -297,8 +277,8 @@ public void testThatCreateSSLEngineWithOnlyTruststoreWorks() throws Exception {
297277 .setSecureSettings (secureSettings )
298278 .build ();
299279 SSLService sslService = new SSLService (TestEnvironment .newEnvironment (buildEnvSettings (settings )));
300- SslConfiguration configuration = sslService .getSSLConfiguration ("xpack.security.http.ssl" );
301- SSLEngine sslEngine = sslService . createSSLEngine ( configuration , null , -1 );
280+ SslProfile profile = sslService .profile ("xpack.security.http.ssl" );
281+ SSLEngine sslEngine = profile . engine ( null , -1 );
302282 assertThat (sslEngine , notNullValue ());
303283
304284 assertThat (sslService .profile ("xpack.security.http.ssl." ).engine (null , -1 ), notNullValue ());
@@ -496,16 +476,10 @@ public void testCiphersAndInvalidCiphersWork() throws Exception {
496476 .build ();
497477 SSLService sslService = new SSLService (TestEnvironment .newEnvironment (buildEnvSettings (settings )));
498478
499- final SslConfiguration configuration = sslService .getSSLConfiguration ("xpack.security.transport.ssl" );
500- SSLEngine engine = sslService .createSSLEngine (configuration , null , -1 );
501- assertThat (engine , is (notNullValue ()));
502- String [] enabledCiphers = engine .getEnabledCipherSuites ();
503- assertThat (Arrays .asList (enabledCiphers ), not (contains ("foo" , "bar" )));
504-
505- final SslProfile profile = sslService .profile ("xpack.security.transport.ssl." );
506- engine = profile .engine (null , -1 );
479+ final SslProfile profile = sslService .profile ("xpack.security.transport.ssl" );
480+ var engine = profile .engine (null , -1 );
507481 assertThat (engine , is (notNullValue ()));
508- enabledCiphers = engine .getEnabledCipherSuites ();
482+ var enabledCiphers = engine .getEnabledCipherSuites ();
509483 assertThat (Arrays .asList (enabledCiphers ), not (contains ("foo" , "bar" )));
510484 }
511485
@@ -544,13 +518,8 @@ public void testThatSSLEngineHasCipherSuitesOrderSet() throws Exception {
544518
545519 SSLService sslService = new SSLService (TestEnvironment .newEnvironment (buildEnvSettings (settings )));
546520
547- final SslConfiguration configuration = sslService .getSSLConfiguration ("xpack.security.transport.ssl" );
548- SSLEngine engine = sslService .createSSLEngine (configuration , null , -1 );
549- assertThat (engine , is (notNullValue ()));
550- assertTrue (engine .getSSLParameters ().getUseCipherSuitesOrder ());
551-
552- final SslProfile profile = sslService .profile ("xpack.security.transport.ssl." );
553- engine = profile .engine (null , -1 );
521+ final SslProfile profile = sslService .profile ("xpack.security.transport.ssl" );
522+ SSLEngine engine = profile .engine (null , -1 );
554523 assertThat (engine , is (notNullValue ()));
555524 assertTrue (engine .getSSLParameters ().getUseCipherSuitesOrder ());
556525 }
@@ -598,9 +567,10 @@ public void testThatSSLEngineHasProperCiphersAndProtocols() throws Exception {
598567 .put ("xpack.security.transport.ssl.key" , testnodeKey )
599568 .setSecureSettings (secureSettings )
600569 .build ();
601- SSLService sslService = new SSLService (TestEnvironment .newEnvironment (buildEnvSettings (settings )));
602- SslConfiguration configuration = sslService .getSSLConfiguration ("xpack.security.transport.ssl" );
603- SSLEngine engine = sslService .createSSLEngine (configuration , null , -1 );
570+ final SSLService sslService = new SSLService (TestEnvironment .newEnvironment (buildEnvSettings (settings )));
571+ final SslProfile profile = sslService .profile ("xpack.security.transport.ssl" );
572+ final SSLEngine engine = profile .engine (null , -1 );
573+ final SslConfiguration configuration = profile .configuration ();
604574 final String [] ciphers = sslService .supportedCiphers (engine .getSupportedCipherSuites (), configuration .getCipherSuites (), false );
605575 final String [] getSupportedProtocols = configuration .supportedProtocols ().toArray (Strings .EMPTY_ARRAY );
606576 assertThat (engine .getEnabledCipherSuites (), is (ciphers ));
0 commit comments