use of org.webpieces.ssl.api.dto.SslAction in project webpieces by deanhiller.
the class TestSslBasicClient 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 as ONE packet here and is connected
// @Test
public void testBasic() throws InterruptedException, ExecutionException, TimeoutException, GeneralSecurityException, IOException {
Assert.assertEquals(SslActionEnum.WAIT_FOR_MORE_DATA_FROM_REMOTE_END, parseIncoming().getSslAction());
Assert.assertEquals(SslActionEnum.WAIT_FOR_MORE_DATA_FROM_REMOTE_END, parseIncoming().getSslAction());
DataWrapper payload = mockChannel.nextPayload();
XFuture<List<SslAction>> resultFuture2 = svrSslParser.parseIncoming(payload);
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);
transferBigData();
transferBigDataOtherWay();
rehandShake();
}
use of org.webpieces.ssl.api.dto.SslAction in project webpieces by deanhiller.
the class TestSslBasicClient method rehandShake.
private void rehandShake() throws InterruptedException, ExecutionException, TimeoutException {
SslAction action1 = svrSslParser.beginHandshake();
mockChannel.forceDataRead(mockJdk, action1.getEncryptedData());
SslAction action2 = parseIncoming();
Assert.assertEquals(SslActionEnum.SEND_TO_SOCKET, action2.getSslAction());
mockChannel.forceDataRead(mockJdk, action2.getEncryptedData());
SslAction action3 = parseIncoming();
Assert.assertEquals(SslActionEnum.WAIT_FOR_MORE_DATA_FROM_REMOTE_END, action3.getSslAction());
SslAction action4 = parseIncoming();
Assert.assertEquals(SslActionEnum.WAIT_FOR_MORE_DATA_FROM_REMOTE_END, action4.getSslAction());
SslAction action5 = parseIncoming();
Assert.assertEquals(SslActionEnum.SEND_TO_SOCKET, action5.getSslAction());
mockChannel.forceDataRead(mockJdk, action5.getEncryptedData());
}
use of org.webpieces.ssl.api.dto.SslAction in project webpieces by deanhiller.
the class TestSslCloseClient method testRaceFarendCloseThenClientCloses.
// @Test
public void testRaceFarendCloseThenClientCloses() throws InterruptedException, ExecutionException, TimeoutException {
SslAction action = svrSslParser.close();
Assert.assertEquals(SslActionEnum.SEND_TO_SOCKET, action.getSslAction());
mockChannel.forceDataRead(mockJdk, action.getEncryptedData());
Assert.assertTrue(mockClientDataListener.isClosed());
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 TestSslBasicSvr 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");
SSLEngineFactoryForTestOld sslFactory = new SSLEngineFactoryForTestOld();
MeterRegistry meters = Metrics.globalRegistry;
ChannelManagerFactory factory = ChannelManagerFactory.createFactory(mockJdk, meters);
ChannelManager mgr = factory.createMultiThreadedChanMgr("test'n", new TwoPools("pl", new SimpleMeterRegistry()), new BackpressureConfig(), new DirectExecutor());
AsyncServerManager svrMgr = AsyncServerMgrFactory.createAsyncServer(mgr, meters);
server = svrMgr.createTcpServer(new AsyncConfig(), listener, sslFactory);
XFuture<Void> future = server.start(new InetSocketAddress(8443));
Assert.assertFalse(future.isDone());
mockJdk.setThread(Thread.currentThread());
mockJdk.fireSelector();
future.get(2, TimeUnit.SECONDS);
BufferPool pool = new TwoPools("p1", new SimpleMeterRegistry());
SSLEngine clientSsl = sslFactory.createEngineForSocket();
SSLMetrics sslMetrics = new SSLMetrics("", meters);
clientSslParser = AsyncSSLFactory.create("svr", clientSsl, pool, sslMetrics);
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());
}
use of org.webpieces.ssl.api.dto.SslAction in project webpieces by deanhiller.
the class TestSslBasicSvr 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