本文整理匯總了Java中io.netty.handler.ssl.util.InsecureTrustManagerFactory類的典型用法代碼示例。如果您正苦於以下問題:Java InsecureTrustManagerFactory類的具體用法?Java InsecureTrustManagerFactory怎麽用?Java InsecureTrustManagerFactory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
InsecureTrustManagerFactory類屬於io.netty.handler.ssl.util包,在下文中一共展示了InsecureTrustManagerFactory類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: initChannel
import io.netty.handler.ssl.util.InsecureTrustManagerFactory; //導入依賴的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));
}
示例2: NettyHttpClient
import io.netty.handler.ssl.util.InsecureTrustManagerFactory; //導入依賴的package包/類
public NettyHttpClient(String authCode, HttpProxy proxy, ClientConfig config) {
_maxRetryTimes = config.getMaxRetryTimes();
_readTimeout = config.getReadTimeout();
String message = MessageFormat.format("Created instance with "
+ "connectionTimeout {0}, readTimeout {1}, maxRetryTimes {2}, SSL Version {3}",
config.getConnectionTimeout(), _readTimeout, _maxRetryTimes, config.getSSLVersion());
LOG.debug(message);
_authCode = authCode;
try {
_sslCtx = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build();
_workerGroup = new NioEventLoopGroup();
b = new Bootstrap(); // (1)
b.group(_workerGroup); // (2)
b.channel(NioSocketChannel.class); // (3)
b.option(ChannelOption.SO_KEEPALIVE, true); // (4)
} catch (SSLException e) {
e.printStackTrace();
}
}
示例3: start
import io.netty.handler.ssl.util.InsecureTrustManagerFactory; //導入依賴的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();
}
}
示例4: buildSslCtx
import io.netty.handler.ssl.util.InsecureTrustManagerFactory; //導入依賴的package包/類
private SslContext buildSslCtx() {
SslProvider provider = OpenSsl.isAlpnSupported() ? SslProvider.OPENSSL : SslProvider.JDK;
try {
return SslContextBuilder.forClient()
.sslProvider(provider)
.ciphers(Http2SecurityUtil.CIPHERS, SupportedCipherSuiteFilter.INSTANCE)
.trustManager(InsecureTrustManagerFactory.INSTANCE)
// TODO(JR): Make a seperate Handler Class for http2 as opposed to autoneg
// .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();
} catch (SSLException e) {
e.printStackTrace();
}
return null;
}
示例5: trustManager
import io.netty.handler.ssl.util.InsecureTrustManagerFactory; //導入依賴的package包/類
private static TrustManagerFactory trustManager(NetworkSslConfig cfg, ResourceService resources) throws GeneralSecurityException,
IOException, ResourceLoadingException {
if (cfg.getTrustStorePath() == null || cfg.getTrustStorePath().isEmpty()) {
return InsecureTrustManagerFactory.INSTANCE;
} else {
TrustManagerFactory factory;
if (cfg.getTrustStoreAlgorithm() == null || cfg.getTrustStoreAlgorithm().isEmpty()) {
factory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
} else {
factory = TrustManagerFactory.getInstance(cfg.getTrustStoreAlgorithm());
}
KeyStore store = keyStore(cfg.getTrustStorePath(), cfg.getTrustStorePassword(), cfg.getTrustStoreType(), resources);
factory.init(store);
return factory;
}
}
示例6: shoot
import io.netty.handler.ssl.util.InsecureTrustManagerFactory; //導入依賴的package包/類
public void shoot(ShootComplete shootComplete) {
Bootstrap b = new Bootstrap();
SslContext sslContext = null;
if (ssl) {
try {
sslContext = SslContextBuilder.forClient()
.trustManager(InsecureTrustManagerFactory.INSTANCE).build();
} catch (SSLException e) {
e.printStackTrace();
}
}
b.group(group)
.channel(NioSocketChannel.class)
.handler(new HttpClientInitializer(sslContext));
// Make the connection attempt.
b.connect(host, port).addListener(
(ChannelFutureListener) channelFuture -> {
sendHttpRequest(channelFuture, shootComplete);
});
}
示例7: initChannel
import io.netty.handler.ssl.util.InsecureTrustManagerFactory; //導入依賴的package包/類
@Override
protected void initChannel(SocketChannel channel) throws SSLException {
URI uri = config.getConnectionWebsocketUri();
DefaultHttpHeaders headers = new DefaultHttpHeaders();
headers.add(USER_ID_HEADER, config.getConnectionUserId().toString());
headers.add(USER_PASSWORD_HEADER, config.getConnectionUserPassword());
headers.add(SUPPLIER_ID_HEADER, config.getConnectionServerId());
WebSocketClientHandshaker handshaker = WebSocketClientHandshakerFactory.newHandshaker(uri, WS_VERSION, null, false, headers);
ChannelPipeline pipeline = channel.pipeline();
if (config.isConnectionSecure()) {
try {
SslContext sslContext = SslContext.newClientContext(InsecureTrustManagerFactory.INSTANCE);
pipeline.addLast(sslContext.newHandler(channel.alloc()));
} catch (SSLException e) {
logger.log(Level.SEVERE, "Shutting down client due to unexpected failure to create SSL context", e);
throw e;
}
}
pipeline.addLast(new HttpClientCodec());
pipeline.addLast(new HttpObjectAggregator(8192));
pipeline.addLast(new AudioConnectClientHandler(handshaker));
}
示例8: initChannel
import io.netty.handler.ssl.util.InsecureTrustManagerFactory; //導入依賴的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 ServerCnx(brokerService));
}
示例9: shouldEnableSslWithSslContextProgrammaticallySpecified
import io.netty.handler.ssl.util.InsecureTrustManagerFactory; //導入依賴的package包/類
@Test
public void shouldEnableSslWithSslContextProgrammaticallySpecified() throws Exception {
// just for testing - this is not good for production use
final SslContextBuilder builder = SslContextBuilder.forClient();
builder.trustManager(InsecureTrustManagerFactory.INSTANCE);
builder.sslProvider(SslProvider.JDK);
final Cluster cluster = Cluster.build().enableSsl(true).sslContext(builder.build()).create();
final Client client = cluster.connect();
try {
// this should return "nothing" - there should be no exception
assertEquals("test", client.submit("'test'").one().getString());
} finally {
cluster.close();
}
}
示例10: WebSocketClient
import io.netty.handler.ssl.util.InsecureTrustManagerFactory; //導入依賴的package包/類
public WebSocketClient(WebSocketConfig config) throws URISyntaxException, SSLException, InterruptedException {
final int port = config.serverUri.getPort();
final String scheme = config.serverUri.getScheme().endsWith("s") ? "wss" : "ws";
final boolean isWss = "wss".equalsIgnoreCase(scheme);
this.headers = new DefaultHttpHeaders();
if (config.apiKey != null) headers.add("X-Samebug-ApiKey", config.apiKey);
if (config.workspaceId != null) headers.add("X-Samebug-WorkspaceId", config.workspaceId);
this.port = port == -1 ? (isWss ? 443 : 80) : port;
this.host = config.serverUri.getHost();
this.wsEndpoint = new URI(scheme, null, host, port, "/sockets/websocket", null, null);
this.eventHandler = config.eventHandler;
this.group = config.group;
this.sslContext = isWss ? SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build() : null;
// IMPROVE the constructor blocks the thread with networking!
this.channel = connect();
}
示例11: getSslContext
import io.netty.handler.ssl.util.InsecureTrustManagerFactory; //導入依賴的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;
}
示例12: https
import io.netty.handler.ssl.util.InsecureTrustManagerFactory; //導入依賴的package包/類
@Test
public void https() throws Exception {
ClientFactory clientFactory = new ClientFactoryBuilder()
.sslContextCustomizer(b -> b.trustManager(InsecureTrustManagerFactory.INSTANCE))
.build();
HttpClient client = HttpClient.of(clientFactory, server().httpsUri("/"));
AggregatedHttpMessage response = client.get("/jsp/index.jsp").aggregate().get();
final String actualContent = CR_OR_LF.matcher(response.content().toStringUtf8())
.replaceAll("");
assertThat(actualContent).isEqualTo(
"<html><body>" +
"<p>Hello, Armerian World!</p>" +
"<p>Have you heard about the class 'io.netty.buffer.ByteBuf'?</p>" +
"<p>Context path: </p>" + // ROOT context path
"<p>Request URI: /index.jsp</p>" +
"<p>Scheme: https</p>" +
"</body></html>");
}
示例13: WebSocketClient
import io.netty.handler.ssl.util.InsecureTrustManagerFactory; //導入依賴的package包/類
public WebSocketClient(String host, int port, String path, boolean isSSL) throws Exception {
super(host, port, new Random());
String scheme = isSSL ? "wss://" : "ws://";
URI uri = new URI(scheme + host + ":" + port + path);
if (isSSL) {
sslCtx = SslContextBuilder.forClient().sslProvider(SslProvider.JDK).trustManager(InsecureTrustManagerFactory.INSTANCE).build();
} else {
sslCtx = null;
}
this.handler = new WebSocketClientHandler(
WebSocketClientHandshakerFactory.newHandshaker(
uri, WebSocketVersion.V13, null, false, new DefaultHttpHeaders()));
}
示例14: shouldEnableSslWithSslContextProgrammaticallySpecified
import io.netty.handler.ssl.util.InsecureTrustManagerFactory; //導入依賴的package包/類
@Test
public void shouldEnableSslWithSslContextProgrammaticallySpecified() throws Exception {
// just for testing - this is not good for production use
final SslContextBuilder builder = SslContextBuilder.forClient();
builder.trustManager(InsecureTrustManagerFactory.INSTANCE);
builder.sslProvider(SslProvider.JDK);
final Cluster cluster = TestClientFactory.build().enableSsl(true).sslContext(builder.build()).create();
final Client client = cluster.connect();
try {
// this should return "nothing" - there should be no exception
assertEquals("test", client.submit("'test'").one().getString());
} finally {
cluster.close();
}
}
示例15: initialize
import io.netty.handler.ssl.util.InsecureTrustManagerFactory; //導入依賴的package包/類
public ExtractorClient initialize() throws DeepExtractorInitializationException {
try {
// Configure SSL.
final SslContext sslCtx;
if (SSL) {
sslCtx = SslContext.newClientContext(InsecureTrustManagerFactory.INSTANCE);
} else {
sslCtx = null;
}
Bootstrap b = new Bootstrap();
b.group(group).channel(NioSocketChannel.class).handler(new ExtractorClientInitializer<T>(sslCtx));
// Make a new connection.
this.ch = b.connect(HOST, PORT).sync().channel();
// Get the handler instance to initiate the request.
this.handler = ch.pipeline().get(ExtractorClientHandler.class);
} catch (SSLException | InterruptedException e) {
throw new DeepExtractorInitializationException(e);
}
return this;
}