本文整理汇总了Java中io.netty.handler.ssl.ApplicationProtocolNames类的典型用法代码示例。如果您正苦于以下问题:Java ApplicationProtocolNames类的具体用法?Java ApplicationProtocolNames怎么用?Java ApplicationProtocolNames使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ApplicationProtocolNames类属于io.netty.handler.ssl包,在下文中一共展示了ApplicationProtocolNames类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: applicationProtocolConfig
import io.netty.handler.ssl.ApplicationProtocolNames; //导入依赖的package包/类
private static ApplicationProtocolConfig applicationProtocolConfig(NitmProxyConfig config, boolean http2) {
if (http2) {
return new ApplicationProtocolConfig(
Protocol.ALPN,
SelectorFailureBehavior.NO_ADVERTISE,
SelectedListenerFailureBehavior.ACCEPT,
ApplicationProtocolNames.HTTP_2,
ApplicationProtocolNames.HTTP_1_1);
} else {
return new ApplicationProtocolConfig(
Protocol.ALPN,
SelectorFailureBehavior.NO_ADVERTISE,
SelectedListenerFailureBehavior.ACCEPT,
ApplicationProtocolNames.HTTP_1_1);
}
}
示例2: getNettySslContextInner
import io.netty.handler.ssl.ApplicationProtocolNames; //导入依赖的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();
}
示例3: configurePipeline
import io.netty.handler.ssl.ApplicationProtocolNames; //导入依赖的package包/类
@Override
protected void configurePipeline(ChannelHandlerContext ctx, String protocol) throws Exception {
if (ApplicationProtocolNames.HTTP_2.equals(protocol)) {
ctx.pipeline().addLast(new Http2MultiplexCodec(true, new HelloWorldHttp2Handler()));
return;
}
if (ApplicationProtocolNames.HTTP_1_1.equals(protocol)) {
ctx.pipeline().addLast(new HttpServerCodec(),
new HttpObjectAggregator(MAX_CONTENT_LENGTH),
new HelloWorldHttp1Handler("ALPN Negotiation"));
return;
}
throw new IllegalStateException("unknown protocol: " + protocol);
}
示例4: configureSsl
import io.netty.handler.ssl.ApplicationProtocolNames; //导入依赖的package包/类
/**
* Configure the pipeline for TLS NPN negotiation to HTTP/2.
*/
private void configureSsl(SocketChannel ch) {
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast(sslCtx.newHandler(ch.alloc()));
// We must wait for the handshake to finish and the protocol to be negotiated before configuring
// the HTTP/2 components of the pipeline.
pipeline.addLast(new ApplicationProtocolNegotiationHandler("") {
@Override
protected void configurePipeline(ChannelHandlerContext ctx, String protocol) {
if (ApplicationProtocolNames.HTTP_2.equals(protocol)) {
ChannelPipeline p = ctx.pipeline();
p.addLast(connectionHandler);
configureEndOfPipeline(p);
return;
}
ctx.close();
throw new IllegalStateException("unknown protocol: " + protocol);
}
});
}
示例5: configurePipeline
import io.netty.handler.ssl.ApplicationProtocolNames; //导入依赖的package包/类
@Override
protected void configurePipeline(ChannelHandlerContext ctx, String protocol) throws Exception {
if (ApplicationProtocolNames.HTTP_2.equals(protocol)) {
ctx.pipeline().addLast(new HelloWorldHttp2HandlerBuilder().build());
return;
}
if (ApplicationProtocolNames.HTTP_1_1.equals(protocol)) {
ctx.pipeline().addLast(new HttpServerCodec(),
new HttpObjectAggregator(MAX_CONTENT_LENGTH),
new HelloWorldHttp1Handler("ALPN Negotiation"));
return;
}
throw new IllegalStateException("unknown protocol: " + protocol);
}
示例6: getSslContext
import io.netty.handler.ssl.ApplicationProtocolNames; //导入依赖的package包/类
private SslContext getSslContext() {
SslContext sslCtx = null;
final SslProvider provider = OpenSsl.isAlpnSupported() ? SslProvider.OPENSSL : SslProvider.JDK;
try {
sslCtx = SslContextBuilder.forClient()
.sslProvider(provider)
.ciphers(Http2SecurityUtil.CIPHERS, SupportedCipherSuiteFilter.INSTANCE)
.trustManager(InsecureTrustManagerFactory.INSTANCE)
.applicationProtocolConfig(new ApplicationProtocolConfig(
Protocol.ALPN,
SelectorFailureBehavior.NO_ADVERTISE,
SelectedListenerFailureBehavior.ACCEPT,
ApplicationProtocolNames.HTTP_2))
.build();
} catch(SSLException exception) {
return null;
}
return sslCtx;
}
示例7: createHttp2TLSContext
import io.netty.handler.ssl.ApplicationProtocolNames; //导入依赖的package包/类
/**
* This method will provide netty ssl context which supports HTTP2 over TLS using
* Application Layer Protocol Negotiation (ALPN)
*
* @return instance of {@link SslContext}
* @throws SSLException if any error occurred during building SSL context.
*/
public SslContext createHttp2TLSContext() throws SSLException {
// If listener configuration does not include cipher suites , default ciphers required by the HTTP/2
// specification will be added.
List<String> ciphers = sslConfig.getCipherSuites() != null && sslConfig.getCipherSuites().length > 0 ? Arrays
.asList(sslConfig.getCipherSuites()) : Http2SecurityUtil.CIPHERS;
SslProvider provider = OpenSsl.isAlpnSupported() ? SslProvider.OPENSSL : SslProvider.JDK;
return SslContextBuilder.forServer(this.getKeyManagerFactory())
.trustManager(this.getTrustStoreFactory())
.sslProvider(provider)
.ciphers(ciphers,
SupportedCipherSuiteFilter.INSTANCE)
.clientAuth(needClientAuth ? ClientAuth.REQUIRE : ClientAuth.NONE)
.applicationProtocolConfig(new ApplicationProtocolConfig(
ApplicationProtocolConfig.Protocol.ALPN,
// NO_ADVERTISE is currently the only mode supported by both OpenSsl and JDK providers.
ApplicationProtocolConfig.SelectorFailureBehavior.NO_ADVERTISE,
// ACCEPT is currently the only mode supported by both OpenSsl and JDK providers.
ApplicationProtocolConfig.SelectedListenerFailureBehavior.ACCEPT,
ApplicationProtocolNames.HTTP_2,
ApplicationProtocolNames.HTTP_1_1)).build();
}
示例8: build
import io.netty.handler.ssl.ApplicationProtocolNames; //导入依赖的package包/类
static SslContext build(final Config conf) throws IOException, CertificateException {
String tmpdir = conf.getString("application.tmpdir");
boolean http2 = conf.getBoolean("server.http2.enabled");
File keyStoreCert = toFile(conf.getString("ssl.keystore.cert"), tmpdir);
File keyStoreKey = toFile(conf.getString("ssl.keystore.key"), tmpdir);
String keyStorePass = conf.hasPath("ssl.keystore.password")
? conf.getString("ssl.keystore.password") : null;
SslContextBuilder scb = SslContextBuilder.forServer(keyStoreCert, keyStoreKey, keyStorePass);
if (conf.hasPath("ssl.trust.cert")) {
scb.trustManager(toFile(conf.getString("ssl.trust.cert"), tmpdir))
.clientAuth(ClientAuth.REQUIRE);
}
if (http2) {
SslProvider provider = OpenSsl.isAlpnSupported() ? SslProvider.OPENSSL : SslProvider.JDK;
return scb.sslProvider(provider)
.ciphers(Http2SecurityUtil.CIPHERS, SupportedCipherSuiteFilter.INSTANCE)
.applicationProtocolConfig(new ApplicationProtocolConfig(
Protocol.ALPN,
SelectorFailureBehavior.NO_ADVERTISE,
SelectedListenerFailureBehavior.ACCEPT,
Arrays.asList(ApplicationProtocolNames.HTTP_2, ApplicationProtocolNames.HTTP_1_1)))
.build();
}
return scb.build();
}
示例9: alpn
import io.netty.handler.ssl.ApplicationProtocolNames; //导入依赖的package包/类
private Block alpn(final SslProvider provider) {
return unit -> {
SslContextBuilder scb = unit.get(SslContextBuilder.class);
expect(scb.sslProvider(provider)).andReturn(scb);
expect(scb.ciphers(Http2SecurityUtil.CIPHERS, SupportedCipherSuiteFilter.INSTANCE))
.andReturn(scb);
ApplicationProtocolConfig apc = unit.constructor(ApplicationProtocolConfig.class)
.args(Protocol.class, SelectorFailureBehavior.class,
SelectedListenerFailureBehavior.class, List.class)
.build(Protocol.ALPN,
SelectorFailureBehavior.NO_ADVERTISE,
SelectedListenerFailureBehavior.ACCEPT,
Arrays.asList(ApplicationProtocolNames.HTTP_2,
ApplicationProtocolNames.HTTP_1_1));
expect(scb.applicationProtocolConfig(apc)).andReturn(scb);
};
}
示例10: configurePipeline
import io.netty.handler.ssl.ApplicationProtocolNames; //导入依赖的package包/类
@Override
protected void configurePipeline(ChannelHandlerContext ctx, String protocol) throws Exception {
if (ApplicationProtocolNames.HTTP_2.equals(protocol)) {
configHttp2(tlsCtx);
} else if (ApplicationProtocolNames.HTTP_1_1.equals(protocol)) {
configHttp1(tlsCtx);
} else {
throw new IllegalStateException("unknown protocol: " + protocol);
}
}
示例11: Http2TestServerRunnable
import io.netty.handler.ssl.ApplicationProtocolNames; //导入依赖的package包/类
Http2TestServerRunnable(File certFile, File keyFile) throws Exception {
ApplicationProtocolConfig applicationProtocolConfig = new ApplicationProtocolConfig(
Protocol.ALPN, SelectorFailureBehavior.NO_ADVERTISE,
SelectedListenerFailureBehavior.ACCEPT, ApplicationProtocolNames.HTTP_2);
mSslCtx = new OpenSslServerContext(certFile, keyFile, null, null,
Http2SecurityUtil.CIPHERS, SupportedCipherSuiteFilter.INSTANCE,
applicationProtocolConfig, 0, 0);
}
示例12: configurePipeline
import io.netty.handler.ssl.ApplicationProtocolNames; //导入依赖的package包/类
@Override
protected void configurePipeline(ChannelHandlerContext ctx, String protocol)
throws Exception {
if (ApplicationProtocolNames.HTTP_2.equals(protocol)) {
ctx.pipeline().addLast(new Http2TestHandler.Builder().build());
return;
}
throw new IllegalStateException("unknown protocol: " + protocol);
}
示例13: newClientEngine
import io.netty.handler.ssl.ApplicationProtocolNames; //导入依赖的package包/类
@Override
public SSLEngine newClientEngine(String cipher, boolean useAlpn) {
SSLEngine engine = initEngine(clientContext.createSSLEngine(), cipher, true);
if (useAlpn) {
Conscrypt.setApplicationProtocols(engine, new String[] {ApplicationProtocolNames.HTTP_2});
}
return engine;
}
示例14: newServerEngine
import io.netty.handler.ssl.ApplicationProtocolNames; //导入依赖的package包/类
@Override
public SSLEngine newServerEngine(String cipher, boolean useAlpn) {
SSLEngine engine = initEngine(serverContext.createSSLEngine(), cipher, false);
if (useAlpn) {
Conscrypt.setApplicationProtocols(engine, new String[] {ApplicationProtocolNames.HTTP_2});
}
return engine;
}
示例15: createNettyClientSSlContext
import io.netty.handler.ssl.ApplicationProtocolNames; //导入依赖的package包/类
private static SslContext createNettyClientSSlContext() {
try {
return SslContextBuilder.forClient()
.trustManager(InsecureTrustManagerFactory.INSTANCE)
.applicationProtocolConfig(new ApplicationProtocolConfig(
ApplicationProtocolConfig.Protocol.ALPN,
SelectorFailureBehavior.NO_ADVERTISE,
SelectedListenerFailureBehavior.ACCEPT,
ApplicationProtocolNames.HTTP_2,
ApplicationProtocolNames.HTTP_1_1))
.build();
} catch (SSLException e) {
throw new SSLContextException(e);
}
}