List of usage examples for io.netty.handler.ssl.util SelfSignedCertificate SelfSignedCertificate
public SelfSignedCertificate() throws CertificateException
From source file:com.topsec.bdc.platform.api.test.http.cors.HttpCorsServer.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 a2 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 HttpCorsServerInitializer(sslCtx)); b.bind(PORT).sync().channel().closeFuture().sync(); } finally { bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
From source file:com.topsec.bdc.platform.api.test.http.file.HttpStaticFileServer.java
License:Apache License
public static void main(String[] args) throws Exception { // Configure SSL. final SslContext sslCtx; if (SSL) {/* w ww . j ava 2 s . com*/ SelfSignedCertificate ssc = new SelfSignedCertificate(); sslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).sslProvider(SslProvider.JDK) .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 HttpStaticFileServerInitializer(sslCtx)); Channel ch = b.bind(PORT).sync().channel(); System.err.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:com.topsec.bdc.platform.api.test.http.helloworld.HttpHelloWorldServer.java
License:Apache License
public static void main(String[] args) throws Exception { // Configure SSL. final SslContext sslCtx; if (SSL) {/* ww w. j a va 2s. co m*/ SelfSignedCertificate ssc = new SelfSignedCertificate(); sslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build(); } else { sslCtx = null; } // Configure the server. EventLoopGroup bossGroup = new NioEventLoopGroup(1); EventLoopGroup workerGroup = new NioEventLoopGroup(); try { ServerBootstrap b = new ServerBootstrap(); b.option(ChannelOption.SO_BACKLOG, 1024); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .handler(new LoggingHandler(LogLevel.INFO)) .childHandler(new HttpHelloWorldServerInitializer(sslCtx)); Channel ch = b.bind(PORT).sync().channel(); System.err.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:com.topsec.bdc.platform.api.test.http.snoop.HttpSnoopServer.java
License:Apache License
public static void main(String[] args) throws Exception { // Configure SSL. final SslContext sslCtx; if (SSL) {/*from w w w. ja v a 2 s . c o m*/ SelfSignedCertificate ssc = new SelfSignedCertificate(); sslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build(); } else { sslCtx = null; } // Configure the server. 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 HttpSnoopServerInitializer(sslCtx)); Channel ch = b.bind(PORT).sync().channel(); System.err.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:com.topsec.bdc.platform.api.test.http.upload.HttpUploadServer.java
License:Apache License
public static void main(String[] args) throws Exception { // Configure SSL. final SslContext sslCtx; if (SSL) {//from ww w . j a v a 2s .c o m 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); b.channel(NioServerSocketChannel.class); b.handler(new LoggingHandler(LogLevel.INFO)); b.childHandler(new HttpUploadServerInitializer(sslCtx)); Channel ch = b.bind(PORT).sync().channel(); System.err.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:com.topsec.bdc.platform.api.test.http.websocketx.benchmarkserver.WebSocketServer.java
License:Apache License
public static void main(String[] args) throws Exception { // Configure SSL. final SslContext sslCtx; if (SSL) {/* w w w . j ava 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) .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:com.topsec.bdc.platform.api.test.http.websocketx.server.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 va 2 s . c o m 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 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:com.vela.iot.active.netty.http2.server.Http2Server.java
License:Apache License
public static void main(String[] args) throws Exception { // Configure SSL. final SslContext sslCtx; if (SSL) {/*from ww w. j a v a 2s.c o m*/ SslProvider provider = OpenSsl.isAlpnSupported() ? SslProvider.OPENSSL : SslProvider.JDK; SelfSignedCertificate ssc = new SelfSignedCertificate(); sslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).sslProvider(provider) /* * NOTE: the cipher filter may not include all ciphers * required by the HTTP/2 specification. Please refer to the * HTTP/2 specification for cipher requirements. */ .ciphers(Http2SecurityUtil.CIPHERS, SupportedCipherSuiteFilter.INSTANCE) .applicationProtocolConfig(new ApplicationProtocolConfig(Protocol.ALPN, // NO_ADVERTISE is currently the only mode // supported by both OpenSsl and JDK // providers. SelectorFailureBehavior.NO_ADVERTISE, // ACCEPT is currently the only mode // supported by both OpenSsl and JDK // providers. SelectedListenerFailureBehavior.ACCEPT, ApplicationProtocolNames.HTTP_2, ApplicationProtocolNames.HTTP_1_1)) .build(); } else { sslCtx = null; } // Configure the server. EventLoopGroup bossGroup = new NioEventLoopGroup(1); EventLoopGroup workerGroup = new NioEventLoopGroup(7); try { LastInboundHandler serverLastInboundHandler = new SharableLastInboundHandler(); ServerBootstrap b = new ServerBootstrap(); // BACKLOG?ServerSocket?????1Java50 b.option(ChannelOption.SO_BACKLOG, 1024); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .handler(new LoggingHandler(LogLevel.INFO)) .childHandler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel ch) throws Exception { ChannelPipeline p = ch.pipeline(); p.addLast(new Http2Codec(true, serverLastInboundHandler)); //p.addLast(new HttpContentCompressor(1)); p.addLast(new HelloWorldHttp2HandlerBuilder().build()); } }); Channel ch = b.bind(HOST, PORT).sync().channel(); System.err.println("Open your HTTP/2-enabled web browser and navigate to " + (SSL ? "https" : "http") + "://127.0.0.1:" + PORT + '/'); ch.closeFuture().sync(); } finally { bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
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 {/* www. j a v a 2s. c om*/ 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);//from w w w . j a v a 2 s . 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(); } }