Example usage for io.netty.handler.ssl.util SelfSignedCertificate privateKey

List of usage examples for io.netty.handler.ssl.util SelfSignedCertificate privateKey

Introduction

In this page you can find the example usage for io.netty.handler.ssl.util SelfSignedCertificate privateKey.

Prototype

File privateKey

To view the source code for io.netty.handler.ssl.util SelfSignedCertificate privateKey.

Click Source Link

Usage

From source file:com.vmware.dcp.common.http.netty.NettyHttpServiceClientTest.java

License:Open Source License

@Before
public void setUp() throws Exception {
    CommandLineArgumentParser.parseFromProperties(this);
    this.host = VerificationHost.create(0, null);
    CommandLineArgumentParser.parseFromProperties(this.host);

    this.host.setMaintenanceIntervalMicros(
            TimeUnit.MILLISECONDS.toMicros(VerificationHost.FAST_MAINT_INTERVAL_MILLIS));

    this.client = (NettyHttpServiceClient) NettyHttpServiceClient.create(getClass().getCanonicalName(),
            Executors.newFixedThreadPool(4), Executors.newScheduledThreadPool(1), this.host);

    SSLContext clientContext = SSLContext.getInstance(ServiceClient.TLS_PROTOCOL_NAME);
    clientContext.init(null, InsecureTrustManagerFactory.INSTANCE.getTrustManagers(), null);
    this.client.setSSLContext(clientContext);
    this.host.setClient(this.client);

    SelfSignedCertificate ssc = new SelfSignedCertificate();
    this.host.setCertificateFileReference(ssc.certificate().toURI());
    this.host.setPrivateKeyFileReference(ssc.privateKey().toURI());

    try {/* ww w  .  ja v  a  2  s . co  m*/
        this.host.start();
    } catch (Throwable e) {
        throw new Exception(e);
    }

    this.host.setStressTest(this.host.isStressTest);
}

From source file:com.vmware.xenon.common.http.netty.NettyHttpServiceClientTest.java

License:Open Source License

@BeforeClass
public static void setUpOnce() throws Throwable {
    HOST = VerificationHost.create(0);/*  ww w . j  a va2s .  c  o m*/
    HOST.setAuthorizationEnabled(ENABLE_AUTH);
    HOST.setRequestPayloadSizeLimit(1024 * 512);
    HOST.setResponsePayloadSizeLimit(1024 * 512);

    CommandLineArgumentParser.parseFromProperties(HOST);
    HOST.setMaintenanceIntervalMicros(
            TimeUnit.MILLISECONDS.toMicros(VerificationHost.FAST_MAINT_INTERVAL_MILLIS));

    ServiceClient client = NettyHttpServiceClient.create(NettyHttpServiceClientTest.class.getSimpleName(),
            Executors.newFixedThreadPool(4), Executors.newScheduledThreadPool(1), HOST);

    SSLContext clientContext = SSLContext.getInstance(ServiceClient.TLS_PROTOCOL_NAME);
    clientContext.init(null, InsecureTrustManagerFactory.INSTANCE.getTrustManagers(), null);
    client.setSSLContext(clientContext);
    HOST.setClient(client);

    SelfSignedCertificate ssc = new SelfSignedCertificate();
    HOST.setCertificateFileReference(ssc.certificate().toURI());
    HOST.setPrivateKeyFileReference(ssc.privateKey().toURI());

    try {
        HOST.start();
        CommandLineArgumentParser.parseFromProperties(HOST);
    } catch (Throwable e) {
        throw new RuntimeException(e);
    }

    if (ENABLE_AUTH) {
        // Create example user auth related objects
        HOST.setSystemAuthorizationContext();
        HOST.testStart(1);
        AuthorizationSetupHelper.create().setHost(HOST).setUserEmail(SAMPLE_EMAIL)
                .setUserPassword(SAMPLE_PASSWORD).setUserSelfLink(SAMPLE_EMAIL).setIsAdmin(true)
                .setCompletion(HOST.getCompletion()).start();
        HOST.testWait();
        HOST.resetAuthorizationContext();
    }

}

From source file:com.vmware.xenon.common.test.VerificationHost.java

License:Open Source License

