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());
}
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());
}
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());
}
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);
}
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();
}
Aggregations