@@ -51,7 +51,6 @@ public abstract class JdkSslContext extends SslContext {
5151
5252 static {
5353 SSLContext context ;
54- int i ;
5554 try {
5655 context = SSLContext .getInstance (PROTOCOL );
5756 context .init (null , null , null );
@@ -63,12 +62,11 @@ public abstract class JdkSslContext extends SslContext {
6362
6463 // Choose the sensible default list of protocols.
6564 final String [] supportedProtocols = engine .getSupportedProtocols ();
66- Set <String > supportedProtocolsSet = new HashSet <String >(supportedProtocols .length );
67- for (i = 0 ; i < supportedProtocols .length ; ++i ) {
68- supportedProtocolsSet .add (supportedProtocols [i ]);
69- }
70- List <String > protocols = new ArrayList <String >();
71- addIfSupported (supportedProtocolsSet , protocols , "TLSv1.2" , "TLSv1.1" , "TLSv1" );
65+ Set <String > supportedProtocolsSet = new HashSet <>(Arrays .asList (supportedProtocols ));
66+ List <String > protocols = new ArrayList <>();
67+
68+ // Modernized for Java 21: prioritize TLS 1.3 and TLS 1.2
69+ addIfSupported (supportedProtocolsSet , protocols , "TLSv1.3" , "TLSv1.2" );
7270
7371 if (!protocols .isEmpty ()) {
7472 PROTOCOLS = protocols .toArray (new String [0 ]);
@@ -78,26 +76,26 @@ public abstract class JdkSslContext extends SslContext {
7876
7977 // Choose the sensible default list of cipher suites.
8078 final String [] supportedCiphers = engine .getSupportedCipherSuites ();
81- SUPPORTED_CIPHERS = new HashSet <String >(supportedCiphers .length );
82- for (i = 0 ; i < supportedCiphers .length ; ++i ) {
83- SUPPORTED_CIPHERS .add (supportedCiphers [i ]);
84- }
85- List <String > ciphers = new ArrayList <String >();
79+ SUPPORTED_CIPHERS = new HashSet <>(Arrays .asList (supportedCiphers ));
80+ List <String > ciphers = new ArrayList <>();
81+
8682 addIfSupported (
8783 SUPPORTED_CIPHERS ,
8884 ciphers ,
89- // XXX: Make sure to sync this list with OpenSslEngineFactory.
90- // GCM (Galois/Counter Mode) requires JDK 8.
85+ // TLS 1.3 Ciphers
86+ "TLS_AES_256_GCM_SHA384" ,
87+ "TLS_AES_128_GCM_SHA256" ,
88+ "TLS_CHACHA20_POLY1305_SHA256" ,
89+ // Modern TLS 1.2 Ciphers
90+ "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384" ,
91+ "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384" ,
92+ "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256" ,
9193 "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256" ,
9294 "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA" ,
93- // AES256 requires JCE unlimited strength jurisdiction policy files.
9495 "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA" ,
95- // GCM (Galois/Counter Mode) requires JDK 8.
9696 "TLS_RSA_WITH_AES_128_GCM_SHA256" ,
9797 "TLS_RSA_WITH_AES_128_CBC_SHA" ,
98- // AES256 requires JCE unlimited strength jurisdiction policy files.
99- "TLS_RSA_WITH_AES_256_CBC_SHA" ,
100- "SSL_RSA_WITH_3DES_EDE_CBC_SHA" );
98+ "TLS_RSA_WITH_AES_256_CBC_SHA" );
10199
102100 if (ciphers .isEmpty ()) {
103101 // Use the default from JDK as fallback.
@@ -125,7 +123,6 @@ private static void addIfSupported(
125123 }
126124 }
127125
128- /** Returns the JDK {@link SSLSessionContext} object held by this context. */
129126 @ Override
130127 public final SSLSessionContext sessionContext () {
131128 return context ().getServerSessionContext ();
@@ -141,18 +138,6 @@ public final long sessionTimeout() {
141138 return sessionContext ().getSessionTimeout ();
142139 }
143140
144- /**
145- * Build a {@link KeyManagerFactory} based upon a key file, key file password, and a certificate
146- * chain.
147- *
148- * @param certChainFile a X.509 certificate chain file in PEM format
149- * @param keyFile a PKCS#8 private key file in PEM format
150- * @param keyPassword the password of the {@code keyFile}. {@code null} if it's not
151- * password-protected.
152- * @param kmf The existing {@link KeyManagerFactory} that will be used if not {@code null}
153- * @return A {@link KeyManagerFactory} based upon a key file, key file password, and a certificate
154- * chain.
155- */
156141 protected static KeyManagerFactory buildKeyManagerFactory (
157142 final InputStream certChainFile , final InputStream keyFile , final String keyPassword )
158143 throws UnrecoverableKeyException ,
@@ -171,19 +156,6 @@ protected static KeyManagerFactory buildKeyManagerFactory(
171156 return buildKeyManagerFactory (certChainFile , algorithm , keyFile , keyPassword );
172157 }
173158
174- /**
175- * Build a {@link KeyManagerFactory} based upon a key algorithm, key file, key file password, and
176- * a certificate chain.
177- *
178- * @param certChainFile a X.509 certificate chain file in PEM format
179- * @param keyAlgorithm the standard name of the requested algorithm. See the Java Secure Socket
180- * Extension Reference Guide for information about standard algorithm names.
181- * @param keyFile a PKCS#8 private key file in PEM format
182- * @param keyPassword the password of the {@code keyFile}. {@code null} if it's not
183- * password-protected.
184- * @return A {@link KeyManagerFactory} based upon a key algorithm, key file, key file password,
185- * and a certificate chain.
186- */
187159 protected static KeyManagerFactory buildKeyManagerFactory (
188160 final InputStream certChainFile ,
189161 final String keyAlgorithm ,
0 commit comments