diff --git a/httpcore5/src/main/java/org/apache/hc/core5/ssl/SSLContexts.java b/httpcore5/src/main/java/org/apache/hc/core5/ssl/SSLContexts.java index 213026b3b2..3fca5b9116 100644 --- a/httpcore5/src/main/java/org/apache/hc/core5/ssl/SSLContexts.java +++ b/httpcore5/src/main/java/org/apache/hc/core5/ssl/SSLContexts.java @@ -27,7 +27,6 @@ package org.apache.hc.core5.ssl; -import java.security.KeyManagementException; import java.security.NoSuchAlgorithmException; import javax.net.ssl.SSLContext; @@ -41,7 +40,7 @@ * SSLContext#init(KeyManager[], TrustManager[], SecureRandom)} * accepts multiple key and trust managers, however only only first matching type is ever used. * See for example: - * + * * SSLContext.html#init * * @since 4.4 @@ -53,40 +52,31 @@ private SSLContexts() { } /** - * Creates default factory based on the standard JSSE trust material - * ({@code cacerts} file in the security properties directory). System properties - * are not taken into consideration. + * Returns the JDK default {@link SSLContext}. * - * @return the default SSL socket factory - * @throws SSLInitializationException if NoSuchAlgorithmException or KeyManagementException - * are thrown when invoking {@link SSLContext#getInstance(String)} + * @return the default JDK SSL context + * @throws SSLInitializationException if NoSuchAlgorithmException + * is thrown when invoking {@link SSLContext#getInstance(String)} */ public static SSLContext createDefault() throws SSLInitializationException { try { - final SSLContext sslContext = SSLContext.getInstance(SSLContextBuilder.TLS); - sslContext.init(null, null, null); - return sslContext; - } catch (final NoSuchAlgorithmException | KeyManagementException ex) { - throw new SSLInitializationException(ex.getMessage(), ex); + return SSLContext.getDefault(); + } catch (final NoSuchAlgorithmException ex) { + return createDefault(); } } /** - * Creates default SSL context based on system properties. This method obtains - * default SSL context by calling {@code SSLContext.getInstance("Default")}. - * Please note that {@code Default} algorithm is supported as of Java 6. - * This method will fall back onto {@link #createDefault()} when - * {@code Default} algorithm is not available. + * Deprecated alias for {@link #createDefault()}. * - * @return default system SSL context - * @throws SSLInitializationException if {@link #createDefault()} throws it + * @return the default JDK SSL context + * @throws SSLInitializationException if NoSuchAlgorithmException + * is thrown when invoking {@link SSLContext#getInstance(String)} + * @deprecated Call {@link #createDefault} instead */ + @Deprecated public static SSLContext createSystemDefault() throws SSLInitializationException { - try { - return SSLContext.getDefault(); - } catch (final NoSuchAlgorithmException ex) { - return createDefault(); - } + return createDefault(); } /** diff --git a/httpcore5/src/test/java/org/apache/hc/core5/ssl/SSLContextsTest.java b/httpcore5/src/test/java/org/apache/hc/core5/ssl/SSLContextsTest.java index 6862ea97d2..d37ae1d3d0 100644 --- a/httpcore5/src/test/java/org/apache/hc/core5/ssl/SSLContextsTest.java +++ b/httpcore5/src/test/java/org/apache/hc/core5/ssl/SSLContextsTest.java @@ -50,7 +50,7 @@ void createDefault() { final SSLContext sslContext = SSLContexts.createDefault(); assertAll( () -> assertNotNull(sslContext), - () -> assertEquals(SSLContextBuilder.TLS, sslContext.getProtocol()), + () -> assertEquals("Default", sslContext.getProtocol()), () -> assertNotNull(sslContext.getProvider()) ); } @@ -85,4 +85,4 @@ void custom() throws NoSuchAlgorithmException, KeyStoreException, UnrecoverableK () -> assertEquals("SunJSSE", sslContext.getProvider().getName()) ); } -} \ No newline at end of file +}