1818import java .io .IOException ;
1919import java .io .InputStream ;
2020import java .security .KeyStore ;
21+ import java .util .ArrayList ;
2122import java .util .Arrays ;
23+ import java .util .Collections ;
24+ import java .util .List ;
2225
2326import org .springframework .core .io .AbstractResource ;
2427import org .springframework .core .io .Resource ;
@@ -60,6 +63,10 @@ public class SslConfiguration {
6063
6164 private final KeyConfiguration keyConfiguration ;
6265
66+ private final List <String > enabledProtocols ;
67+
68+ private final List <String > enabledCipherSuites ;
69+
6370 /**
6471 * Create a new {@link SslConfiguration} with the default {@link KeyStore} type.
6572 * @param keyStore the key store resource, must not be {@literal null}.
@@ -96,14 +103,23 @@ public SslConfiguration(KeyStoreConfiguration keyStoreConfiguration,
96103 * Create a new {@link SslConfiguration}.
97104 * @param keyStoreConfiguration the key store configuration, must not be
98105 * {@literal null}.
99- * @param keyConfiguration the configuration for a specific key in
100- * {@code keyStoreConfiguration} to use.
101106 * @param trustStoreConfiguration the trust store configuration, must not be
102107 * {@literal null}.
103- * @since 2.2
108+ * @param enabledProtocols the enabled SSL protocols, elements must match protocol
109+ * version strings used by the enabled Java SSL provider. May be {@literal null} to
110+ * indicate the SSL socket factory should use a default list of enabled protocol
111+ * versions.
112+ * @param enabledCipherSuites the enabled SSL cipher suites, elements must match
113+ * cipher suite strings used by the enabled Java SSL provider. May be {@literal null}
114+ * to indicate the SSL socket factory should use a default list of enabled cipher
115+ * suites.
116+ * @since 2.4
117+ * @see sun.security.ssl.ProtocolVersion
118+ * @see sun.security.ssl.CipherSuite
104119 */
105120 public SslConfiguration (KeyStoreConfiguration keyStoreConfiguration , KeyConfiguration keyConfiguration ,
106- KeyStoreConfiguration trustStoreConfiguration ) {
121+ KeyStoreConfiguration trustStoreConfiguration , List <String > enabledProtocols ,
122+ List <String > enabledCipherSuites ) {
107123
108124 Assert .notNull (keyStoreConfiguration , "KeyStore configuration must not be null" );
109125 Assert .notNull (keyConfiguration , "KeyConfiguration must not be null" );
@@ -112,6 +128,50 @@ public SslConfiguration(KeyStoreConfiguration keyStoreConfiguration, KeyConfigur
112128 this .keyStoreConfiguration = keyStoreConfiguration ;
113129 this .keyConfiguration = keyConfiguration ;
114130 this .trustStoreConfiguration = trustStoreConfiguration ;
131+ this .enabledProtocols = enabledProtocols != null
132+ ? Collections .unmodifiableList (new ArrayList <>(enabledProtocols )) : null ;
133+ this .enabledCipherSuites = enabledCipherSuites != null
134+ ? Collections .unmodifiableList (new ArrayList <>(enabledCipherSuites )) : null ;
135+ }
136+
137+ /**
138+ * Create a new {@link SslConfiguration}.
139+ * @param keyStoreConfiguration the key store configuration, must not be
140+ * {@literal null}.
141+ * @param keyConfiguration the configuration for a specific key in
142+ * {@code keyStoreConfiguration} to use.
143+ * @param trustStoreConfiguration the trust store configuration, must not be
144+ * {@literal null}.
145+ * @since 2.2
146+ */
147+ public SslConfiguration (KeyStoreConfiguration keyStoreConfiguration , KeyConfiguration keyConfiguration ,
148+ KeyStoreConfiguration trustStoreConfiguration ) {
149+ this (keyStoreConfiguration , keyConfiguration , trustStoreConfiguration , null , null );
150+ }
151+
152+ /**
153+ * Create a new {@link SslConfiguration}.
154+ * @param keyStoreConfiguration the key store configuration, must not be
155+ * {@literal null}.
156+ * @param trustStoreConfiguration the trust store configuration, must not be
157+ * {@literal null}.
158+ * @param enabledProtocols the enabled SSL protocols, elements must match protocol
159+ * version strings used by the enabled Java SSL provider. May be {@literal null} to
160+ * indicate the SSL socket factory should use a default list of enabled protocol
161+ * versions.
162+ * @param enabledCipherSuites the enabled SSL cipher suites, elements must match
163+ * cipher suite strings used by the enabled Java SSL provider. May be {@literal null}
164+ * to indicate the SSL socket factory should use a default list of enabled cipher
165+ * suites.
166+ * @since 2.4
167+ * @see sun.security.ssl.ProtocolVersion
168+ * @see sun.security.ssl.CipherSuite
169+ */
170+ public SslConfiguration (KeyStoreConfiguration keyStoreConfiguration , KeyStoreConfiguration trustStoreConfiguration ,
171+ List <String > enabledProtocols , List <String > enabledCipherSuites ) {
172+
173+ this (keyStoreConfiguration , KeyConfiguration .unconfigured (), trustStoreConfiguration , enabledProtocols ,
174+ enabledCipherSuites );
115175 }
116176
117177 /**
@@ -299,6 +359,54 @@ public static SslConfiguration unconfigured() {
299359 return new SslConfiguration (KeyStoreConfiguration .unconfigured (), KeyStoreConfiguration .unconfigured ());
300360 }
301361
362+ /**
363+ * The list of SSL protocol versions that must be enabled. A value of {@literal null}
364+ * indicates that the SSL socket factory should use a default list of enabled protocol
365+ * versions.
366+ * @return the list of enabled SSL protocol versions.
367+ * @since 2.4
368+ */
369+ public List <String > getEnabledProtocols () {
370+ return this .enabledProtocols ;
371+ }
372+
373+ /**
374+ * Create a new {@link SslConfiguration} with the enabled protocol versions applied
375+ * retaining the other configuration from this instance.
376+ * @param enabledProtocols may be {@literal null}.
377+ * @return a new {@link SslConfiguration} with the enabled protocol versions applied.
378+ * @since 2.4
379+ * @see sun.security.ssl.ProtocolVersion
380+ */
381+ public SslConfiguration withEnabledProtocols (List <String > enabledProtocols ) {
382+ return new SslConfiguration (this .keyStoreConfiguration , this .keyConfiguration , this .trustStoreConfiguration ,
383+ enabledProtocols , this .enabledCipherSuites );
384+ }
385+
386+ /**
387+ * The list of SSL cipher suites that must be enabled. A value of {@literal null}
388+ * indicates that the SSL socket factory should use a default list of enabled cipher
389+ * suites.
390+ * @return the list of enabled SSL cipher suites.
391+ * @since 2.4
392+ */
393+ public List <String > getEnabledCipherSuites () {
394+ return this .enabledCipherSuites ;
395+ }
396+
397+ /**
398+ * Create a new {@link SslConfiguration} with the enabled cipher suites applied
399+ * retaining the other configuration from this instance.
400+ * @param enabledCipherSuites may be {@literal null}.
401+ * @return a new {@link SslConfiguration} with the enabled cipher suites applied.
402+ * @since 2.4
403+ * @see sun.security.ssl.CipherSuite
404+ */
405+ public SslConfiguration withEnabledCipherSuites (List <String > enabledCipherSuites ) {
406+ return new SslConfiguration (this .keyStoreConfiguration , this .keyConfiguration , this .trustStoreConfiguration ,
407+ this .enabledProtocols , enabledCipherSuites );
408+ }
409+
302410 /**
303411 * @return the {@link java.security.KeyStore key store} resource or {@literal null} if
304412 * not configured.
0 commit comments