Search in sources :

Example 46 with SSLEngineResult

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

the class SSLEngineResultTest method test_bytesProduced.

/**
     * Test for <code>bytesProduced()</code> method
     */
public void test_bytesProduced() {
    int[] pos = { 0, 1, 1000, Integer.MAX_VALUE, (Integer.MAX_VALUE - 1) };
    SSLEngineResult.Status[] enS = SSLEngineResult.Status.values();
    SSLEngineResult.HandshakeStatus[] enHS = SSLEngineResult.HandshakeStatus.values();
    for (int i = 0; i < enS.length; i++) {
        for (int j = 0; j < enHS.length; j++) {
            for (int n = 0; n < pos.length; n++) {
                for (int l = 0; l < pos.length; ++l) {
                    SSLEngineResult res = new SSLEngineResult(enS[i], enHS[j], pos[n], pos[l]);
                    assertEquals("Incorrect bytesProduced", pos[l], res.bytesProduced());
                }
            }
        }
    }
}
Also used : SSLEngineResult(javax.net.ssl.SSLEngineResult)

Example 47 with SSLEngineResult

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

the class SSLEngineResultTest method test_bytesConsumed.

/**
     * Test for <code>bytesConsumed()</code> method
     */
public void test_bytesConsumed() {
    int[] pos = { 0, 1, 1000, Integer.MAX_VALUE, (Integer.MAX_VALUE - 1) };
    SSLEngineResult.Status[] enS = SSLEngineResult.Status.values();
    SSLEngineResult.HandshakeStatus[] enHS = SSLEngineResult.HandshakeStatus.values();
    for (int i = 0; i < enS.length; i++) {
        for (int j = 0; j < enHS.length; j++) {
            for (int n = 0; n < pos.length; n++) {
                for (int l = 0; l < pos.length; l++) {
                    SSLEngineResult res = new SSLEngineResult(enS[i], enHS[j], pos[n], pos[l]);
                    assertEquals("Incorrect bytesConsumed", pos[n], res.bytesConsumed());
                }
            }
        }
    }
}
Also used : SSLEngineResult(javax.net.ssl.SSLEngineResult)

Example 48 with SSLEngineResult

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

the class SSLEngineResultTest method test_ConstructorLjavax_net_ssl_SSLEngineResult_StatusLjavax_net_ssl_SSLEngineResult_HandshakeStatusII.

/**
     * Test for <code>SSLEngineResult(SSLEngineResult.Status status,
     *              SSLEngineResult.HandshakeStatus handshakeStatus,
     *              int bytesConsumed,
     *              int bytesProduced) </code> constructor and
     * <code>getHandshakeStatus()</code>
     * <code>getStatus()</code>
     * <code>bytesConsumed()</code>
     * <code>bytesProduced()</code>
     * <code>toString()</code>
     * methods
     * Assertions:
     * constructor throws IllegalArgumentException when bytesConsumed
     * or bytesProduced is negative or when status or handshakeStatus
     * is null
     *
     */
public void test_ConstructorLjavax_net_ssl_SSLEngineResult_StatusLjavax_net_ssl_SSLEngineResult_HandshakeStatusII() {
    int[] neg = { -1, -10, -1000, Integer.MIN_VALUE, (Integer.MIN_VALUE + 1) };
    try {
        new SSLEngineResult(null, SSLEngineResult.HandshakeStatus.FINISHED, 1, 1);
        fail("IllegalArgumentException must be thrown");
    } catch (IllegalArgumentException e) {
    }
    try {
        new SSLEngineResult(SSLEngineResult.Status.BUFFER_OVERFLOW, null, 1, 1);
        fail("IllegalArgumentException must be thrown");
    } catch (IllegalArgumentException e) {
    }
    for (int i = 0; i < neg.length; i++) {
        try {
            new SSLEngineResult(SSLEngineResult.Status.BUFFER_OVERFLOW, SSLEngineResult.HandshakeStatus.FINISHED, neg[i], 1);
            fail("IllegalArgumentException must be thrown");
        } catch (IllegalArgumentException e) {
        }
    }
    for (int i = 0; i < neg.length; i++) {
        try {
            new SSLEngineResult(SSLEngineResult.Status.BUFFER_OVERFLOW, SSLEngineResult.HandshakeStatus.FINISHED, 1, neg[i]);
            fail("IllegalArgumentException must be thrown");
        } catch (IllegalArgumentException e) {
        }
    }
    try {
        SSLEngineResult res = new SSLEngineResult(SSLEngineResult.Status.BUFFER_OVERFLOW, SSLEngineResult.HandshakeStatus.FINISHED, 1, 2);
        assertNotNull("Null object", res);
        assertEquals(1, res.bytesConsumed());
        assertEquals(2, res.bytesProduced());
    } catch (Exception e) {
        fail("Unexpected exception: " + e);
    }
}
Also used : SSLEngineResult(javax.net.ssl.SSLEngineResult)

