Search in sources :

Example 11 with SslAction

use of org.webpieces.ssl.api.dto.SslAction in project webpieces by deanhiller.

the class TestSslBasicSvr method testSplitData.

// @Test
public void testSplitData() throws InterruptedException, ExecutionException, TimeoutException {
    // 3 encrypted packets sent here
    SslAction action = parseIncoming();
    Assert.assertEquals(SslActionEnum.SEND_TO_SOCKET, action.getSslAction());
    List<DataWrapper> split = split(action.getEncryptedData());
    DataWrapper back = dataGen.chainDataWrappers(split.get(0), split.get(1), split.get(2), split.get(3));
    byte[] b1 = action.getEncryptedData().createByteArray();
    byte[] b2 = back.createByteArray();
    Assert.assertEquals(b1.length, b2.length);
    for (int i = 0; i < b1.length; i++) {
        Assert.assertEquals(b1[i], b2[i]);
    }
    mockChannel.forceDataRead(mockJdk, split.get(0));
    Assert.assertEquals(0, mockChannel.getPayloadQueueSize());
    mockChannel.forceDataRead(mockJdk, split.get(1));
    Assert.assertEquals(0, mockChannel.getPayloadQueueSize());
    mockChannel.forceDataRead(mockJdk, split.get(2));
    Assert.assertEquals(0, mockChannel.getPayloadQueueSize());
    mockChannel.forceDataRead(mockJdk, split.get(3));
    Assert.assertEquals(2, mockChannel.getPayloadQueueSize());
    Assert.assertEquals(SslActionEnum.WAIT_FOR_MORE_DATA_FROM_REMOTE_END, parseIncoming().getSslAction());
    Assert.assertEquals(SslActionEnum.SEND_LINK_ESTABLISHED_TO_APP, parseIncoming().getSslAction());
    ConnectionOpen openedInfo = listener.getConnectionOpenedInfo();
    Assert.assertEquals(true, openedInfo.isReadyForWrites);
    Assert.assertEquals(channel, openedInfo.channel);
    transferBigData();
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) ConnectionOpen(org.webpieces.nio.api.mocks.MockAsyncListener.ConnectionOpen) SslAction(org.webpieces.ssl.api.dto.SslAction)

Example 12 with SslAction

use of org.webpieces.ssl.api.dto.SslAction in project webpieces by deanhiller.

the class TestSslBasicSvr method testBasic.

// begin handshake results in ONE packet client -> server (server creates runnable, creating ONE
// server creates runnable, runs it creating ONE packet server -> client
// client creates runnable, runs it creating THREE packets client -> server
// all 3 received, server creates TWO packets  client -> server (server is connected here)
// client receives two packets and is connected
// @Test
public void testBasic() throws InterruptedException, ExecutionException, TimeoutException, GeneralSecurityException, IOException {
    // 3 encrypted packets sent here
    SslAction action = parseIncoming();
    Assert.assertEquals(SslActionEnum.SEND_TO_SOCKET, action.getSslAction());
    mockChannel.forceDataRead(mockJdk, action.getEncryptedData());
    Assert.assertEquals(SslActionEnum.WAIT_FOR_MORE_DATA_FROM_REMOTE_END, parseIncoming().getSslAction());
    Assert.assertEquals(SslActionEnum.SEND_LINK_ESTABLISHED_TO_APP, parseIncoming().getSslAction());
    ConnectionOpen openedInfo = listener.getConnectionOpenedInfo();
    Assert.assertEquals(true, openedInfo.isReadyForWrites);
    Assert.assertEquals(channel, openedInfo.channel);
    transferBigData();
}
Also used : ConnectionOpen(org.webpieces.nio.api.mocks.MockAsyncListener.ConnectionOpen) SslAction(org.webpieces.ssl.api.dto.SslAction)

Example 13 with SslAction

use of org.webpieces.ssl.api.dto.SslAction in project webpieces by deanhiller.

the class TestSslBasicSvr method parseIncoming.

private SslAction parseIncoming() throws InterruptedException, ExecutionException, TimeoutException {
    DataWrapper payload = mockChannel.nextPayload();
    XFuture<List<SslAction>> resultFuture2 = clientSslParser.parseIncoming(payload);
    List<SslAction> result2 = resultFuture2.get(2, TimeUnit.SECONDS);
    Assert.assertEquals(1, result2.size());
    return result2.get(0);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) ArrayList(java.util.ArrayList) List(java.util.List) SslAction(org.webpieces.ssl.api.dto.SslAction)

Example 14 with SslAction

use of org.webpieces.ssl.api.dto.SslAction in project webpieces by deanhiller.

the class TestSslCloseSvr method testBasicCloseFromServer.

// @Test
public void testBasicCloseFromServer() throws GeneralSecurityException, IOException, InterruptedException, ExecutionException, TimeoutException {
    XFuture<Void> future = channel.close();
    Assert.assertTrue(future.isDone());
    DataWrapper payload = mockChannel.nextPayload();
    XFuture<List<SslAction>> resultFuture2 = clientSslParser.parseIncoming(payload);
    List<SslAction> result2 = resultFuture2.get(2, TimeUnit.SECONDS);
    Assert.assertEquals(2, result2.size());
    Assert.assertTrue(future.isDone());
    Assert.assertEquals(SslActionEnum.SEND_TO_SOCKET, result2.get(0).getSslAction());
    Assert.assertEquals(SslActionEnum.SEND_LINK_CLOSED_TO_APP, result2.get(1).getSslAction());
    mockChannel.forceDataRead(mockJdk, result2.get(0).getEncryptedData());
    future.get(2, TimeUnit.SECONDS);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) List(java.util.List) SslAction(org.webpieces.ssl.api.dto.SslAction)

Example 15 with SslAction

use of org.webpieces.ssl.api.dto.SslAction in project webpieces by deanhiller.

the class TestSslCloseSvr method parseIncoming.

private SslAction parseIncoming() throws InterruptedException, ExecutionException, TimeoutException {
    DataWrapper payload = mockChannel.nextPayload();
    XFuture<List<SslAction>> resultFuture2 = clientSslParser.parseIncoming(payload);
    List<SslAction> result2 = resultFuture2.get(2, TimeUnit.SECONDS);
    Assert.assertEquals(1, result2.size());
    return result2.get(0);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) List(java.util.List) SslAction(org.webpieces.ssl.api.dto.SslAction)

Aggregations

SslAction (org.webpieces.ssl.api.dto.SslAction)27 DataWrapper (org.webpieces.data.api.DataWrapper)11 List (java.util.List)10 ArrayList (java.util.ArrayList)6 InetSocketAddress (java.net.InetSocketAddress)4 ByteBuffer (java.nio.ByteBuffer)4 ConnectionOpen (org.webpieces.nio.api.mocks.MockAsyncListener.ConnectionOpen)4 Before (org.junit.Before)2 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)1 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)1 SSLEngine (javax.net.ssl.SSLEngine)1 AsyncConfig (org.webpieces.asyncserver.api.AsyncConfig)1 AsyncServerManager (org.webpieces.asyncserver.api.AsyncServerManager)1 BufferPool (org.webpieces.data.api.BufferPool)1 TwoPools (org.webpieces.data.api.TwoPools)1 Channel (org.webpieces.nio.api.channels.Channel)1 TCPChannel (org.webpieces.nio.api.channels.TCPChannel)1 MockSvrChannel (org.webpieces.nio.api.mocks.MockSvrChannel)1 MockSvrSideJdkChannel (org.webpieces.nio.api.mocks.MockSvrSideJdkChannel)1 SSLMetrics (org.webpieces.ssl.api.SSLMetrics)1