当前位置: 首页>>代码示例>>Java>>正文


Java SslContext类代码示例

本文整理汇总了Java中io.netty.handler.ssl.SslContext的典型用法代码示例。如果您正苦于以下问题:Java SslContext类的具体用法?Java SslContext怎么用?Java SslContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SslContext类属于io.netty.handler.ssl包,在下文中一共展示了SslContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initChannel

import io.netty.handler.ssl.SslContext; //导入依赖的package包/类
@Override
protected void initChannel(SocketChannel ch) throws Exception {
    if (enableTLS) {
        File tlsCert = new File(serviceConfig.getTlsCertificateFilePath());
        File tlsKey = new File(serviceConfig.getTlsKeyFilePath());
        SslContextBuilder builder = SslContextBuilder.forServer(tlsCert, tlsKey);
        if (serviceConfig.isTlsAllowInsecureConnection()) {
            builder.trustManager(InsecureTrustManagerFactory.INSTANCE);
        } else {
            if (serviceConfig.getTlsTrustCertsFilePath().isEmpty()) {
                // Use system default
                builder.trustManager((File) null);
            } else {
                File trustCertCollection = new File(serviceConfig.getTlsTrustCertsFilePath());
                builder.trustManager(trustCertCollection);
            }
        }
        SslContext sslCtx = builder.clientAuth(ClientAuth.OPTIONAL).build();
        ch.pipeline().addLast(TLS_HANDLER, sslCtx.newHandler(ch.alloc()));
    }
    ch.pipeline().addLast("frameDecoder", new LengthFieldBasedFrameDecoder(PulsarDecoder.MaxFrameSize, 0, 4, 0, 4));
    ch.pipeline().addLast("handler", new ServerConnection(discoveryService));
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:24,代码来源:ServiceChannelInitializer.java

示例2: setupWSChannel

import io.netty.handler.ssl.SslContext; //导入依赖的package包/类
protected ChannelHandler setupWSChannel(SslContext sslCtx, Configuration conf, DataStore datastore) {
    return new ChannelInitializer<SocketChannel>() {

        @Override
        protected void initChannel(SocketChannel ch) throws Exception {
            ch.pipeline().addLast("ssl", sslCtx.newHandler(ch.alloc()));
            ch.pipeline().addLast("httpServer", new HttpServerCodec());
            ch.pipeline().addLast("aggregator", new HttpObjectAggregator(8192));
            ch.pipeline().addLast("sessionExtractor", new WebSocketHttpCookieHandler(config));
            ch.pipeline().addLast("idle-handler", new IdleStateHandler(conf.getWebsocket().getTimeout(), 0, 0));
            ch.pipeline().addLast("ws-protocol", new WebSocketServerProtocolHandler(WS_PATH, null, true));
            ch.pipeline().addLast("wsDecoder", new WebSocketRequestDecoder(datastore, config));
            ch.pipeline().addLast("error", new WSExceptionHandler());
        }
    };

}
 
开发者ID:NationalSecurityAgency,项目名称:qonduit,代码行数:18,代码来源:Server.java

示例3: start

import io.netty.handler.ssl.SslContext; //导入依赖的package包/类
public void start(String ip, int port) throws Exception {
	// Configure SSL.
	final SslContext sslCtx;
	if (SSL) {
		sslCtx = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build();
	} else {
		sslCtx = null;
	}
	EventLoopGroup group = new NioEventLoopGroup();
	try {
		Bootstrap b = new Bootstrap();
		b.group(group).channel(NioSocketChannel.class).handler(new FileClientInitializer(sslCtx));
		Channel ch = b.connect(ip, port).sync().channel();
		ConfigurationContext.propMap.putIfAbsent(SOCKET_CHANNEL, ch);			
	}catch(Exception e){
		e.printStackTrace();
	}
}
 
开发者ID:polarcoral,项目名称:monica,代码行数:19,代码来源:SocketClient.java

示例4: ConnectionFactory

import io.netty.handler.ssl.SslContext; //导入依赖的package包/类
ConnectionFactory(
        EventLoopGroup group,
        MessageFraming messageFraming,
        MessageEncoding messageEncoding,
        Optional<Supplier<SslContext>> sslContextSupplier,
        DriftNettyClientConfig clientConfig)
{
    this.group = requireNonNull(group, "group is null");
    this.messageFraming = requireNonNull(messageFraming, "messageFraming is null");
    this.messageEncoding = requireNonNull(messageEncoding, "messageEncoding is null");
    this.sslContextSupplier = requireNonNull(sslContextSupplier, "sslContextSupplier is null");

    requireNonNull(clientConfig, "clientConfig is null");
    this.connectTimeout = clientConfig.getConnectTimeout();
    this.requestTimeout = clientConfig.getRequestTimeout();
    this.socksProxy = Optional.ofNullable(clientConfig.getSocksProxy());
}
 
开发者ID:airlift,项目名称:drift,代码行数:18,代码来源:ConnectionFactory.java

示例5: load

import io.netty.handler.ssl.SslContext; //导入依赖的package包/类
@Override
public boolean load() {
    final SslContext previous = reference.get();
    try {
        final SslContext context = loader.get();
        if (context == null) {
            return finishLoadWithReloadState(ReloadState.FAILED, null);
        }

        if (Objects.equals(previous, context)) {
            return finishLoadWithReloadState(ReloadState.NO_CHANGE, null);
        }

        reference.set(context);
        return finishLoadWithReloadState(ReloadState.RELOADED, null);
    } catch (final Exception e) {
        LOGGER.error("Failed to load SslContext.", e);
    }

    return finishLoadWithReloadState(ReloadState.FAILED, null);
}
 
开发者ID:indeedeng-alpha,项目名称:indeed-grpc-java,代码行数:22,代码来源:SslContextReloader.java

示例6: get

import io.netty.handler.ssl.SslContext; //导入依赖的package包/类
@Test
public void get() throws Exception {
    final SslContextReloader reloader = new SslContextReloader(() -> null);

    assertFalse(reloader.load());
    assertEquals(ReloadState.FAILED, reloader.getReloadState());
    assertNull(reloader.getDataVersion());

    final SslContext context = reloader.get();
    assertNotNull(context);

    expectNullPointerException(context::isClient);
    expectNullPointerException(context::cipherSuites);
    expectNullPointerException(context::sessionCacheSize);
    expectNullPointerException(context::sessionTimeout);
    expectNullPointerException(context::applicationProtocolNegotiator);
    expectNullPointerException(context::sessionContext);
    expectNullPointerException(() -> context.newEngine(ByteBufAllocator.DEFAULT));
    expectNullPointerException(() -> context.newEngine(ByteBufAllocator.DEFAULT, "localhost", 1234));
}
 
开发者ID:indeedeng-alpha,项目名称:indeed-grpc-java,代码行数:21,代码来源:SslContextReloaderTest.java

示例7: ImapClient

import io.netty.handler.ssl.SslContext; //导入依赖的package包/类
public ImapClient(ImapClientConfiguration configuration,
                  Channel channel,
                  SslContext sslContext,
                  EventExecutorGroup promiseExecutor,
                  String clientName) {
  this.logger = LogUtils.loggerWithName(ImapClient.class, clientName);
  this.configuration = configuration;
  this.channel = channel;
  this.sslContext = sslContext;
  this.promiseExecutor = promiseExecutor;
  this.clientState = new ImapClientState(clientName, promiseExecutor);
  this.codec = new ImapCodec(clientState);
  this.pendingWriteQueue = new ConcurrentLinkedQueue<>();
  this.connectionShutdown = new AtomicBoolean(false);
  this.connectionClosed = new AtomicBoolean(false);
  this.capabilities = new AtomicReference<>(null);

  configureChannel();
}
 
开发者ID:HubSpot,项目名称:NioImapClient,代码行数:20,代码来源:ImapClient.java

示例8: usingNetty

import io.netty.handler.ssl.SslContext; //导入依赖的package包/类
static ClientHttpRequestFactory usingNetty(ClientOptions options)
		throws IOException, GeneralSecurityException {

	SslContext sslContext = new JdkSslContext(SSLContext.getDefault(), true, ClientAuth.REQUIRE);

	final Netty4ClientHttpRequestFactory requestFactory = new Netty4ClientHttpRequestFactory();
	requestFactory.setSslContext(sslContext);

	if (options.getConnectionTimeout() != null) {
		requestFactory.setConnectTimeout(options.getConnectionTimeout());
	}
	if (options.getReadTimeout() != null) {
		requestFactory.setReadTimeout(options.getReadTimeout());
	}

	return requestFactory;
}
 
开发者ID:spring-projects,项目名称:spring-credhub,代码行数:18,代码来源:ClientHttpRequestFactoryFactory.java

示例9: createSSlContext

import io.netty.handler.ssl.SslContext; //导入依赖的package包/类
/**
 * Create ssl context for the host
 */
public SslContext createSSlContext(String host, boolean useH2) {
    String finalHost = Networks.wildcardHost(host);
    lock.readLock().lock();
    try {
        return sslContextCache.computeIfAbsent(host + ":" + useH2, key -> {
            try {
                return getNettySslContextInner(finalHost, useH2);
            } catch (Exception e) {
                throw new SSLContextException(e);
            }
        });
    } finally {
        lock.readLock().unlock();
    }
}
 
开发者ID:hsiafan,项目名称:byproxy,代码行数:19,代码来源:ServerSSLContextManager.java

示例10: newNettyClientContext

import io.netty.handler.ssl.SslContext; //导入依赖的package包/类
private static SslContext newNettyClientContext(
        io.netty.handler.ssl.SslProvider sslProvider, boolean useAlpn) {
    try {
        TestKeyStore server = TestKeyStore.getServer();
        SslContextBuilder ctx =
                SslContextBuilder.forClient()
                        .sslProvider(sslProvider)
                        .trustManager((X509Certificate[]) server.getPrivateKey("RSA", "RSA")
                                              .getCertificateChain());
        if (useAlpn) {
            ctx.applicationProtocolConfig(OpenJdkEngineFactoryConfig.NETTY_ALPN_CONFIG);
        }
        return ctx.build();
    } catch (SSLException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:google,项目名称:conscrypt,代码行数:18,代码来源:OpenJdkEngineFactory.java

示例11: getServerInitializer

import io.netty.handler.ssl.SslContext; //导入依赖的package包/类
private ChannelInitializer<LocalChannel> getServerInitializer(
    PrivateKey privateKey,
    X509Certificate certificate,
    Lock serverLock,
    Exception serverException)
    throws Exception {
  SslContext sslContext = SslContextBuilder.forServer(privateKey, certificate).build();
  return new ChannelInitializer<LocalChannel>() {
    @Override
    protected void initChannel(LocalChannel ch) throws Exception {
      ch.pipeline()
          .addLast(
              sslContext.newHandler(ch.alloc()), new EchoHandler(serverLock, serverException));
    }
  };
}
 
开发者ID:google,项目名称:nomulus,代码行数:17,代码来源:SslClientInitializerTest.java

示例12: getNettySslContextInner

import io.netty.handler.ssl.SslContext; //导入依赖的package包/类
private SslContext getNettySslContextInner(String host, boolean useH2) throws Exception {
        long start = System.currentTimeMillis();
        PrivateKeyAndCertChain keyAndCertChain = keyStoreGenerator.generateCertChain(host, Settings.certValidityDays);
        logger.debug("Create certificate for {}, cost {} ms", host, System.currentTimeMillis() - start);
        SslContextBuilder builder = SslContextBuilder
                .forServer(keyAndCertChain.getPrivateKey(), keyAndCertChain.getCertificateChain());
        if (useH2) {
//                .ciphers(Http2SecurityUtil.CIPHERS, SupportedCipherSuiteFilter.INSTANCE)
            builder.applicationProtocolConfig(new ApplicationProtocolConfig(
                    ApplicationProtocolConfig.Protocol.ALPN,
                    SelectorFailureBehavior.NO_ADVERTISE,
                    SelectedListenerFailureBehavior.ACCEPT,
                    ApplicationProtocolNames.HTTP_2,
                    ApplicationProtocolNames.HTTP_1_1));
        }
        return builder.build();
    }
 
开发者ID:hsiafan,项目名称:byproxy,代码行数:18,代码来源:ServerSSLContextManager.java

示例13: initChannel_adds_sslCtx_handler_first_if_available_and_no_utility_handlers

import io.netty.handler.ssl.SslContext; //导入依赖的package包/类
@Test
public void initChannel_adds_sslCtx_handler_first_if_available_and_no_utility_handlers() throws SSLException {
    // given
    SslContext sslCtx = new JdkSslClientContext();
    HttpChannelInitializer hci = basicHttpChannelInitializer(sslCtx, 0, 100, false, mock(RequestValidator.class),
                                                             createRequestAndResponseFilterMock());

    // when
    hci.initChannel(socketChannelMock);

    // then
    ArgumentCaptor<ChannelHandler> channelHandlerArgumentCaptor = ArgumentCaptor.forClass(ChannelHandler.class);
    verify(channelPipelineMock, atLeastOnce()).addLast(anyString(), channelHandlerArgumentCaptor.capture());
    List<ChannelHandler> handlers = channelHandlerArgumentCaptor.getAllValues();
    assertThat(handlers.get(0), instanceOf(SslHandler.class));
}
 
开发者ID:Nike-Inc,项目名称:riposte,代码行数:17,代码来源:HttpChannelInitializerTest.java

示例14: getSSLContext

import io.netty.handler.ssl.SslContext; //导入依赖的package包/类
private static SslContext getSSLContext() throws IOException, GeneralSecurityException {
    try {
        final String privateKeyFile = "keys/server.pkcs8.key";
        final String certificateFile = "keys/server.crt";
        final String rootCAFile = "keys/rootCA.pem";

        final PrivateKey privateKey = loadPrivateKey(privateKeyFile);
        final X509Certificate certificate = loadX509Cert(certificateFile);
        final X509Certificate rootCA = loadX509Cert(rootCAFile);

        return SslContextBuilder.forClient()
                .sslProvider(SslProvider.JDK)
                .trustManager(rootCA)
                .keyManager(privateKey, certificate)
                .build();

    } catch (IOException | GeneralSecurityException e) {
        LOGGER.warn("Failed to establish SSL Context");
        LOGGER.debug("Failed to establish SSL Context", e);
        throw e;
    }
}
 
开发者ID:inst-tech,项目名称:opentsdb-plugins,代码行数:23,代码来源:RelayClient.java

示例15: main

import io.netty.handler.ssl.SslContext; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    SelfSignedCertificate ssc = new SelfSignedCertificate();
    SslContext sslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey())
        .build();

    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 SecureChatServerInitializer(sslCtx));

        b.bind(PORT).sync().channel().closeFuture().sync();
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}
 
开发者ID:cowthan,项目名称:JavaAyo,代码行数:21,代码来源:SecureChatServer.java


注:本文中的io.netty.handler.ssl.SslContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。