Example 49 with SSLEngineResult

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

the class SSLEngineResultTest method test_getHandshakeStatus.

/**
     * Test for <code>getHandshakeStatus()</code> method
     */
public void test_getHandshakeStatus() {
    int[] pos = { 0, 1, 1000, Integer.MAX_VALUE, (Integer.MAX_VALUE - 1) };
    SSLEngineResult.Status[] enS = SSLEngineResult.Status.values();
    SSLEngineResult.HandshakeStatus[] enHS = SSLEngineResult.HandshakeStatus.values();
    for (int i = 0; i < enS.length; i++) {
        for (int j = 0; j < enHS.length; j++) {
            for (int n = 0; n < pos.length; n++) {
                for (int l = 0; l < pos.length; ++l) {
                    SSLEngineResult res = new SSLEngineResult(enS[i], enHS[j], pos[n], pos[l]);
                    assertEquals("Incorrect HandshakeStatus", enHS[j], res.getHandshakeStatus());
                }
            }
        }
    }
}
Also used : SSLEngineResult(javax.net.ssl.SSLEngineResult)

Example 50 with SSLEngineResult

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

the class SSLEngineTest method test_unwrap_06.

/**
     * javax.net.ssl.SSLEngine#unwrap(ByteBuffer src, ByteBuffer[] dsts,
     *                                       int offset, int length)
     */
public void test_unwrap_06() {
    String host = "new host";
    int port = 8080;
    ByteBuffer[] bbA = { ByteBuffer.allocate(100), ByteBuffer.allocate(10), ByteBuffer.allocate(100) };
    ByteBuffer bb = ByteBuffer.allocate(10);
    SSLEngine sse = getEngine(host, port);
    sse.setUseClientMode(true);
    try {
        SSLEngineResult res = sse.unwrap(bb, bbA, 0, bbA.length);
        assertEquals(0, res.bytesConsumed());
        assertEquals(0, res.bytesProduced());
    } catch (Exception ex) {
        fail("Unexpected exception: " + ex);
    }
}
Also used : SSLEngineResult(javax.net.ssl.SSLEngineResult) SSLEngine(javax.net.ssl.SSLEngine) ByteBuffer(java.nio.ByteBuffer) IOException(java.io.IOException) KeyManagementException(java.security.KeyManagementException) SSLException(javax.net.ssl.SSLException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ReadOnlyBufferException(java.nio.ReadOnlyBufferException)

Aggregations

SSLEngineResult (javax.net.ssl.SSLEngineResult)139 ByteBuffer (java.nio.ByteBuffer)53 IOException (java.io.IOException)32 SSLException (javax.net.ssl.SSLException)32 SSLEngine (javax.net.ssl.SSLEngine)25 Test (org.junit.Test)13 ReadOnlyBufferException (java.nio.ReadOnlyBufferException)12 SelfSignedCertificate (io.netty.handler.ssl.util.SelfSignedCertificate)10 HandshakeStatus (javax.net.ssl.SSLEngineResult.HandshakeStatus)9 EOFException (java.io.EOFException)7 ByteBuf (io.netty.buffer.ByteBuf)6 SSLSession (javax.net.ssl.SSLSession)6 WritePendingException (java.nio.channels.WritePendingException)5 KeyManagementException (java.security.KeyManagementException)5 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)5 ExecutionException (java.util.concurrent.ExecutionException)5 TimeoutException (java.util.concurrent.TimeoutException)5 Status (javax.net.ssl.SSLEngineResult.Status)5 CompositeByteBuf (io.netty.buffer.CompositeByteBuf)4 BufferUnderflowException (java.nio.BufferUnderflowException)3