@Override public String certificatePath() { return certificate.certificate().getAbsolutePath(); }
/** * Returns the self-signed certificate file. */ public File certificateFile() { ensureCertificate(); return certificate.certificate(); }
public static void main(String[] args) throws Exception { if (args.length != 1) { System.err.println("Please give port as argument"); System.exit(1); } int port = Integer.parseInt(args[0]); SelfSignedCertificate cert = new SelfSignedCertificate(); SslContext context = SslContext.newServerContext( cert.certificate(), cert.privateKey()); final SecureChatServer endpoint = new SecureChatServer(context); ChannelFuture future = endpoint.start(new InetSocketAddress(port)); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { endpoint.destroy(); } }); future.channel().closeFuture().syncUninterruptibly(); } }
/** * Configures SSL or TLS of this {@link VirtualHost} with an auto-generated self-signed certificate. * <strong>Note:</strong> You should never use this in production but only for a testing purpose. * * @throws CertificateException if failed to generate a self-signed certificate */ public B tlsSelfSigned() throws SSLException, CertificateException { final SelfSignedCertificate ssc = new SelfSignedCertificate(defaultHostname); return tls(ssc.certificate(), ssc.privateKey()); }
public static SslContext build(SslProvider sslProvider) throws CertificateException, SSLException { SelfSignedCertificate ssc = new SelfSignedCertificate(); return SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()) .sslProvider(sslProvider) .build(); }
certFile = ssc.certificate(); keyFile = ssc.privateKey(); } catch (CertificateException e) {
@Test void shouldLoadPEMCertificates() throws Throwable { // Given SelfSignedCertificate cert = new SelfSignedCertificate( "example.com" ); PkiUtils certs = new PkiUtils(); File pemCertificate = cert.certificate(); // When Certificate[] certificates = certs.loadCertificates( pemCertificate ); // Then assertThat(certificates.length, equalTo(1)); }
try { SelfSignedCertificate ssc = new SelfSignedCertificate(); return Optional.of(SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build()); } catch (CertificateException | SSLException e) { throw new SslConfigurationException("Encountered an error while building a self signed certificate", e);
/** * For backwards-compatibility reasons, we support both PEM-encoded certificates *and* raw binary files containing * the certificate data. */ @Test void shouldLoadBinaryCertificates() throws Throwable { // Given SelfSignedCertificate cert = new SelfSignedCertificate( "example.com" ); PkiUtils certs = new PkiUtils(); File cPath = testDirectory.file( "certificate" ); assertTrue( cPath.createNewFile() ); byte[] raw = certs.loadCertificates(cert.certificate())[0].getEncoded(); try ( FileChannel ch = FileChannel.open( cPath.toPath(), WRITE ) ) { FileUtils.writeAll( ch, ByteBuffer.wrap( raw ) ); } // When Certificate[] certificates = certs.loadCertificates( cPath ); // Then assertThat( certificates.length, equalTo( 1 ) ); }
private SslContext newSslContext() throws Exception { return GrpcSslContexts.forServer(ssc.certificate(), ssc.privateKey()) .applicationProtocolConfig(ALPN) .trustManager(TestUtils.loadCert("ca.pem")) .build(); } };
sslCtx = io.netty.handler.ssl.SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()) .sslProvider(provider)
sslCtx = io.netty.handler.ssl.SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()) .sslProvider(provider)
SelfSignedCertificate selfSignedCertificate = new SelfSignedCertificate(); return SslContextBuilder .forServer(selfSignedCertificate.certificate(), selfSignedCertificate.privateKey()) .sslProvider(SslProvider.JDK) .clientAuth(ClientAuth.OPTIONAL)
@Override public String certificatePath() { return certificate.certificate().getAbsolutePath(); }
@Override protected void initServer() throws Exception { SelfSignedCertificate cert = new SelfSignedCertificate(); SslContextBuilder builder = SslContextBuilder.forServer(cert.certificate(), cert.privateKey()); this.reactorHandler = createHttpHandlerAdapter(); this.reactorServer = reactor.netty.http.server.HttpServer.create() .host(getHost()) .port(getPort()) .secure(spec -> spec.sslContext(builder).defaultConfiguration(DefaultConfigurationType.TCP)); }
@Override protected ManagedChannel createChannel() { try { final int port = server.httpsPort(); return OkHttpChannelBuilder .forAddress("localhost", port) .useTransportSecurity() .maxInboundMessageSize(16 * 1024 * 1024) .connectionSpec(ConnectionSpec.MODERN_TLS) .overrideAuthority("example.com:" + port) .sslSocketFactory(TestUtils.newSslSocketFactoryForCa( Platform.get().getProvider(), ssc.certificate())) .build(); } catch (Exception ex) { throw new RuntimeException(ex); } }
@Override public void startup() throws Exception { GameServerConfigService gameServerConfigService = LocalMananger.getInstance().getLocalSpringServiceManager().getGameServerConfigService(); GameServerConfig gameServerConfig = gameServerConfigService.getGameServerConfig(); boolean webSocketSSLFlag = gameServerConfig.isWebSockectSSLFlag(); if(webSocketSSLFlag){ SelfSignedCertificate ssc = new SelfSignedCertificate(); sslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build(); } }
SelfSignedCertificate selfSignedCertificate = new SelfSignedCertificate(); return SslContextBuilder .forServer(selfSignedCertificate.certificate(), selfSignedCertificate.privateKey()) .sslProvider(SslProvider.JDK) .clientAuth(ClientAuth.OPTIONAL)
SelfSignedCertificate selfSignedCertificate = new SelfSignedCertificate(); return SslContextBuilder .forServer(selfSignedCertificate.certificate(), selfSignedCertificate.privateKey()) .sslProvider(SslProvider.JDK) .clientAuth(ClientAuth.OPTIONAL)
public void initChannelInitializer() throws CertificateException, SSLException { GameServerConfigService gameServerConfigService = LocalMananger.getInstance().getLocalSpringServiceManager().getGameServerConfigService(); GameServerConfig gameServerConfig = gameServerConfigService.getGameServerConfig(); NetWebSocketServerConfig netWebSocketServerConfig = gameServerConfigService.getNetWebSocketServerConfig(); if(netWebSocketServerConfig != null){ SdWebSocketServerConfig sdWebSocketServerConfig = netWebSocketServerConfig.getSdWebSocketServerConfig(); if(sdWebSocketServerConfig != null) { boolean sslFlag = sdWebSocketServerConfig.isSsl(); if(sslFlag) { SelfSignedCertificate ssc = new SelfSignedCertificate(); sslContext = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build(); } } } nettyTcpChannelInitializer = new GameNetProtoMessageTcpServerChannelInitializer(); nettyUdpChannelInitializer = new GameNetProtoMessageUdpServerChannelInitializer(); rpcChannelInitializer = new GameNetRPCChannleInitializer(); proxyChannleInitializer = new ProxyTcpFrontedChannelInitializer(); httpChannelInitialier = new GameNetProtoMessageHttpServerChannelInitializer(); webSocketChannelInitialer = new GameNetProtoMessageWebSocketServerChannelInitializer(sslContext); }