Search in sources :

Example 6 with SslAction

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

the class TestSslCloseSvr method transferBigData.

private void transferBigData() throws InterruptedException, ExecutionException, TimeoutException {
    ByteBuffer b = ByteBuffer.allocate(17000);
    b.put((byte) 1);
    b.put((byte) 2);
    // simulate buffer full of 0's except first 2 and last 2
    b.position(b.limit() - 2);
    b.put((byte) 3);
    b.put((byte) 4);
    b.flip();
    XFuture<Void> future = channel.write(b);
    future.get(2, TimeUnit.SECONDS);
    // results in two ssl packets going out instead of the one that was fed in..
    SslAction action = parseIncoming();
    SslAction action2 = parseIncoming();
    Assert.assertEquals(SslActionEnum.SEND_TO_APP, action.getSslAction());
    Assert.assertEquals(SslActionEnum.SEND_TO_APP, action2.getSslAction());
    Assert.assertEquals(17000, action.getDecryptedData().getReadableSize() + action2.getDecryptedData().getReadableSize());
}
Also used : ByteBuffer(java.nio.ByteBuffer) SslAction(org.webpieces.ssl.api.dto.SslAction)

Example 7 with SslAction

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

the class TestSslCloseSvr method testBasicCloseFromClient.

// @Test
public void testBasicCloseFromClient() throws GeneralSecurityException, IOException, InterruptedException, ExecutionException, TimeoutException {
    SslAction action = clientSslParser.close();
    Assert.assertEquals(SslActionEnum.SEND_TO_SOCKET, action.getSslAction());
    mockChannel.forceDataRead(mockJdk, action.getEncryptedData());
    Channel closedChannel = listener.getConnectionClosed();
    Assert.assertEquals(channel, closedChannel);
    SslAction action2 = parseIncoming();
    Assert.assertEquals(SslActionEnum.LINK_SUCCESSFULLY_CLOSED, action2.getSslAction());
}
Also used : Channel(org.webpieces.nio.api.channels.Channel) TCPChannel(org.webpieces.nio.api.channels.TCPChannel) MockSvrChannel(org.webpieces.nio.api.mocks.MockSvrChannel) MockSvrSideJdkChannel(org.webpieces.nio.api.mocks.MockSvrSideJdkChannel) SslAction(org.webpieces.ssl.api.dto.SslAction)

Example 8 with SslAction

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

the class TestSslCloseSvr method testBothEndsAtSameTime.

// @Test
public void testBothEndsAtSameTime() throws InterruptedException, ExecutionException, TimeoutException {
    XFuture<Void> future = channel.close();
    SslAction action = clientSslParser.close();
    Assert.assertEquals(SslActionEnum.SEND_TO_SOCKET, action.getSslAction());
    Assert.assertTrue(future.isDone());
    mockChannel.forceDataRead(mockJdk, action.getEncryptedData());
    future.get(2, TimeUnit.SECONDS);
    SslAction action2 = parseIncoming();
    Assert.assertEquals(SslActionEnum.LINK_SUCCESSFULLY_CLOSED, action2.getSslAction());
    // far end closed should NOT be called...
    Assert.assertEquals(0, listener.getNumConnectionsClosed());
}
Also used : SslAction(org.webpieces.ssl.api.dto.SslAction)

Example 9 with SslAction

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

the class TestSslCloseSvr method testRaceFarendCloseThenServerCloses.

// @Test
public void testRaceFarendCloseThenServerCloses() throws InterruptedException, ExecutionException, TimeoutException {
    SslAction action = clientSslParser.close();
    Assert.assertEquals(SslActionEnum.SEND_TO_SOCKET, action.getSslAction());
    mockChannel.forceDataRead(mockJdk, action.getEncryptedData());
    Assert.assertEquals(1, listener.getNumConnectionsClosed());
    SslAction action2 = parseIncoming();
    Assert.assertEquals(SslActionEnum.LINK_SUCCESSFULLY_CLOSED, action2.getSslAction());
    // but before the client knew it was closing and was notified, it calls close as well
    XFuture<Void> future = channel.close();
    future.get(2, TimeUnit.SECONDS);
}
Also used : SslAction(org.webpieces.ssl.api.dto.SslAction)

Example 10 with SslAction

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

the class TestSslCloseSvr method setup.

@Before
public void setup() throws GeneralSecurityException, IOException, InterruptedException, ExecutionException, TimeoutException {
    System.setProperty("jdk.tls.server.protocols", "TLSv1.2");
    System.setProperty("jdk.tls.client.protocols", "TLSv1.2");
    server = createServer();
    clientSslParser = createClientParser();
    XFuture<Void> future = server.start(new InetSocketAddress(8443));
    Assert.assertFalse(future.isDone());
    mockJdk.setThread(Thread.currentThread());
    mockJdk.fireSelector();
    future.get(2, TimeUnit.SECONDS);
    SslAction result = clientSslParser.beginHandshake();
    // simulate the jdk firing the selector with a new channel...
    mockSvrChannel.addNewChannel(mockChannel);
    mockJdk.setThread(Thread.currentThread());
    mockJdk.fireSelector();
    // assert connectionOpened was called with value of isReadyForWrites=false
    // (This feature is specifically so clients can start a time and timeout the connection if they do not
    // receive a valid payload in a certain amount of time).
    ConnectionOpen connectionOpenedInfo = listener.getConnectionOpenedInfo();
    channel = connectionOpenedInfo.channel;
    Assert.assertEquals(false, connectionOpenedInfo.isReadyForWrites);
    mockChannel.setNumBytesToConsume(100000);
    mockChannel.forceDataRead(mockJdk, result.getEncryptedData());
    // 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) InetSocketAddress(java.net.InetSocketAddress) SslAction(org.webpieces.ssl.api.dto.SslAction) Before(org.junit.Before)

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