public SelfSignedCertificateImpl() { try { certificate = new io.netty.handler.ssl.util.SelfSignedCertificate(); } catch (CertificateException e) { throw new VertxException(e); } }
public SelfSignedCertificateImpl(String fqdn) { try { certificate = new io.netty.handler.ssl.util.SelfSignedCertificate(fqdn); } catch (CertificateException e) { throw new VertxException(e); } }
/** * Generates a {@link SelfSignedCertificate}. */ @Override protected void before() throws Throwable { if (fqdn == null) { if (notBefore == null || notAfter == null) { certificate = new SelfSignedCertificate(); } else { certificate = new SelfSignedCertificate(toDate(notBefore), toDate(notAfter)); } } else if (random == null || bits == null) { if (notBefore == null || notAfter == null) { certificate = new SelfSignedCertificate(fqdn); } else { certificate = new SelfSignedCertificate(fqdn, toDate(notBefore), toDate(notAfter)); } } else { if (notBefore == null || notAfter == null) { certificate = new SelfSignedCertificate(fqdn, random, bits); } else { certificate = new SelfSignedCertificate(fqdn, random, bits, toDate(notBefore), toDate(notAfter)); } } }
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();
@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)); }
SelfSignedCertificate ssc = new SelfSignedCertificate(); return Optional.of(SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build()); } catch (CertificateException | SSLException 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 ) ); }
/** * 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 ); } }
@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 ); }
SelfSignedCertificate ssc = new SelfSignedCertificate(); sslCtx = io.netty.handler.ssl.SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()) .sslProvider(provider)
SelfSignedCertificate ssc = new SelfSignedCertificate(); sslCtx = io.netty.handler.ssl.SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()) .sslProvider(provider)
SelfSignedCertificate selfSignedCertificate = new SelfSignedCertificate(); return SslContextBuilder .forServer(selfSignedCertificate.certificate(), selfSignedCertificate.privateKey())
@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 void configure(ServerBuilder sb) throws Exception { ssc = new SelfSignedCertificate("example.com"); sb.serverListener(new ServerListenerAdapter() { @Override public void serverStopped(Server server) { executor.shutdown(); ssc.delete(); } }); sb.https(new InetSocketAddress("127.0.0.1", 0)); sb.tls(newSslContext()); sb.defaultMaxRequestLength(16 * 1024 * 1024); sb.serviceUnder("/", new GrpcServiceBuilder() .addService(ServerInterceptors.intercept( new TestServiceImpl(executor), TestServiceImpl.interceptors())) .build() .decorate((delegate, ctx, req) -> { ctxCapture.set(ctx); return delegate.serve(ctx, req); })); }
public SelfSignedCertificateImpl() { try { certificate = new io.netty.handler.ssl.util.SelfSignedCertificate(); } catch (CertificateException e) { throw new VertxException(e); } }
public SelfSignedCertificateImpl(String fqdn) { try { certificate = new io.netty.handler.ssl.util.SelfSignedCertificate(fqdn); } catch (CertificateException e) { throw new VertxException(e); } }
@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(); } }