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