Skip to content

Commit 4ba9a9f

Browse files
committed
Check in a fix for hostname validation failure.
1 parent eace5fe commit 4ba9a9f

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

src/main/java/com/ning/http/client/providers/netty/NettyConnectListener.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ public final void operationComplete(ChannelFuture f) throws Exception {
7777
// TODO: channel.getRemoteAddress()).getHostName() is very expensive. Should cache the result.
7878
if (!v.verify(InetSocketAddress.class.cast(channel.getRemoteAddress()).getHostName(),
7979
sslHandler.getEngine().getSession())) {
80-
throw new ConnectException("HostnameVerifier exception.");
80+
future.abort(new ConnectException("HostnameVerifier exception."));
81+
return;
8182
}
8283
}
8384

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright 2014 AsyncHttpClient Project
3+
*
4+
* AsyncHttpClient Project licenses this file to you under the Apache License, version 2.0
5+
* (the "License"); you may not use this file except in compliance with the
6+
* License. You may obtain a copy of the License at:
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations
14+
* under the License.
15+
*
16+
*/
17+
package com.ning.http.client.providers.netty;
18+
19+
import com.ning.http.client.AsyncHttpClient;
20+
import com.ning.http.client.AsyncHttpClientConfig;
21+
import com.ning.http.client.Response;
22+
import org.jboss.netty.logging.InternalLoggerFactory;
23+
import org.jboss.netty.logging.Slf4JLoggerFactory;
24+
import org.testng.annotations.Test;
25+
26+
import javax.net.ssl.HostnameVerifier;
27+
import javax.net.ssl.SSLSession;
28+
import java.io.IOException;
29+
import java.net.ConnectException;
30+
import java.util.concurrent.ExecutionException;
31+
32+
import static org.testng.Assert.*;
33+
34+
/**
35+
*
36+
*/
37+
public class NettyHostnameValidationFailureTest {
38+
39+
@Test(groups = "standalone")
40+
public void testHostnameValidationFailure() {
41+
//InternalLoggerFactory.setDefaultFactory(new Slf4JLoggerFactory());
42+
43+
AsyncHttpClientConfig.Builder builder = new AsyncHttpClientConfig.Builder()//
44+
.setAllowPoolingConnection(true)//
45+
.setHostnameVerifier(new HostnameVerifier() {
46+
public boolean verify(String arg0, SSLSession arg1) {
47+
return false;
48+
}
49+
})
50+
.setConnectionTimeoutInMs(60000);
51+
AsyncHttpClient client = new AsyncHttpClient(builder.build());
52+
53+
try {
54+
client.prepareGet("https://www.google.fr").execute().get();
55+
fail("Should have thrown an exception");
56+
} catch (ExecutionException e) {
57+
assertTrue(e.getMessage().contains("HostnameVerifier exception."));
58+
} catch (Exception e) {
59+
fail(e.getClass().getCanonicalName());
60+
} finally {
61+
client.close();
62+
}
63+
}
64+
}

0 commit comments

Comments
 (0)