public static void createAndAttachSSLClient(ServiceHost h) throws Throwable {
    // we create a random userAgent string to validate host to host communication when
    // the client appears to be from an external, non-Xenon source.
    ServiceClient client = NettyHttpServiceClient.create(UUID.randomUUID().toString(), null,
            h.getScheduledExecutor(), h);

    SSLContext clientContext = SSLContext.getInstance(ServiceClient.TLS_PROTOCOL_NAME);
    clientContext.init(null, InsecureTrustManagerFactory.INSTANCE.getTrustManagers(), null);
    client.setSSLContext(clientContext);
    h.setClient(client);/*from   w w w.ja  v  a 2  s  . c  om*/

    SelfSignedCertificate ssc = new SelfSignedCertificate();
    h.setCertificateFileReference(ssc.certificate().toURI());
    h.setPrivateKeyFileReference(ssc.privateKey().toURI());
}

From source file:com.vmware.xenon.common.TestServiceHost.java

License:Open Source License

@Test
public void httpScheme() throws Throwable {
    setUp(true);//  ww  w  . ja  v a2s.com

    // SSL config for https
    SelfSignedCertificate ssc = new SelfSignedCertificate();
    this.host.setCertificateFileReference(ssc.certificate().toURI());
    this.host.setPrivateKeyFileReference(ssc.privateKey().toURI());

    assertEquals("before starting, scheme is NONE", ServiceHost.HttpScheme.NONE,
            this.host.getCurrentHttpScheme());

    this.host.setPort(0);
    this.host.setSecurePort(0);
    this.host.start();

    ServiceRequestListener httpListener = this.host.getListener();
    ServiceRequestListener httpsListener = this.host.getSecureListener();

    assertTrue("http listener should be on", httpListener.isListening());
    assertTrue("https listener should be on", httpsListener.isListening());
    assertEquals(ServiceHost.HttpScheme.HTTP_AND_HTTPS, this.host.getCurrentHttpScheme());
    assertTrue("public uri scheme should be HTTP", this.host.getPublicUri().getScheme().equals("http"));

    httpsListener.stop();
    assertTrue("http listener should be on ", httpListener.isListening());
    assertFalse("https listener should be off", httpsListener.isListening());
    assertEquals(ServiceHost.HttpScheme.HTTP_ONLY, this.host.getCurrentHttpScheme());
    assertTrue("public uri scheme should be HTTP", this.host.getPublicUri().getScheme().equals("http"));

    httpListener.stop();
    assertFalse("http listener should be off", httpListener.isListening());
    assertFalse("https listener should be off", httpsListener.isListening());
    assertEquals(ServiceHost.HttpScheme.NONE, this.host.getCurrentHttpScheme());

    // re-start listener even host is stopped, verify getCurrentHttpScheme only
    httpsListener.start(0, ServiceHost.LOOPBACK_ADDRESS);
    assertFalse("http listener should be off", httpListener.isListening());
    assertTrue("https listener should be on", httpsListener.isListening());
    assertEquals(ServiceHost.HttpScheme.HTTPS_ONLY, this.host.getCurrentHttpScheme());
    httpsListener.stop();

    this.host.stop();
    // set HTTP port to disabled, restart host. Verify scheme is HTTPS only. We must
    // set both HTTP and secure port, to null out the listeners from the host instance.
    this.host.setPort(ServiceHost.PORT_VALUE_LISTENER_DISABLED);
    this.host.setSecurePort(0);
    VerificationHost.createAndAttachSSLClient(this.host);
    this.host.start();

    httpListener = this.host.getListener();
    httpsListener = this.host.getSecureListener();

    assertTrue("http listener should be null, default port value set to disabled", httpListener == null);
    assertTrue("https listener should be on", httpsListener.isListening());
    assertEquals(ServiceHost.HttpScheme.HTTPS_ONLY, this.host.getCurrentHttpScheme());
    assertTrue("public uri scheme should be HTTPS", this.host.getPublicUri().getScheme().equals("https"));
}

From source file:com.xxx.netty.run.SecureChatServer.java

License:Apache License

@SuppressWarnings("resource")
public static void main(String[] args) throws Exception {
    ApplicationContext context = new ClassPathXmlApplicationContext("classpath*:root-context.xml");// loading
    //jedis = context.getBean(RedisInitBean.class).getSingletonInstance();
    SecureChatServer chatServer = context.getBean(SecureChatServer.class);
    // SelfSignedCertificate????
    SelfSignedCertificate ssc = new SelfSignedCertificate();
    // ???//from w  ww. ja  v a 2s . co  m
    SslContext sslCtx = SslContext.newServerContext(ssc.certificate(), ssc.privateKey());
    EventLoopGroup bossGroup = new NioEventLoopGroup(1);
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {
        ServerBootstrap serverBootstrap = new ServerBootstrap();// ?????
        serverBootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
                .handler(new LoggingHandler(LogLevel.INFO))
                .childHandler(new SecureChatServerInitializer(sslCtx));
        if (null != args && args.length > 1 && args[0].matches("\\d")) {
            chatServer.PORT = Integer.parseInt(args[0]);
        }
        LOGGER.debug("SSL TCP server started on port:{}", chatServer.PORT);
        serverBootstrap.bind(chatServer.PORT).sync().channel().closeFuture().sync();

    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
        context = null;
    }
}

