@Override public String privateKeyPath() { return certificate.privateKey().getAbsolutePath(); }
/** * Returns the private key file of the self-signed certificate. */ public File privateKeyFile() { ensureCertificate(); return certificate.privateKey(); }
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(); }
final SelfSignedCertificate ssc = new SelfSignedCertificate(configuration.getString(CK_BIND_ADDRESS) + ":" + configuration.getString(CK_PORT)); certFile = ssc.certificate(); keyFile = ssc.privateKey(); } catch (CertificateException e) { final String msg = String.format(Locale.ENGLISH, "Problem creating a self-signed certificate for input [%s/%s].", input.getName(), input.getId());
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 private keys *and* raw binary files containing * the private key data */ @Test void shouldLoadBinaryPrivateKey() throws Throwable { // Given SelfSignedCertificate cert = new SelfSignedCertificate( "example.com" ); PkiUtils certs = new PkiUtils(); File keyFile = testDirectory.file( "certificate" ); assertTrue( keyFile.createNewFile() ); byte[] raw = certs.loadPrivateKey( cert.privateKey() ).getEncoded(); try ( FileChannel ch = FileChannel.open( keyFile.toPath(), WRITE ) ) { FileUtils.writeAll( ch, ByteBuffer.wrap( raw ) ); } // When PrivateKey pk = certs.loadPrivateKey( keyFile ); // Then assertNotNull( pk ); } }
private SslContext newSslContext() throws Exception { return GrpcSslContexts.forServer(ssc.certificate(), ssc.privateKey()) .applicationProtocolConfig(ALPN) .trustManager(TestUtils.loadCert("ca.pem")) .build(); } };
@Test void shouldLoadPEMPrivateKey() throws Throwable { // Given SelfSignedCertificate cert = new SelfSignedCertificate( "example.com" ); PkiUtils certs = new PkiUtils(); File privateKey = cert.privateKey(); // When PrivateKey pk = certs.loadPrivateKey( privateKey ); // Then assertNotNull( pk ); }
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 privateKeyPath() { return certificate.privateKey().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 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); }
@Override protected HttpServer customizeServerOptions(HttpServer server) { try { SslContext ctx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build(); return server.secure(ssl -> ssl.sslContext(ctx)); } catch (SSLException e) { throw new RuntimeException(e); } }