HTTPCLIENT-2047: fixed regression in DefaultHostnameVerifier causing rejection of certs with non-standard domains.
This reverts commit 87cc64fc
This commit is contained in:
parent
3575cff3dc
commit
4401991d93
|
@ -164,7 +164,7 @@ public final class DefaultHostnameVerifier implements HttpClientHostnameVerifier
|
||||||
final SubjectName subjectAlt = subjectAlts.get(i);
|
final SubjectName subjectAlt = subjectAlts.get(i);
|
||||||
if (subjectAlt.getType() == SubjectName.DNS) {
|
if (subjectAlt.getType() == SubjectName.DNS) {
|
||||||
final String normalizedSubjectAlt = DnsUtils.normalize(subjectAlt.getValue());
|
final String normalizedSubjectAlt = DnsUtils.normalize(subjectAlt.getValue());
|
||||||
if (matchIdentityStrict(normalizedHost, normalizedSubjectAlt, publicSuffixMatcher, DomainType.ICANN)) {
|
if (matchIdentityStrict(normalizedHost, normalizedSubjectAlt, publicSuffixMatcher)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -177,7 +177,7 @@ public final class DefaultHostnameVerifier implements HttpClientHostnameVerifier
|
||||||
final PublicSuffixMatcher publicSuffixMatcher) throws SSLException {
|
final PublicSuffixMatcher publicSuffixMatcher) throws SSLException {
|
||||||
final String normalizedHost = DnsUtils.normalize(host);
|
final String normalizedHost = DnsUtils.normalize(host);
|
||||||
final String normalizedCn = DnsUtils.normalize(cn);
|
final String normalizedCn = DnsUtils.normalize(cn);
|
||||||
if (!matchIdentityStrict(normalizedHost, normalizedCn, publicSuffixMatcher, DomainType.ICANN)) {
|
if (!matchIdentityStrict(normalizedHost, normalizedCn, publicSuffixMatcher)) {
|
||||||
throw new SSLPeerUnverifiedException("Certificate for <" + host + "> doesn't match " +
|
throw new SSLPeerUnverifiedException("Certificate for <" + host + "> doesn't match " +
|
||||||
"common name of the certificate subject: " + cn);
|
"common name of the certificate subject: " + cn);
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,7 @@ import java.nio.charset.StandardCharsets;
|
||||||
import java.security.cert.CertificateFactory;
|
import java.security.cert.CertificateFactory;
|
||||||
import java.security.cert.X509Certificate;
|
import java.security.cert.X509Certificate;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -414,4 +415,28 @@ public class TestDefaultHostnameVerifier {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMatchDNSName() throws Exception {
|
||||||
|
DefaultHostnameVerifier.matchDNSName(
|
||||||
|
"host.domain.com",
|
||||||
|
Collections.singletonList(SubjectName.DNS("*.domain.com")),
|
||||||
|
publicSuffixMatcher);
|
||||||
|
DefaultHostnameVerifier.matchDNSName(
|
||||||
|
"host.xx",
|
||||||
|
Collections.singletonList(SubjectName.DNS("*.xx")),
|
||||||
|
publicSuffixMatcher);
|
||||||
|
DefaultHostnameVerifier.matchDNSName(
|
||||||
|
"host.appspot.com",
|
||||||
|
Collections.singletonList(SubjectName.DNS("*.appspot.com")),
|
||||||
|
publicSuffixMatcher);
|
||||||
|
DefaultHostnameVerifier.matchDNSName(
|
||||||
|
"demo-s3-bucket.s3.eu-central-1.amazonaws.com",
|
||||||
|
Collections.singletonList(SubjectName.DNS("*.s3.eu-central-1.amazonaws.com")),
|
||||||
|
publicSuffixMatcher);
|
||||||
|
DefaultHostnameVerifier.matchDNSName(
|
||||||
|
"hostname-workspace-1.local",
|
||||||
|
Collections.singletonList(SubjectName.DNS("hostname-workspace-1.local")),
|
||||||
|
publicSuffixMatcher);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
xx
|
xx
|
||||||
lan
|
lan
|
||||||
appspot.com
|
appspot.com
|
||||||
|
s3.eu-central-1.amazonaws.com
|
||||||
// ===END PRIVATE DOMAINS===
|
// ===END PRIVATE DOMAINS===
|
||||||
|
|
||||||
// ===BEGIN ICANN DOMAINS===
|
// ===BEGIN ICANN DOMAINS===
|
||||||
|
|
Loading…
Reference in New Issue