From source file:com.yahoo.ads.pb.network.netty.NettyPistachioServer.java

License:Open Source License

public static void main(String[] args) throws Exception {
    // Configure SSL.
    final SslContext sslCtx;
    if (SSL) {//from ww w.  j  ava  2 s  . c o  m
        SelfSignedCertificate ssc = new SelfSignedCertificate();
        sslCtx = SslContext.newServerContext(ssc.certificate(), ssc.privateKey());
    } else {
        sslCtx = null;
    }

    EventLoopGroup bossGroup = new NioEventLoopGroup(1);
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {
        ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
                .handler(new LoggingHandler(LogLevel.INFO))
                .childHandler(new NettyPistachioServerInitializer(sslCtx));

        b.bind(PORT).sync().channel().closeFuture().sync();
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}

From source file:com.zy.learning.netty.websocket.WebSocketServer.java

License:Apache License

public static void main(String[] args) throws Exception {
    // Configure SSL.
    final SslContext sslCtx;
    if (SSL) {/*from w  w  w  .j a  v a 2  s  .c om*/
        SelfSignedCertificate ssc = new SelfSignedCertificate();
        sslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build();
    } else {
        sslCtx = null;
    }

    EventLoopGroup bossGroup = new NioEventLoopGroup(1);
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {
        ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
                .handler(new LoggingHandler(LogLevel.INFO)).childHandler(new ProtocolDetectorInitializer());
        //.childHandler(new WebSocketServerInitializer(sslCtx));

        Channel ch = b.bind(PORT).sync().channel();

        System.out.println("Open your web browser and navigate to " + (SSL ? "https" : "http") + "://127.0.0.1:"
                + PORT + '/');

        ch.closeFuture().sync();
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}

From source file:connexion.ServerSocket.java

public static void bind(int port) throws InterruptedException, SSLException, CertificateException {
    // Configure SSL.
    SelfSignedCertificate ssc = new SelfSignedCertificate();
    SslContext sslCtx = SslContext.newServerContext(ssc.certificate(), ssc.privateKey());

    // Configure Group
    bossGroup = new NioEventLoopGroup(1);
    workerGroup = new NioEventLoopGroup();
    ServerBootstrap b = new ServerBootstrap();
    b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
            .handler(new LoggingHandler(LogLevel.INFO)).childHandler(new ServerInitializer(sslCtx));

    b.bind(port).sync().channel().closeFuture().sync();
}

From source file:de.dfki.kiara.netty.AbstractTransport.java

License:Open Source License

protected SslContext createServerSslContext() throws CertificateException, SSLException {
    if (SSL) {//  ww  w  .j a  v a2  s. c om
        SelfSignedCertificate ssc = new SelfSignedCertificate();
        return SslContext.newServerContext(ssc.certificate(), ssc.privateKey());
    } else {
        return null;
    }
}

From source file:de.ocarthon.core.network.tcp.TCPServer.java

License:Apache License

public void initBootstrap() throws CertificateException, SSLException {
    SelfSignedCertificate cert = new SelfSignedCertificate();
    this.serverSslContext = SslContext.newServerContext(cert.certificate(), cert.privateKey());

    this.bootstrap = new ServerBootstrap();
    this.bootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
            .childHandler(new ChannelInitializer<Channel>() {
                @Override/*from ww w .j  a  va2  s. c o m*/
                protected void initChannel(Channel ch) throws Exception {
                    ChannelPipeline p = ch.pipeline();

                    if (useTls) {
                        p.addLast(serverSslContext.newHandler(ch.alloc()));
                    }

                    p.addLast(lengthPrepender);
                    p.addLast(new LengthFieldBasedFrameDecoder(65535, 0, lengthBytes, 0, lengthBytes));

                    if (pipelineCodec != null) {
                        pipelineCodec.accept(p);
                    }

                    p.addLast(handler);
                }
            });
}