Search in sources :

Example 56 with SSLSocket

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

the class AbstractClientConnAdapter method getSSLSession.

// non-javadoc, see interface ManagedClientConnection
public SSLSession getSSLSession() {
    OperatedClientConnection conn = getWrappedConnection();
    assertValid(conn);
    if (!isOpen())
        return null;
    SSLSession result = null;
    Socket sock = conn.getSocket();
    if (sock instanceof SSLSocket) {
        result = ((SSLSocket) sock).getSession();
    }
    return result;
}
Also used : SSLSocket(javax.net.ssl.SSLSocket) OperatedClientConnection(org.apache.http.conn.OperatedClientConnection) SSLSession(javax.net.ssl.SSLSession) Socket(java.net.Socket) SSLSocket(javax.net.ssl.SSLSocket)

Example 57 with SSLSocket

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

the class HandshakeCompletedEventTest method test_getCipherSuite.

/**
     * @throws IOException
     * javax.net.ssl.HandshakeCompletedEvent#getCipherSuite()
     */
public final void test_getCipherSuite() throws Exception {
    mySSLSession session = new mySSLSession("localhost", 1080, null);
    SSLSocket socket = (SSLSocket) SSLSocketFactory.getDefault().createSocket();
    HandshakeCompletedEvent event = new HandshakeCompletedEvent(socket, session);
    assertEquals("SuiteName", event.getCipherSuite());
}
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 58 with SSLSocket

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

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

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

Aggregations

SSLSocket (javax.net.ssl.SSLSocket)326 IOException (java.io.IOException)101 Test (org.junit.Test)62 SSLContext (javax.net.ssl.SSLContext)59 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)59 Socket (java.net.Socket)57 OutputStream (java.io.OutputStream)50 InetSocketAddress (java.net.InetSocketAddress)39 CertificateException (java.security.cert.CertificateException)33 SSLException (javax.net.ssl.SSLException)32 SSLSession (javax.net.ssl.SSLSession)31 InputStream (java.io.InputStream)30 SSLPeerUnverifiedException (javax.net.ssl.SSLPeerUnverifiedException)30 SSLServerSocket (javax.net.ssl.SSLServerSocket)27 SocketTimeoutException (java.net.SocketTimeoutException)24 SocketException (java.net.SocketException)23 ServerSocket (java.net.ServerSocket)22 UnknownHostException (java.net.UnknownHostException)21 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)21 InputStreamReader (java.io.InputStreamReader)19