Skip to content

Commit 78a64f4

Browse files
committed
Drop NettySslPackageAccessor, close AsyncHttpClient#1382
Motivation: * mess up with provided SslContext * crash when netty and ahc are in different classloaders Modifications: * Drop NettySslPackageAccessor * Revert to empty conf to use Netty default behavior (only Netty recommended ciphers are available by default) Result: Don’t override provided SslContext behavior. No more crash when netty and ahc sits in different classloaders
1 parent cec67cf commit 78a64f4

File tree

6 files changed

+24
-46
lines changed

6 files changed

+24
-46
lines changed

client/src/main/java/io/netty/handler/ssl/NettySslPackageAccessor.java

Lines changed: 0 additions & 26 deletions
This file was deleted.

client/src/main/java/org/asynchttpclient/config/AsyncHttpClientConfigDefaults.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@
1212
*/
1313
package org.asynchttpclient.config;
1414

15-
import io.netty.handler.ssl.NettySslPackageAccessor;
16-
17-
import java.util.Arrays;
18-
import java.util.Set;
1915

2016
public final class AsyncHttpClientConfigDefaults {
2117

@@ -81,9 +77,7 @@ public static String[] defaultEnabledProtocols() {
8177
}
8278

8379
public static String[] defaultEnabledCipherSuites() {
84-
String[] defaultEnabledCipherSuites = AsyncHttpClientConfigHelper.getAsyncHttpClientConfig().getStringArray(ASYNC_CLIENT_CONFIG_ROOT + "enabledCipherSuites");
85-
Set<String> supportedCipherSuites = NettySslPackageAccessor.jdkSupportedCipherSuites();
86-
return Arrays.stream(defaultEnabledCipherSuites).filter(supportedCipherSuites::contains).toArray(String[]::new);
80+
return AsyncHttpClientConfigHelper.getAsyncHttpClientConfig().getStringArray(ASYNC_CLIENT_CONFIG_ROOT + "enabledCipherSuites");
8781
}
8882

8983
public static boolean defaultUseProxySelector() {

client/src/main/java/org/asynchttpclient/config/AsyncHttpClientConfigHelper.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ public String getString(String key) {
9494

9595
public String[] getStringArray(String key) {
9696
String s = getString(key);
97+
s = s.trim();
98+
if (s.isEmpty()) {
99+
return null;
100+
}
97101
String[] rawArray = s.split(",");
98102
String[] array = new String[rawArray.length];
99103
for (int i = 0; i < rawArray.length; i++)

client/src/main/java/org/asynchttpclient/netty/ssl/DefaultSslEngineFactory.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@
1313
*/
1414
package org.asynchttpclient.netty.ssl;
1515

16+
import static org.asynchttpclient.util.MiscUtils.*;
17+
1618
import io.netty.buffer.ByteBufAllocator;
1719
import io.netty.handler.ssl.SslContext;
1820
import io.netty.handler.ssl.SslContextBuilder;
1921
import io.netty.handler.ssl.SslProvider;
2022

23+
import java.util.Arrays;
24+
2125
import javax.net.ssl.SSLEngine;
2226
import javax.net.ssl.SSLException;
2327

@@ -28,16 +32,26 @@ public class DefaultSslEngineFactory extends SslEngineFactoryBase {
2832
private volatile SslContext sslContext;
2933

3034
private SslContext buildSslContext(AsyncHttpClientConfig config) throws SSLException {
31-
if (config.getSslContext() != null)
35+
if (config.getSslContext() != null) {
3236
return config.getSslContext();
37+
}
3338

3439
SslContextBuilder sslContextBuilder = SslContextBuilder.forClient()//
3540
.sslProvider(config.isUseOpenSsl() ? SslProvider.OPENSSL : SslProvider.JDK)//
3641
.sessionCacheSize(config.getSslSessionCacheSize())//
3742
.sessionTimeout(config.getSslSessionTimeout());
3843

39-
if (config.isAcceptAnyCertificate())
44+
if (isNonEmpty(config.getEnabledProtocols())) {
45+
sslContextBuilder.protocols(config.getEnabledProtocols());
46+
}
47+
48+
if (isNonEmpty(config.getEnabledCipherSuites())) {
49+
sslContextBuilder.ciphers(Arrays.asList(config.getEnabledCipherSuites()));
50+
}
51+
52+
if (config.isAcceptAnyCertificate()) {
4053
sslContextBuilder.trustManager(InsecureTrustManagerFactory.INSTANCE);
54+
}
4155

4256
return configureSslContextBuilder(sslContextBuilder).build();
4357
}
@@ -56,8 +70,8 @@ public void init(AsyncHttpClientConfig config) throws SSLException {
5670
}
5771

5872
/**
59-
* The last step of configuring the SslContextBuilder used to create an SslContext when no context is provided in
60-
* the {@link AsyncHttpClientConfig}. This defaults to no-op and is intended to be overridden as needed.
73+
* The last step of configuring the SslContextBuilder used to create an SslContext when no context is provided in the {@link AsyncHttpClientConfig}. This defaults to no-op and
74+
* is intended to be overridden as needed.
6175
*
6276
* @param builder builder with normal configuration applied
6377
* @return builder to be used to build context (can be the same object as the input)

client/src/main/java/org/asynchttpclient/netty/ssl/SslEngineFactoryBase.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
*/
1414
package org.asynchttpclient.netty.ssl;
1515

16-
import static org.asynchttpclient.util.MiscUtils.isNonEmpty;
17-
1816
import javax.net.ssl.SSLEngine;
1917
import javax.net.ssl.SSLParameters;
2018

@@ -28,11 +26,5 @@ protected void configureSslEngine(SSLEngine sslEngine, AsyncHttpClientConfig con
2826
SSLParameters params = sslEngine.getSSLParameters();
2927
params.setEndpointIdentificationAlgorithm("HTTPS");
3028
sslEngine.setSSLParameters(params);
31-
32-
if (isNonEmpty(config.getEnabledProtocols()))
33-
sslEngine.setEnabledProtocols(config.getEnabledProtocols());
34-
35-
if (isNonEmpty(config.getEnabledCipherSuites()))
36-
sslEngine.setEnabledCipherSuites(config.getEnabledCipherSuites());
3729
}
3830
}

client/src/main/resources/ahc-default.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ org.asynchttpclient.maxRedirects=5
1212
org.asynchttpclient.compressionEnforced=false
1313
org.asynchttpclient.userAgent=AHC/2.0
1414
org.asynchttpclient.enabledProtocols=TLSv1.2, TLSv1.1, TLSv1
15-
org.asynchttpclient.enabledCipherSuites=TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,TLS_RSA_WITH_AES_128_GCM_SHA256,TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA
15+
org.asynchttpclient.enabledCipherSuites=
1616
org.asynchttpclient.useProxySelector=false
1717
org.asynchttpclient.useProxyProperties=false
1818
org.asynchttpclient.validateResponseHeaders=true

0 commit comments

Comments
 (0)