Skip to content

Commit 5c05d9d

Browse files
committed
Rename AcceptAnyCertificate config option into UseInsecureTrustManager, close AsyncHttpClient#1312
1 parent 2d8431d commit 5c05d9d

File tree

12 files changed

+28
-28
lines changed

12 files changed

+28
-28
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ public interface AsyncHttpClientConfig {
210210

211211
boolean isUseOpenSsl();
212212

213-
boolean isAcceptAnyCertificate();
213+
boolean isUseInsecureTrustManager();
214214

215215
/**
216216
* @return the array of enabled protocols

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public class DefaultAsyncHttpClientConfig implements AsyncHttpClientConfig {
9595

9696
// ssl
9797
private final boolean useOpenSsl;
98-
private final boolean acceptAnyCertificate;
98+
private final boolean useInsecureTrustManager;
9999
private final int handshakeTimeout;
100100
private final String[] enabledProtocols;
101101
private final String[] enabledCipherSuites;
@@ -167,7 +167,7 @@ private DefaultAsyncHttpClientConfig(//
167167

168168
// ssl
169169
boolean useOpenSsl,//
170-
boolean acceptAnyCertificate,//
170+
boolean useInsecureTrustManager,//
171171
int handshakeTimeout,//
172172
String[] enabledProtocols,//
173173
String[] enabledCipherSuites,//
@@ -240,7 +240,7 @@ private DefaultAsyncHttpClientConfig(//
240240

241241
// ssl
242242
this.useOpenSsl = useOpenSsl;
243-
this.acceptAnyCertificate = acceptAnyCertificate;
243+
this.useInsecureTrustManager = useInsecureTrustManager;
244244
this.handshakeTimeout = handshakeTimeout;
245245
this.enabledProtocols = enabledProtocols;
246246
this.enabledCipherSuites = enabledCipherSuites;
@@ -422,8 +422,8 @@ public boolean isUseOpenSsl() {
422422
}
423423

424424
@Override
425-
public boolean isAcceptAnyCertificate() {
426-
return acceptAnyCertificate;
425+
public boolean isUseInsecureTrustManager() {
426+
return useInsecureTrustManager;
427427
}
428428

429429
@Override
@@ -629,7 +629,7 @@ public static class Builder {
629629

630630
// ssl
631631
private boolean useOpenSsl = defaultUseOpenSsl();
632-
private boolean acceptAnyCertificate = defaultAcceptAnyCertificate();
632+
private boolean useInsecureTrustManager = defaultUseInsecureTrustManager();
633633
private int handshakeTimeout = defaultHandshakeTimeout();
634634
private String[] enabledProtocols = defaultEnabledProtocols();
635635
private String[] enabledCipherSuites = defaultEnabledCipherSuites();
@@ -703,7 +703,7 @@ public Builder(AsyncHttpClientConfig config) {
703703
keepAliveStrategy = config.getKeepAliveStrategy();
704704

705705
// ssl
706-
acceptAnyCertificate = config.isAcceptAnyCertificate();
706+
useInsecureTrustManager = config.isUseInsecureTrustManager();
707707
handshakeTimeout = config.getHandshakeTimeout();
708708
enabledProtocols = config.getEnabledProtocols();
709709
enabledCipherSuites = config.getEnabledCipherSuites();
@@ -897,8 +897,8 @@ public Builder setUseOpenSsl(boolean useOpenSsl) {
897897
return this;
898898
}
899899

900-
public Builder setAcceptAnyCertificate(boolean acceptAnyCertificate) {
901-
this.acceptAnyCertificate = acceptAnyCertificate;
900+
public Builder setUseInsecureTrustManager(boolean useInsecureTrustManager) {
901+
this.useInsecureTrustManager = useInsecureTrustManager;
902902
return this;
903903
}
904904

@@ -1123,7 +1123,7 @@ public DefaultAsyncHttpClientConfig build() {
11231123
channelPool, //
11241124
keepAliveStrategy, //
11251125
useOpenSsl, //
1126-
acceptAnyCertificate, //
1126+
useInsecureTrustManager, //
11271127
handshakeTimeout, //
11281128
enabledProtocols, //
11291129
enabledCipherSuites, //

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ public static boolean defaultUseOpenSsl() {
118118
return AsyncHttpClientConfigHelper.getAsyncHttpClientConfig().getBoolean(ASYNC_CLIENT_CONFIG_ROOT + "useOpenSsl");
119119
}
120120

121-
public static boolean defaultAcceptAnyCertificate() {
122-
return AsyncHttpClientConfigHelper.getAsyncHttpClientConfig().getBoolean(ASYNC_CLIENT_CONFIG_ROOT + "acceptAnyCertificate");
121+
public static boolean defaultUseInsecureTrustManager() {
122+
return AsyncHttpClientConfigHelper.getAsyncHttpClientConfig().getBoolean(ASYNC_CLIENT_CONFIG_ROOT + "useInsecureTrustManager");
123123
}
124124

125125
public static int defaultSslSessionCacheSize() {

client/src/main/java/org/asynchttpclient/netty/handler/WebSocketHandler.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ private void invokeOnSucces(Channel channel, WebSocketUpgradeHandler h) {
8484

8585
@Override
8686
public void call() throws Exception {
87-
8887
boolean validStatus = response.status().equals(SWITCHING_PROTOCOLS);
8988
boolean validUpgrade = response.headers().get(UPGRADE) != null;
9089
String connection = response.headers().get(CONNECTION);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ private SslContext buildSslContext(AsyncHttpClientConfig config) throws SSLExcep
3636
.sessionCacheSize(config.getSslSessionCacheSize())//
3737
.sessionTimeout(config.getSslSessionTimeout());
3838

39-
if (config.isAcceptAnyCertificate())
39+
if (config.isUseInsecureTrustManager()) {
4040
sslContextBuilder.trustManager(InsecureTrustManagerFactory.INSTANCE);
41+
}
4142

4243
return configureSslContextBuilder(sslContextBuilder).build();
4344
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ org.asynchttpclient.maxRequestRetry=5
2222
org.asynchttpclient.disableUrlEncodingForBoundRequests=false
2323
org.asynchttpclient.removeQueryParamOnRedirect=true
2424
org.asynchttpclient.useOpenSsl=false
25-
org.asynchttpclient.acceptAnyCertificate=false
25+
org.asynchttpclient.useInsecureTrustManager=false
2626
org.asynchttpclient.sslSessionCacheSize=0
2727
org.asynchttpclient.sslSessionTimeout=0
2828
org.asynchttpclient.tcpNoDelay=true

client/src/test/java/org/asynchttpclient/AsyncHttpClientDefaultsTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ public void testDefaultDisableUrlEncodingForBoundRequests() {
110110
testBooleanSystemProperty("disableUrlEncodingForBoundRequests", "defaultDisableUrlEncodingForBoundRequests", "true");
111111
}
112112

113-
public void testDefaultAcceptAnyCertificate() {
114-
Assert.assertFalse(AsyncHttpClientConfigDefaults.defaultAcceptAnyCertificate());
115-
testBooleanSystemProperty("acceptAnyCertificate", "defaultAcceptAnyCertificate", "true");
113+
public void testDefaultUseInsecureTrustManager() {
114+
Assert.assertFalse(AsyncHttpClientConfigDefaults.defaultUseInsecureTrustManager());
115+
testBooleanSystemProperty("useInsecureTrustManager", "defaultUseInsecureTrustManager", "false");
116116
}
117117

118118
private void testIntegerSystemProperty(String propertyName, String methodName, String value) {

client/src/test/java/org/asynchttpclient/BasicHttpProxyToHttpsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public void tearDownGlobal() throws Exception {
9393

9494
@Test
9595
public void nonPreemptyProxyAuthWithHttpsTarget() throws IOException, InterruptedException, ExecutionException {
96-
try (AsyncHttpClient client = asyncHttpClient(config().setAcceptAnyCertificate(true))) {
96+
try (AsyncHttpClient client = asyncHttpClient(config().setUseInsecureTrustManager(true))) {
9797
String targetUrl = "https://localhost:" + httpPort + "/foo/bar";
9898
Request request = get(targetUrl)//
9999
.setProxyServer(proxyServer("127.0.0.1", proxyPort).setRealm(realm(AuthScheme.BASIC, "johndoe", "pass")))//

client/src/test/java/org/asynchttpclient/HttpToHttpsRedirectTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public void httpToHttpsRedirect() throws Exception {
9696
AsyncHttpClientConfig cg = config()//
9797
.setMaxRedirects(5)//
9898
.setFollowRedirect(true)//
99-
.setAcceptAnyCertificate(true)//
99+
.setUseInsecureTrustManager(true)//
100100
.build();
101101
try (AsyncHttpClient c = asyncHttpClient(cg)) {
102102
Response response = c.prepareGet(getTargetUrl()).setHeader("X-redirect", getTargetUrl2()).execute().get();
@@ -113,7 +113,7 @@ public void httpToHttpsProperConfig() throws Exception {
113113
AsyncHttpClientConfig cg = config()//
114114
.setMaxRedirects(5)//
115115
.setFollowRedirect(true)//
116-
.setAcceptAnyCertificate(true)//
116+
.setUseInsecureTrustManager(true)//
117117
.build();
118118
try (AsyncHttpClient c = asyncHttpClient(cg)) {
119119
Response response = c.prepareGet(getTargetUrl()).setHeader("X-redirect", getTargetUrl2() + "/test2").execute().get();
@@ -136,7 +136,7 @@ public void relativeLocationUrl() throws Exception {
136136
AsyncHttpClientConfig cg = config()//
137137
.setMaxRedirects(5)//
138138
.setFollowRedirect(true)//
139-
.setAcceptAnyCertificate(true)//
139+
.setUseInsecureTrustManager(true)//
140140
.build();
141141
try (AsyncHttpClient c = asyncHttpClient(cg)) {
142142
Response response = c.prepareGet(getTargetUrl()).setHeader("X-redirect", "/foo/test").execute().get();

client/src/test/java/org/asynchttpclient/proxy/HttpsProxyTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void tearDownGlobal() throws Exception {
6767
@Test(groups = "standalone")
6868
public void testRequestProxy() throws Exception {
6969

70-
try (AsyncHttpClient asyncHttpClient = asyncHttpClient(config().setFollowRedirect(true).setAcceptAnyCertificate(true))) {
70+
try (AsyncHttpClient asyncHttpClient = asyncHttpClient(config().setFollowRedirect(true).setUseInsecureTrustManager(true))) {
7171
RequestBuilder rb = get(getTargetUrl2()).setProxyServer(proxyServer("localhost", port1));
7272
Response r = asyncHttpClient.executeRequest(rb.build()).get();
7373
assertEquals(r.getStatusCode(), 200);
@@ -79,7 +79,7 @@ public void testConfigProxy() throws Exception {
7979
AsyncHttpClientConfig config = config()//
8080
.setFollowRedirect(true)//
8181
.setProxyServer(proxyServer("localhost", port1).build())//
82-
.setAcceptAnyCertificate(true)//
82+
.setUseInsecureTrustManager(true)//
8383
.build();
8484
try (AsyncHttpClient asyncHttpClient = asyncHttpClient(config)) {
8585
Response r = asyncHttpClient.executeRequest(get(getTargetUrl2())).get();
@@ -90,7 +90,7 @@ public void testConfigProxy() throws Exception {
9090
@Test(groups = "standalone")
9191
public void testPooledConnectionsWithProxy() throws Exception {
9292

93-
try (AsyncHttpClient asyncHttpClient = asyncHttpClient(config().setFollowRedirect(true).setAcceptAnyCertificate(true).setKeepAlive(true))) {
93+
try (AsyncHttpClient asyncHttpClient = asyncHttpClient(config().setFollowRedirect(true).setUseInsecureTrustManager(true).setKeepAlive(true))) {
9494
RequestBuilder rb = get(getTargetUrl2()).setProxyServer(proxyServer("localhost", port1));
9595

9696
Response r1 = asyncHttpClient.executeRequest(rb.build()).get();

client/src/test/java/org/asynchttpclient/ws/ProxyTunnellingTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ private void runTest(boolean secure) throws Exception {
8787

8888
// CONNECT happens over HTTP, not HTTPS
8989
ProxyServer ps = proxyServer("localhost", port1).build();
90-
try (AsyncHttpClient asyncHttpClient = asyncHttpClient(config().setProxyServer(ps).setAcceptAnyCertificate(true))) {
90+
try (AsyncHttpClient asyncHttpClient = asyncHttpClient(config().setProxyServer(ps).setUseInsecureTrustManager(true))) {
9191
final CountDownLatch latch = new CountDownLatch(1);
9292
final AtomicReference<String> text = new AtomicReference<>("");
9393

extras/simple/src/main/java/org/asynchttpclient/extras/simple/SimpleAsyncHttpClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ public Builder setMaxRequestRetry(int maxRequestRetry) {
648648
}
649649

650650
public Builder setAcceptAnyCertificate(boolean acceptAnyCertificate) {
651-
configBuilder.setAcceptAnyCertificate(acceptAnyCertificate);
651+
configBuilder.setUseInsecureTrustManager(acceptAnyCertificate);
652652
return this;
653653
}
654654

0 commit comments

Comments
 (0)