use of javax.net.ssl.SSLPeerUnverifiedException in project robovm by robovm.
the class myHostnameVerifier method test_getServerCertificates.
/**
* javax.net.ssl.HttpsURLConnection#getServerCertificates()
*/
public final void test_getServerCertificates() throws Exception {
URL url = new URL("https://localhost:55555");
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
try {
connection.getServerCertificates();
fail("IllegalStateException wasn't thrown");
} catch (IllegalStateException expected) {
}
HttpsURLConnection con = new MyHttpsURLConnection(new URL("https://www.fortify.net/"), "X.508");
try {
con.getServerCertificates();
fail("SSLPeerUnverifiedException wasn't thrown");
} catch (SSLPeerUnverifiedException expected) {
}
con = new MyHttpsURLConnection(new URL("https://www.fortify.net/"), "X.509");
Certificate[] cert = con.getServerCertificates();
assertNotNull(cert);
assertEquals(1, cert.length);
}
use of javax.net.ssl.SSLPeerUnverifiedException in project robovm by robovm.
the class myHostnameVerifier method getServerCertificates.
/*
* @see javax.net.ssl.HttpsURLConnection#getServerCertificates()
*/
public Certificate[] getServerCertificates() throws SSLPeerUnverifiedException {
try {
CertificateFactory cf = CertificateFactory.getInstance(typeDone);
byte[] barr = TestUtils.getX509Certificate_v3();
ByteArrayInputStream bis = new ByteArrayInputStream(barr);
Certificate cert = cf.generateCertificate(bis);
return new Certificate[] { cert };
} catch (CertificateException se) {
throw new SSLPeerUnverifiedException("No server's end-entity certificate");
}
}
use of javax.net.ssl.SSLPeerUnverifiedException in project robovm by robovm.
the class SSLPeerUnverifiedExceptionTest method test_Constructor02.
/**
* Test for <code>SSLPeerUnverifiedException(String)</code> constructor Assertion:
* constructs SSLPeerUnverifiedException with detail message msg. Parameter
* <code>msg</code> is null.
*/
public void test_Constructor02() {
String msg = null;
SSLPeerUnverifiedException sslE = new SSLPeerUnverifiedException(msg);
assertNull("getMessage() must return null.", sslE.getMessage());
assertNull("getCause() must return null", sslE.getCause());
}
use of javax.net.ssl.SSLPeerUnverifiedException in project robovm by robovm.
the class HandshakeCompletedEventTest method test_getPeerCertificateChain.
/**
* @throws IOException
* javax.net.ssl.HandshakeCompletedEvent#getPeerCertificateChain()
*/
public final void test_getPeerCertificateChain() throws Exception {
ByteArrayInputStream bis = new ByteArrayInputStream(certificate.getBytes());
mySSLSession session = new mySSLSession((X509Certificate[]) null);
SSLSocket socket = (SSLSocket) SSLSocketFactory.getDefault().createSocket();
HandshakeCompletedEvent event = new HandshakeCompletedEvent(socket, session);
try {
event.getPeerCertificateChain();
fail("SSLPeerUnverifiedException wasn't thrown");
} catch (SSLPeerUnverifiedException expected) {
}
X509Certificate xc = X509Certificate.getInstance(bis);
X509Certificate[] xcs = { xc };
session = new mySSLSession(xcs);
event = new HandshakeCompletedEvent(socket, session);
X509Certificate[] res = event.getPeerCertificateChain();
assertEquals(1, res.length);
}
use of javax.net.ssl.SSLPeerUnverifiedException in project robovm by robovm.
the class HandshakeCompletedEventTest method test_getPeerCertificates.
/**
* @throws IOException
* javax.net.ssl.HandshakeCompletedEvent#getPeerCertificates()
*/
public final void test_getPeerCertificates() throws IOException {
mySSLSession session = new mySSLSession("localhost", 1080, null);
SSLSocket socket = (SSLSocket) SSLSocketFactory.getDefault().createSocket();
HandshakeCompletedEvent event = new HandshakeCompletedEvent(socket, session);
try {
event.getPeerCertificates();
fail("SSLPeerUnverifiedException wasn't thrown");
} catch (SSLPeerUnverifiedException expected) {
}
session = new mySSLSession((X509Certificate[]) null);
event = new HandshakeCompletedEvent(socket, session);
Certificate[] res = event.getPeerCertificates();
assertEquals(3, res.length);
}
Aggregations