Skip to content

Commit d59fd20

Browse files
committed
Have an option for disabling HTTPS Algorithm on SSLEngine, close AsyncHttpClient#1313
1 parent 5c05d9d commit d59fd20

File tree

5 files changed

+31
-6
lines changed

5 files changed

+31
-6
lines changed

client/src/main/java/org/asynchttpclient/AsyncHttpClientConfig.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,6 @@ public interface AsyncHttpClientConfig {
202202
boolean isStrict302Handling();
203203

204204
/**
205-
* Return the maximum time in millisecond an {@link AsyncHttpClient} will keep connection in the pool, or -1 to keep connection while possible.
206-
*
207205
* @return the maximum time in millisecond an {@link AsyncHttpClient} will keep connection in the pool, or -1 to keep connection while possible.
208206
*/
209207
int getConnectionTtl();
@@ -212,6 +210,11 @@ public interface AsyncHttpClientConfig {
212210

213211
boolean isUseInsecureTrustManager();
214212

213+
/**
214+
* @return true to disable all HTTPS behaviors AT ONCE, such as hostname verification and SNI
215+
*/
216+
boolean isDisableHttpsAlgorithm();
217+
215218
/**
216219
* @return the array of enabled protocols
217220
*/

client/src/main/java/org/asynchttpclient/DefaultAsyncHttpClientConfig.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ public class DefaultAsyncHttpClientConfig implements AsyncHttpClientConfig {
9696
// ssl
9797
private final boolean useOpenSsl;
9898
private final boolean useInsecureTrustManager;
99+
private final boolean disableHttpsAlgorithm;
99100
private final int handshakeTimeout;
100101
private final String[] enabledProtocols;
101102
private final String[] enabledCipherSuites;
@@ -168,6 +169,7 @@ private DefaultAsyncHttpClientConfig(//
168169
// ssl
169170
boolean useOpenSsl,//
170171
boolean useInsecureTrustManager,//
172+
boolean disableHttpsAlgorithm,//
171173
int handshakeTimeout,//
172174
String[] enabledProtocols,//
173175
String[] enabledCipherSuites,//
@@ -241,6 +243,7 @@ private DefaultAsyncHttpClientConfig(//
241243
// ssl
242244
this.useOpenSsl = useOpenSsl;
243245
this.useInsecureTrustManager = useInsecureTrustManager;
246+
this.disableHttpsAlgorithm = disableHttpsAlgorithm;
244247
this.handshakeTimeout = handshakeTimeout;
245248
this.enabledProtocols = enabledProtocols;
246249
this.enabledCipherSuites = enabledCipherSuites;
@@ -426,6 +429,11 @@ public boolean isUseInsecureTrustManager() {
426429
return useInsecureTrustManager;
427430
}
428431

432+
@Override
433+
public boolean isDisableHttpsAlgorithm() {
434+
return disableHttpsAlgorithm;
435+
}
436+
429437
@Override
430438
public int getHandshakeTimeout() {
431439
return handshakeTimeout;
@@ -630,6 +638,7 @@ public static class Builder {
630638
// ssl
631639
private boolean useOpenSsl = defaultUseOpenSsl();
632640
private boolean useInsecureTrustManager = defaultUseInsecureTrustManager();
641+
private boolean disableHttpsAlgorithm = defaultDisableHttpsAlgorithm();
633642
private int handshakeTimeout = defaultHandshakeTimeout();
634643
private String[] enabledProtocols = defaultEnabledProtocols();
635644
private String[] enabledCipherSuites = defaultEnabledCipherSuites();
@@ -902,6 +911,11 @@ public Builder setUseInsecureTrustManager(boolean useInsecureTrustManager) {
902911
return this;
903912
}
904913

914+
public Builder setDisableHttpsAlgorithm(boolean disableHttpsAlgorithm) {
915+
this.useInsecureTrustManager = disableHttpsAlgorithm;
916+
return this;
917+
}
918+
905919
public Builder setHandshakeTimeout(int handshakeTimeout) {
906920
this.handshakeTimeout = handshakeTimeout;
907921
return this;
@@ -1124,6 +1138,7 @@ public DefaultAsyncHttpClientConfig build() {
11241138
keepAliveStrategy, //
11251139
useOpenSsl, //
11261140
useInsecureTrustManager, //
1141+
disableHttpsAlgorithm, //
11271142
handshakeTimeout, //
11281143
enabledProtocols, //
11291144
enabledCipherSuites, //

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public static String defaultUserAgent() {
7979
public static String[] defaultEnabledProtocols() {
8080
return AsyncHttpClientConfigHelper.getAsyncHttpClientConfig().getStringArray(ASYNC_CLIENT_CONFIG_ROOT + "enabledProtocols");
8181
}
82-
82+
8383
public static String[] defaultEnabledCipherSuites() {
8484
String[] defaultEnabledCipherSuites = AsyncHttpClientConfigHelper.getAsyncHttpClientConfig().getStringArray(ASYNC_CLIENT_CONFIG_ROOT + "enabledCipherSuites");
8585
Set<String> supportedCipherSuites = NettySslPackageAccessor.jdkSupportedCipherSuites();
@@ -122,6 +122,10 @@ public static boolean defaultUseInsecureTrustManager() {
122122
return AsyncHttpClientConfigHelper.getAsyncHttpClientConfig().getBoolean(ASYNC_CLIENT_CONFIG_ROOT + "useInsecureTrustManager");
123123
}
124124

125+
public static boolean defaultDisableHttpsAlgorithm() {
126+
return AsyncHttpClientConfigHelper.getAsyncHttpClientConfig().getBoolean(ASYNC_CLIENT_CONFIG_ROOT + "disableHttpsAlgorithm");
127+
}
128+
125129
public static int defaultSslSessionCacheSize() {
126130
return AsyncHttpClientConfigHelper.getAsyncHttpClientConfig().getInt(ASYNC_CLIENT_CONFIG_ROOT + "sslSessionCacheSize");
127131
}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ public abstract class SslEngineFactoryBase implements SslEngineFactory {
2525

2626
protected void configureSslEngine(SSLEngine sslEngine, AsyncHttpClientConfig config) {
2727
sslEngine.setUseClientMode(true);
28-
SSLParameters params = sslEngine.getSSLParameters();
29-
params.setEndpointIdentificationAlgorithm("HTTPS");
30-
sslEngine.setSSLParameters(params);
28+
if (!config.isDisableHttpsAlgorithm()) {
29+
SSLParameters params = sslEngine.getSSLParameters();
30+
params.setEndpointIdentificationAlgorithm("HTTPS");
31+
sslEngine.setSSLParameters(params);
32+
}
3133

3234
if (isNonEmpty(config.getEnabledProtocols()))
3335
sslEngine.setEnabledProtocols(config.getEnabledProtocols());

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ org.asynchttpclient.disableUrlEncodingForBoundRequests=false
2323
org.asynchttpclient.removeQueryParamOnRedirect=true
2424
org.asynchttpclient.useOpenSsl=false
2525
org.asynchttpclient.useInsecureTrustManager=false
26+
org.asynchttpclient.disableHttpsAlgorithm=false
2627
org.asynchttpclient.sslSessionCacheSize=0
2728
org.asynchttpclient.sslSessionTimeout=0
2829
org.asynchttpclient.tcpNoDelay=true

0 commit comments

Comments
 (0)