Search in sources :

Example 16 with SslAction

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

the class SSLParserImpl method createResult.

private List<SslAction> createResult() {
    List<SslAction> infos = new ArrayList<>();
    if (encryptedData != null) {
        infos.add(new SslAction(SslActionEnum.SEND_TO_SOCKET, encryptedData, null));
        encryptedData = null;
    }
    if (decryptedData != null) {
        infos.add(new SslAction(SslActionEnum.SEND_TO_APP, null, decryptedData));
        decryptedData = null;
    }
    if (encryptedLinkEsstablished) {
        encryptedLinkEsstablished = false;
        infos.add(new SslAction(SslActionEnum.SEND_LINK_ESTABLISHED_TO_APP, null, null));
    }
    if (isClosed) {
        if (isClientInitiatedClosed)
            infos.add(new SslAction(SslActionEnum.LINK_SUCCESSFULLY_CLOSED, null, null));
        else
            infos.add(new SslAction(SslActionEnum.SEND_LINK_CLOSED_TO_APP, null, null));
    }
    if (infos.size() == 0)
        infos.add(new SslAction(SslActionEnum.WAIT_FOR_MORE_DATA_FROM_REMOTE_END, null, null));
    // get result from above
    return infos;
}
Also used : ArrayList(java.util.ArrayList) SslAction(org.webpieces.ssl.api.dto.SslAction)

Example 17 with SslAction

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

the class TestSslBasicClient 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 18 with SslAction

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

the class TestSslBasicClient method testHalfThenTooMuchFedInPacket.

// @Test
public void testHalfThenTooMuchFedInPacket() throws InterruptedException, ExecutionException, TimeoutException {
    List<DataWrapper> packets = reshuffle();
    SslAction action1 = parseIncoming(packets.get(0));
    Assert.assertEquals(SslActionEnum.WAIT_FOR_MORE_DATA_FROM_REMOTE_END, action1.getSslAction());
    SslAction action2 = parseIncoming(packets.get(1));
    Assert.assertEquals(SslActionEnum.WAIT_FOR_MORE_DATA_FROM_REMOTE_END, action2.getSslAction());
    SslAction action3 = parseIncoming(packets.get(2));
    Assert.assertEquals(SslActionEnum.WAIT_FOR_MORE_DATA_FROM_REMOTE_END, action3.getSslAction());
    XFuture<List<SslAction>> resultFuture2 = svrSslParser.parseIncoming(packets.get(3));
    List<SslAction> result2 = resultFuture2.get(2, TimeUnit.SECONDS);
    Assert.assertEquals(SslActionEnum.SEND_TO_SOCKET, result2.get(0).getSslAction());
    Assert.assertEquals(SslActionEnum.SEND_LINK_ESTABLISHED_TO_APP, result2.get(1).getSslAction());
    // client is still NOT connected yet until the SSL handshake final messages are received
    Assert.assertFalse(connectFuture.isDone());
    mockChannel.forceDataRead(mockJdk, result2.get(0).getEncryptedData());
    connectFuture.get(2, TimeUnit.SECONDS);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) ArrayList(java.util.ArrayList) List(java.util.List) SslAction(org.webpieces.ssl.api.dto.SslAction)

Example 19 with SslAction

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

the class TestSslBasicClient 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");
    svrSslParser = TestSslCloseClient.createSslSvrParser();
    channel = TestSslCloseClient.createClientChannel("server", mockJdk);
    int port = 8443;
    mockChannel.setNumBytesToConsume(100000);
    mockChannel.addConnectReturnValue(true);
    // trick the selector into thinking we are on the selector thread
    mockJdk.setThread(Thread.currentThread());
    connectFuture = channel.connect(new InetSocketAddress("localhost", port), mockClientDataListener);
    // not connected until ssl handshake is complete
    Assert.assertFalse(connectFuture.isDone());
    SslAction result = parseIncoming();
    Assert.assertEquals(SslActionEnum.SEND_TO_SOCKET, result.getSslAction());
    mockChannel.forceDataRead(mockJdk, result.getEncryptedData());
}
Also used : InetSocketAddress(java.net.InetSocketAddress) SslAction(org.webpieces.ssl.api.dto.SslAction)

Example 20 with SslAction

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

the class TestSslCloseClient 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)

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