Search in sources :

Example 6 with HandshakeCompletedEvent

use of javax.net.ssl.HandshakeCompletedEvent 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 7 with HandshakeCompletedEvent

use of javax.net.ssl.HandshakeCompletedEvent 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)

Example 8 with HandshakeCompletedEvent

use of javax.net.ssl.HandshakeCompletedEvent in project robovm by robovm.

the class HandshakeCompletedEventTest method test_getSession.

/**
     * @throws IOException
     * javax.net.ssl.HandshakeCompletedEvent#getSession()
     */
public final void test_getSession() throws IOException {
    mySSLSession session = new mySSLSession("localhost", 1080, null);
    SSLSocket socket = (SSLSocket) SSLSocketFactory.getDefault().createSocket();
    HandshakeCompletedEvent event = new HandshakeCompletedEvent(socket, session);
    SSLSession ss = event.getSession();
    assertNotNull(ss);
    assertEquals(session, ss);
}
Also used : HandshakeCompletedEvent(javax.net.ssl.HandshakeCompletedEvent) SSLSocket(javax.net.ssl.SSLSocket) SSLSession(javax.net.ssl.SSLSession) org.apache.harmony.xnet.tests.support.mySSLSession(org.apache.harmony.xnet.tests.support.mySSLSession) org.apache.harmony.xnet.tests.support.mySSLSession(org.apache.harmony.xnet.tests.support.mySSLSession)

Example 9 with HandshakeCompletedEvent

use of javax.net.ssl.HandshakeCompletedEvent in project robovm by robovm.

the class HandshakeCompletedEventTest method test_getLocalPrincipal.

/**
     * @throws IOException
     * javax.net.ssl.HandshakeCompletedEvent#getLocalPrincipal()
     */
public final void test_getLocalPrincipal() throws Exception {
    mySSLSession session = new mySSLSession("localhost", 1080, null);
    SSLSocket socket = (SSLSocket) SSLSocketFactory.getDefault().createSocket();
    HandshakeCompletedEvent event = new HandshakeCompletedEvent(socket, session);
    assertNull(event.getLocalPrincipal());
}
Also used : HandshakeCompletedEvent(javax.net.ssl.HandshakeCompletedEvent) SSLSocket(javax.net.ssl.SSLSocket) org.apache.harmony.xnet.tests.support.mySSLSession(org.apache.harmony.xnet.tests.support.mySSLSession)

Example 10 with HandshakeCompletedEvent

use of javax.net.ssl.HandshakeCompletedEvent in project robovm by robovm.

the class HandshakeCompletedEventTest method test_getLocalCertificates.

/**
     * @throws IOException
     * javax.net.ssl.HandshakeCompletedEvent#getLocalCertificates()
     */
public final void test_getLocalCertificates() throws Exception {
    mySSLSession session = new mySSLSession("localhost", 1080, null);
    SSLSocket socket = (SSLSocket) SSLSocketFactory.getDefault().createSocket();
    HandshakeCompletedEvent event = new HandshakeCompletedEvent(socket, session);
    assertNull(event.getLocalCertificates());
}
Also used : HandshakeCompletedEvent(javax.net.ssl.HandshakeCompletedEvent) SSLSocket(javax.net.ssl.SSLSocket) org.apache.harmony.xnet.tests.support.mySSLSession(org.apache.harmony.xnet.tests.support.mySSLSession)

Aggregations

HandshakeCompletedEvent (javax.net.ssl.HandshakeCompletedEvent)17 SSLSocket (javax.net.ssl.SSLSocket)14 org.apache.harmony.xnet.tests.support.mySSLSession (org.apache.harmony.xnet.tests.support.mySSLSession)8 IOException (java.io.IOException)7 HandshakeCompletedListener (javax.net.ssl.HandshakeCompletedListener)6 SSLPeerUnverifiedException (javax.net.ssl.SSLPeerUnverifiedException)5 SocketException (java.net.SocketException)4 SSLException (javax.net.ssl.SSLException)4 CertificateException (java.security.cert.CertificateException)3 SocketTimeoutException (java.net.SocketTimeoutException)2 Certificate (java.security.cert.Certificate)2 ExecutorService (java.util.concurrent.ExecutorService)2 SSLEngineResult (javax.net.ssl.SSLEngineResult)2 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)2 SSLProtocolException (javax.net.ssl.SSLProtocolException)2 SSLServerSocket (javax.net.ssl.SSLServerSocket)2 SSLSession (javax.net.ssl.SSLSession)2 X509Certificate (javax.security.cert.X509Certificate)2 SharedPreferences (android.content.SharedPreferences)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1