Search in sources :

Example 1 with BufferedFuture

use of org.webpieces.ssl.api.MockSslListener.BufferedFuture in project webpieces by deanhiller.

the class TestHandshakeBackpressure method testTransferOnePacketsForOneBigOneEncrypted.

// @Test
public void testTransferOnePacketsForOneBigOneEncrypted() throws GeneralSecurityException, IOException, InterruptedException, ExecutionException, TimeoutException {
    finishHandshake();
    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 = clientEngine.feedPlainPacket(b);
    List<BufferedFuture> encrypted = clientListener.getEncrypted();
    // results in two ssl packets instead of the one that was fed in..
    Assert.assertEquals(2, encrypted.size());
    encrypted.get(0).future.complete(null);
    Assert.assertFalse(future.isDone());
    encrypted.get(1).future.complete(null);
    future.get(2, TimeUnit.SECONDS);
    ByteBuffer single = combine(encrypted);
    XFuture<Void> svrFut1 = svrEngine.feedEncryptedPacket(single);
    // result in two decrypted as packet was large..
    List<BufferedFuture> toClient = svrListener.getDecrypted();
    toClient.get(0).future.complete(null);
    Assert.assertFalse(svrFut1.isDone());
    toClient.get(1).future.complete(null);
    svrFut1.get(2, TimeUnit.SECONDS);
    Assert.assertEquals(17000, toClient.get(0).engineToSocketData.remaining() + toClient.get(1).engineToSocketData.remaining());
}
Also used : BufferedFuture(org.webpieces.ssl.api.MockSslListener.BufferedFuture) ByteBuffer(java.nio.ByteBuffer)

Example 2 with BufferedFuture

use of org.webpieces.ssl.api.MockSslListener.BufferedFuture in project webpieces by deanhiller.

the class TestHandshakeBackpressure method testCombineBuffers.

// @Test
public void testCombineBuffers() throws InterruptedException, ExecutionException, TimeoutException {
    ByteBuffer combine = combine(buffers);
    XFuture<Void> svrFut = svrEngine.feedEncryptedPacket(combine);
    List<BufferedFuture> toClientBuffers = svrListener.getHandshake();
    toClientBuffers.get(0).future.complete(null);
    Assert.assertFalse(svrFut.isDone());
    toClientBuffers.get(1).future.complete(null);
    svrFut.get(2, TimeUnit.SECONDS);
    Assert.assertEquals(ConnectionState.CONNECTED, svrEngine.getConnectionState());
    Assert.assertTrue(svrListener.connected);
    ByteBuffer toCli = combine(toClientBuffers);
    XFuture<Void> cliFut2 = clientEngine.feedEncryptedPacket(toCli);
    Assert.assertEquals(ConnectionState.CONNECTED, clientEngine.getConnectionState());
    Assert.assertTrue(clientListener.connected);
    cliFut2.get(2, TimeUnit.SECONDS);
}
Also used : BufferedFuture(org.webpieces.ssl.api.MockSslListener.BufferedFuture) ByteBuffer(java.nio.ByteBuffer)

Example 3 with BufferedFuture

use of org.webpieces.ssl.api.MockSslListener.BufferedFuture in project webpieces by deanhiller.

the class TestHandshakeBackpressure method combine.

private ByteBuffer combine(List<BufferedFuture> buffersToSend) {
    int size = 0;
    for (BufferedFuture b : buffersToSend) {
        size += b.engineToSocketData.remaining();
    }
    ByteBuffer buf = ByteBuffer.allocate(size);
    for (BufferedFuture b : buffersToSend) {
        buf.put(b.engineToSocketData);
    }
    buf.flip();
    return buf;
}
Also used : BufferedFuture(org.webpieces.ssl.api.MockSslListener.BufferedFuture) ByteBuffer(java.nio.ByteBuffer)

Example 4 with BufferedFuture

use of org.webpieces.ssl.api.MockSslListener.BufferedFuture in project webpieces by deanhiller.

