Skip to content

Commit b930227

Browse files
committed
HTTPCLIENT-1255: AbstractVerifier incorrectly parses certificate CN containing wildcard
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1406217 13f79535-47bb-0310-9956-ffa450edef68
1 parent 44f798c commit b930227

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

Diff for: RELEASE_NOTES.txt

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
Changes since 4.2.1
1+
Changes in trunk
22
-------------------
33

4-
* [HTTPCLIENT-1248]: Default and lax redirect strategies should not convert requests redirected
4+
* [HTTPCLIENT-1255] AbstractVerifier incorrectly parses certificate CN containing wildcard
5+
Contributed by Oleg Kalnichevski <olegk at apache.org>
6+
7+
* [HTTPCLIENT-1248] Default and lax redirect strategies should not convert requests redirected
58
with 307 status to GET method.
69
Contributed by Oleg Kalnichevski <olegk at apache.org>
710

Diff for: httpclient/src/main/java/org/apache/http/conn/ssl/AbstractVerifier.java

+4-7
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@
4343
import java.util.List;
4444
import java.util.Locale;
4545
import java.util.StringTokenizer;
46-
import java.util.logging.Logger;
47-
import java.util.logging.Level;
4846

4947
import javax.net.ssl.SSLException;
5048
import javax.net.ssl.SSLSession;
@@ -204,9 +202,10 @@ public final void verify(final String host, final String[] cns,
204202
!isIPAddress(host);
205203

206204
if(doWildcard) {
207-
if (parts[0].length() > 1) { // e.g. server*
208-
String prefix = parts[0].substring(0, parts.length-2); // e.g. server
209-
String suffix = cn.substring(parts[0].length()); // skip wildcard part from cn
205+
String firstpart = parts[0];
206+
if (firstpart.length() > 1) { // e.g. server*
207+
String prefix = firstpart.substring(0, firstpart.length() - 1); // e.g. server
208+
String suffix = cn.substring(firstpart.length()); // skip wildcard part from cn
210209
String hostSuffix = hostName.substring(prefix.length()); // skip wildcard part from host
211210
match = hostName.startsWith(prefix) && hostSuffix.endsWith(suffix);
212211
} else {
@@ -302,8 +301,6 @@ private static String[] getSubjectAlts(
302301
c = cert.getSubjectAlternativeNames();
303302
}
304303
catch(CertificateParsingException cpe) {
305-
Logger.getLogger(AbstractVerifier.class.getName())
306-
.log(Level.FINE, "Error parsing certificate.", cpe);
307304
}
308305
if(c != null) {
309306
for (List<?> aC : c) {

Diff for: httpclient/src/test/java/org/apache/http/conn/ssl/TestHostnameVerifier.java

+12-1
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ public void testMatching() {
300300
}
301301

302302
@Test
303-
public void HTTPCLIENT_1097() {
303+
public void testHTTPCLIENT_1097() {
304304
String cns[];
305305
String alt[] = {};
306306
X509HostnameVerifier bhv = new BrowserCompatHostnameVerifier();
@@ -318,6 +318,17 @@ public void HTTPCLIENT_1097() {
318318
checkWildcard("s*.gouv.uk", false); // 2 character TLD, invalid 2TLD
319319
}
320320

321+
@Test
322+
public void testHTTPCLIENT_1255() {
323+
X509HostnameVerifier bhv = new BrowserCompatHostnameVerifier();
324+
X509HostnameVerifier shv = new StrictHostnameVerifier();
325+
326+
String cns[] = new String []{"m*.a.b.c.com"}; // component part
327+
String alt[] = {};
328+
checkMatching(bhv, "mail.a.b.c.com", cns, alt, false); // OK
329+
checkMatching(shv, "mail.a.b.c.com", cns, alt, false); // OK
330+
}
331+
321332
// Helper
322333
private void checkWildcard(String host, boolean isOK) {
323334
Assert.assertTrue(host+" should be "+isOK, isOK==AbstractVerifier.acceptableCountryWildcard(host));

0 commit comments

Comments
 (0)