Search in sources :

Example 1 with SSLMetrics

use of org.webpieces.ssl.api.SSLMetrics 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());
}
Also used : TwoPools(org.webpieces.data.api.TwoPools) InetSocketAddress(java.net.InetSocketAddress) SSLEngine(javax.net.ssl.SSLEngine) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) AsyncConfig(org.webpieces.asyncserver.api.AsyncConfig) AsyncServerManager(org.webpieces.asyncserver.api.AsyncServerManager) SslAction(org.webpieces.ssl.api.dto.SslAction) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) ConnectionOpen(org.webpieces.nio.api.mocks.MockAsyncListener.ConnectionOpen) BufferPool(org.webpieces.data.api.BufferPool) DirectExecutor(org.webpieces.util.threading.DirectExecutor) SSLMetrics(org.webpieces.ssl.api.SSLMetrics) Before(org.junit.Before)

Example 2 with SSLMetrics

use of org.webpieces.ssl.api.SSLMetrics in project webpieces by deanhiller.

the class TestSslCloseSvr method createClientParser.

private SSLParser createClientParser() {
    SSLEngineFactoryForTestOld sslFactory = new SSLEngineFactoryForTestOld();
    BufferPool pool = new TwoPools("p1", new SimpleMeterRegistry());
    SSLEngine clientSsl = sslFactory.createEngineForSocket();
    SSLMetrics sslMetrics = new SSLMetrics("", new SimpleMeterRegistry());
    SSLParser clientSslParser1 = AsyncSSLFactory.create("svr", clientSsl, pool, sslMetrics);
    return clientSslParser1;
}
Also used : SSLParser(org.webpieces.ssl.api.SSLParser) BufferPool(org.webpieces.data.api.BufferPool) TwoPools(org.webpieces.data.api.TwoPools) SSLEngine(javax.net.ssl.SSLEngine) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) SSLMetrics(org.webpieces.ssl.api.SSLMetrics)

Example 3 with SSLMetrics

use of org.webpieces.ssl.api.SSLMetrics in project webpieces by deanhiller.

the class TestSslCloseClient method createSslSvrParser.

public static SSLParser createSslSvrParser() throws GeneralSecurityException, IOException {
    MockSSLEngineFactory sslFactory = new MockSSLEngineFactory();
    BufferPool pool = new TwoPools("pSvr", new SimpleMeterRegistry());
    SSLEngine svrSsl = sslFactory.createEngineForServerSocket();
    SSLMetrics metrics = new SSLMetrics("", new SimpleMeterRegistry());
    return AsyncSSLFactory.create("svr", svrSsl, pool, metrics);
}
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) SSLMetrics(org.webpieces.ssl.api.SSLMetrics)

Example 4 with SSLMetrics

use of org.webpieces.ssl.api.SSLMetrics in project webpieces by deanhiller.

the class SslChannelService method createTCPChannel.

@Override
public TCPChannel createTCPChannel(String id, SSLEngine engine) {
    if (engine == null || id == null)
        throw new IllegalArgumentException("no arguments can be null");
    Function<SslListener, AsyncSSLEngine> function = l -> AsyncSSLFactory.create(id, engine, pool, l, sslMetrics);
    TCPChannel channel = mgr.createTCPChannel(id);
    SslTCPChannel sslChannel = new SslTCPChannel(function, channel, sslMetrics);
    return sslChannel;
}
Also used : BufferPool(org.webpieces.data.api.BufferPool) DatagramChannel(org.webpieces.nio.api.channels.DatagramChannel) AsyncSSLFactory(org.webpieces.ssl.api.AsyncSSLFactory) TCPServerChannel(org.webpieces.nio.api.channels.TCPServerChannel) ConnectionListener(org.webpieces.nio.api.handlers.ConnectionListener) Function(java.util.function.Function) ChannelManager(org.webpieces.nio.api.ChannelManager) SSLMetrics(org.webpieces.ssl.api.SSLMetrics) SSLEngine(javax.net.ssl.SSLEngine) UDPChannel(org.webpieces.nio.api.channels.UDPChannel) AsyncSSLEngine(org.webpieces.ssl.api.AsyncSSLEngine) DatagramListener(org.webpieces.nio.api.handlers.DatagramListener) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) SSLEngineFactory(org.webpieces.nio.api.SSLEngineFactory) SslListener(org.webpieces.ssl.api.SslListener) TCPChannel(org.webpieces.nio.api.channels.TCPChannel) AsyncSSLEngine(org.webpieces.ssl.api.AsyncSSLEngine) TCPChannel(org.webpieces.nio.api.channels.TCPChannel) SslListener(org.webpieces.ssl.api.SslListener)

Aggregations

SSLEngine (javax.net.ssl.SSLEngine)4 BufferPool (org.webpieces.data.api.BufferPool)4 SSLMetrics (org.webpieces.ssl.api.SSLMetrics)4 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)3 TwoPools (org.webpieces.data.api.TwoPools)3 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)2 InetSocketAddress (java.net.InetSocketAddress)1 Function (java.util.function.Function)1 Before (org.junit.Before)1 AsyncConfig (org.webpieces.asyncserver.api.AsyncConfig)1 AsyncServerManager (org.webpieces.asyncserver.api.AsyncServerManager)1 ChannelManager (org.webpieces.nio.api.ChannelManager)1 SSLEngineFactory (org.webpieces.nio.api.SSLEngineFactory)1 DatagramChannel (org.webpieces.nio.api.channels.DatagramChannel)1 TCPChannel (org.webpieces.nio.api.channels.TCPChannel)1 TCPServerChannel (org.webpieces.nio.api.channels.TCPServerChannel)1 UDPChannel (org.webpieces.nio.api.channels.UDPChannel)1 ConnectionListener (org.webpieces.nio.api.handlers.ConnectionListener)1 DatagramListener (org.webpieces.nio.api.handlers.DatagramListener)1 ConnectionOpen (org.webpieces.nio.api.mocks.MockAsyncListener.ConnectionOpen)1