the class TestSplitBackpressure 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");
    SSLMetrics metrics = new SSLMetrics("", new SimpleMeterRegistry());
    MockSSLEngineFactory sslEngineFactory = new MockSSLEngineFactory();
    BufferPool pool = new TwoPools("p1", new SimpleMeterRegistry());
    SSLEngine client = sslEngineFactory.createEngineForSocket();
    SSLEngine svr = sslEngineFactory.createEngineForServerSocket();
    clientEngine = AsyncSSLFactory.create("client", client, pool, clientListener, metrics);
    svrEngine = AsyncSSLFactory.create("svr", svr, pool, svrListener, metrics);
    Assert.assertEquals(ConnectionState.NOT_STARTED, clientEngine.getConnectionState());
    Assert.assertEquals(ConnectionState.NOT_STARTED, svrEngine.getConnectionState());
    XFuture<Void> clientFuture = clientEngine.beginHandshake();
    Assert.assertEquals(ConnectionState.CONNECTING, clientEngine.getConnectionState());
    BufferedFuture toSend = clientListener.getSingleHandshake();
    assertFutureJustResolved(clientFuture, toSend);
    List<ByteBuffer> split = split(toSend.engineToSocketData);
    // TODO: feed in this packet as two and resolving 'both' resolves the future returned
    XFuture<Void> svrFuture = svrEngine.feedEncryptedPacket(split.get(0));
    Assert.assertEquals(ConnectionState.CONNECTING, svrEngine.getConnectionState());
    XFuture<Void> svrFuture2 = svrEngine.feedEncryptedPacket(split.get(1));
    Assert.assertEquals(ConnectionState.CONNECTING, svrEngine.getConnectionState());
    BufferedFuture toSend2 = svrListener.getSingleHandshake();
    Assert.assertFalse(svrFuture.isDone());
    Assert.assertFalse(svrFuture2.isDone());
    toSend2.future.complete(null);
    svrFuture.get(2, TimeUnit.SECONDS);
    svrFuture2.get(2, TimeUnit.SECONDS);
    // TODO: feed 2 halves of this packet in and test resolution of future
    List<ByteBuffer> split2 = split(toSend2.engineToSocketData);
    XFuture<Void> clientFuture1 = clientEngine.feedEncryptedPacket(split2.get(0));
    Assert.assertEquals(ConnectionState.CONNECTING, clientEngine.getConnectionState());
    XFuture<Void> clientFuture2 = clientEngine.feedEncryptedPacket(split2.get(1));
    List<BufferedFuture> buffers = clientListener.getHandshake();
    buffers.get(0).future.complete(null);
    buffers.get(1).future.complete(null);
    Assert.assertFalse(clientFuture1.isDone());
    Assert.assertFalse(clientFuture2.isDone());
    buffers.get(2).future.complete(null);
    clientFuture1.get(2, TimeUnit.SECONDS);
    clientFuture2.get(2, TimeUnit.SECONDS);
    XFuture<Void> fut1 = svrEngine.feedEncryptedPacket(buffers.get(0).engineToSocketData);
    fut1.get(2, TimeUnit.SECONDS);
    XFuture<Void> fut2 = svrEngine.feedEncryptedPacket(buffers.get(1).engineToSocketData);
    Assert.assertEquals(ConnectionState.CONNECTING, clientEngine.getConnectionState());
    fut2.get(2, TimeUnit.SECONDS);
    XFuture<Void> fut3 = svrEngine.feedEncryptedPacket(buffers.get(2).engineToSocketData);
    Assert.assertEquals(ConnectionState.CONNECTED, svrEngine.getConnectionState());
    Assert.assertTrue(svrListener.connected);
    List<BufferedFuture> toClientBuffers = svrListener.getHandshake();
    toClientBuffers.get(0).future.complete(null);
    assertFutureJustResolved(fut3, toClientBuffers.get(1));
    XFuture<Void> cliFut = clientEngine.feedEncryptedPacket(toClientBuffers.get(0).engineToSocketData);
    Assert.assertEquals(ConnectionState.CONNECTING, clientEngine.getConnectionState());
    cliFut.get(2, TimeUnit.SECONDS);
    XFuture<Void> cliFut2 = clientEngine.feedEncryptedPacket(toClientBuffers.get(1).engineToSocketData);
    Assert.assertEquals(ConnectionState.CONNECTED, clientEngine.getConnectionState());
    Assert.assertTrue(clientListener.connected);
    cliFut2.get(2, TimeUnit.SECONDS);
}
Also used : BufferPool(org.webpieces.data.api.BufferPool) TwoPools(org.webpieces.data.api.TwoPools) SSLEngine(javax.net.ssl.SSLEngine) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) BufferedFuture(org.webpieces.ssl.api.MockSslListener.BufferedFuture) ByteBuffer(java.nio.ByteBuffer) Before(org.junit.Before)

Example 5 with BufferedFuture

use of org.webpieces.ssl.api.MockSslListener.BufferedFuture in project webpieces by deanhiller.

the class TestSplitBackpressure method combine.

private ByteBuffer combine(List<BufferedFuture> buffersToSend) {
    int size = 0;
    for (BufferedFuture b : buffersToSend) {
        size += b.engineToSocketData.remaining();
    }
    ByteBuffer buf = ByteBuffer.allocate(size);
    for (BufferedFuture b : buffersToSend) {
        buf.put(b.engineToSocketData);
    }
    buf.flip();
    return buf;
}
Also used : BufferedFuture(org.webpieces.ssl.api.MockSslListener.BufferedFuture) ByteBuffer(java.nio.ByteBuffer)

Aggregations

BufferedFuture (org.webpieces.ssl.api.MockSslListener.BufferedFuture)9 ByteBuffer (java.nio.ByteBuffer)8 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)2 SSLEngine (javax.net.ssl.SSLEngine)2 BufferPool (org.webpieces.data.api.BufferPool)2 TwoPools (org.webpieces.data.api.TwoPools)2 Before (org.junit.Before)1