Search in sources :

Example 6 with SSLPeerUnverifiedException

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);
}
Also used : SSLPeerUnverifiedException(javax.net.ssl.SSLPeerUnverifiedException) URL(java.net.URL) HttpsURLConnection(javax.net.ssl.HttpsURLConnection) Certificate(java.security.cert.Certificate)

Example 7 with SSLPeerUnverifiedException

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");
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) SSLPeerUnverifiedException(javax.net.ssl.SSLPeerUnverifiedException) CertificateException(java.security.cert.CertificateException) CertificateFactory(java.security.cert.CertificateFactory) Certificate(java.security.cert.Certificate)

Example 8 with SSLPeerUnverifiedException

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());
}
Also used : SSLPeerUnverifiedException(javax.net.ssl.SSLPeerUnverifiedException)

Example 9 with SSLPeerUnverifiedException

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);
}
Also used : HandshakeCompletedEvent(javax.net.ssl.HandshakeCompletedEvent) ByteArrayInputStream(java.io.ByteArrayInputStream) SSLSocket(javax.net.ssl.SSLSocket) SSLPeerUnverifiedException(javax.net.ssl.SSLPeerUnverifiedException) org.apache.harmony.xnet.tests.support.mySSLSession(org.apache.harmony.xnet.tests.support.mySSLSession) X509Certificate(javax.security.cert.X509Certificate)

Example 10 with SSLPeerUnverifiedException

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);
}
Also used : HandshakeCompletedEvent(javax.net.ssl.HandshakeCompletedEvent) SSLSocket(javax.net.ssl.SSLSocket) SSLPeerUnverifiedException(javax.net.ssl.SSLPeerUnverifiedException) org.apache.harmony.xnet.tests.support.mySSLSession(org.apache.harmony.xnet.tests.support.mySSLSession) X509Certificate(javax.security.cert.X509Certificate) Certificate(java.security.cert.Certificate)

Aggregations

SSLPeerUnverifiedException (javax.net.ssl.SSLPeerUnverifiedException)109 X509Certificate (java.security.cert.X509Certificate)40 Certificate (java.security.cert.Certificate)39 SSLSession (javax.net.ssl.SSLSession)27 SSLSocket (javax.net.ssl.SSLSocket)23 IOException (java.io.IOException)18 CertificateException (java.security.cert.CertificateException)14 SSLException (javax.net.ssl.SSLException)14 X509Certificate (javax.security.cert.X509Certificate)12 Principal (java.security.Principal)11 Test (org.junit.jupiter.api.Test)11 Test (org.junit.Test)8 InetSocketAddress (java.net.InetSocketAddress)7 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)7 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)7 CertificateEncodingException (java.security.cert.CertificateEncodingException)6 HttpsURLConnection (javax.net.ssl.HttpsURLConnection)6 MockResponse (mockwebserver3.MockResponse)6 Request (okhttp3.Request)6 UnknownHostException (java.net.UnknownHostException)5