use of javax.net.ssl.HostnameVerifier in project robovm by robovm.
the class HostnameVerifierTest method testSubjectAltNameWithWildcard.
public void testSubjectAltNameWithWildcard() throws Exception {
/*
* $ cat ./cert.cnf
* [req]
* distinguished_name=distinguished_name
* req_extensions=req_extensions
* x509_extensions=x509_extensions
* [distinguished_name]
* [req_extensions]
* [x509_extensions]
* subjectAltName=DNS:bar.com,DNS:*.baz.com
*
* $ openssl req -x509 -nodes -days 36500 -subj '/CN=foo.com' -config ./cert.cnf \
* -newkey rsa:512 -out cert.pem
*/
String cert = "-----BEGIN CERTIFICATE-----\n" + "MIIBPzCB6qADAgECAgkAnv/7Jv5r7pMwDQYJKoZIhvcNAQEFBQAwEjEQMA4GA1UE\n" + "AxMHZm9vLmNvbTAgFw0xMDEyMjAxODQ2MDFaGA8yMTEwMTEyNjE4NDYwMVowEjEQ\n" + "MA4GA1UEAxMHZm9vLmNvbTBcMA0GCSqGSIb3DQEBAQUAA0sAMEgCQQDAz2YXnyog\n" + "YdYLSFr/OEgSumtwqtZKJTB4wqTW/eKbBCEzxnyUMxWZIqUGu353PzwfOuWp2re3\n" + "nvVV+QDYQlh9AgMBAAGjITAfMB0GA1UdEQQWMBSCB2Jhci5jb22CCSouYmF6LmNv\n" + "bTANBgkqhkiG9w0BAQUFAANBAB8yrSl8zqy07i0SNYx2B/FnvQY734pxioaqFWfO\n" + "Bqo1ZZl/9aPHEWIwBrxYNVB0SGu/kkbt/vxqOjzzrkXukmI=\n" + "-----END CERTIFICATE-----";
CertificateFactory cf = CertificateFactory.getInstance("X.509");
InputStream in = new ByteArrayInputStream(cert.getBytes("UTF-8"));
X509Certificate x509 = (X509Certificate) cf.generateCertificate(in);
mySSLSession session = new mySSLSession(new X509Certificate[] { x509 });
HostnameVerifier verifier = HttpsURLConnection.getDefaultHostnameVerifier();
assertFalse(verifier.verify("foo.com", session));
assertTrue(verifier.verify("bar.com", session));
assertTrue(verifier.verify("a.baz.com", session));
assertTrue(verifier.verify("baz.com", session));
assertFalse(verifier.verify("a.foo.com", session));
assertFalse(verifier.verify("a.bar.com", session));
assertFalse(verifier.verify("quux.com", session));
}
use of javax.net.ssl.HostnameVerifier in project robovm by robovm.
the class HostnameVerifierTest method test_verify.
/**
* javax.net.ssl.HostnameVerifier#verify(String hostname, SSLSession
* session)
*/
public final void test_verify() throws Exception {
mySSLSession session = new mySSLSession("localhost", 1080, null);
HostnameVerifier hv = HttpsURLConnection.getDefaultHostnameVerifier();
assertFalse(hv.verify("localhost", session));
}
use of javax.net.ssl.HostnameVerifier in project robovm by robovm.
the class myHostnameVerifier method test_setDefaultHostnameVerifier.
/**
* javax.net.ssl.HttpsURLConnection#setDefaultHostnameVerifier()
*/
public final void test_setDefaultHostnameVerifier() {
try {
HttpsURLConnection.setDefaultHostnameVerifier(null);
fail("No expected IllegalArgumentException");
} catch (IllegalArgumentException expected) {
}
HostnameVerifier def = HttpsURLConnection.getDefaultHostnameVerifier();
try {
myHostnameVerifier hnv = new myHostnameVerifier();
HttpsURLConnection.setDefaultHostnameVerifier(hnv);
assertEquals(hnv, HttpsURLConnection.getDefaultHostnameVerifier());
} finally {
HttpsURLConnection.setDefaultHostnameVerifier(def);
}
}
use of javax.net.ssl.HostnameVerifier in project robovm by robovm.
the class myHostnameVerifier method test_getDefaultHostnameVerifier.
/**
* javax.net.ssl.HttpsURLConnection#getDefaultHostnameVerifier()
*/
public final void test_getDefaultHostnameVerifier() {
HostnameVerifier verifyer = HttpsURLConnection.getDefaultHostnameVerifier();
assertNotNull("Default hostname verifyer is null", verifyer);
}
use of javax.net.ssl.HostnameVerifier in project helios by spotify.
the class HostnameVerifierProviderTest method testHostnameVerificationDisabled.
@Test
public void testHostnameVerificationDisabled() {
final HostnameVerifierProvider provider = new HostnameVerifierProvider(false, delegate);
final HostnameVerifier verifier = provider.verifierFor("any.host");
assertTrue(verifier.verify("example.com", sslSession));
verifyNoMoreInteractions(delegate, sslSession);
}
Aggregations