use of org.apache.flink.shaded.netty4.io.netty.handler.ssl.SslHandler in project pulsar by yahoo.
the class ServerConnection method handleConnect.
/**
* handles connect request and sends {@code State.Connected} ack to client
*/
@Override
protected void handleConnect(CommandConnect connect) {
checkArgument(state == State.Start);
if (LOG.isDebugEnabled()) {
LOG.debug("Received CONNECT from {}", remoteAddress);
}
if (service.getConfiguration().isAuthenticationEnabled()) {
try {
String authMethod = "none";
if (connect.hasAuthMethodName()) {
authMethod = connect.getAuthMethodName();
} else if (connect.hasAuthMethod()) {
// Legacy client is passing enum
authMethod = connect.getAuthMethod().name().substring(10).toLowerCase();
}
String authData = connect.getAuthData().toStringUtf8();
ChannelHandler sslHandler = ctx.channel().pipeline().get(TLS_HANDLER);
SSLSession sslSession = null;
if (sslHandler != null) {
sslSession = ((SslHandler) sslHandler).engine().getSession();
}
authRole = service.getAuthenticationService().authenticate(new AuthenticationDataCommand(authData, remoteAddress, sslSession), authMethod);
LOG.info("[{}] Client successfully authenticated with {} role {}", remoteAddress, authMethod, authRole);
} catch (AuthenticationException e) {
String msg = "Unable to authenticate";
LOG.warn("[{}] {}: {}", remoteAddress, msg, e.getMessage());
ctx.writeAndFlush(Commands.newError(-1, ServerError.AuthenticationError, msg));
close();
return;
}
}
ctx.writeAndFlush(Commands.newConnected(connect));
state = State.Connected;
remoteEndpointProtocolVersion = connect.getProtocolVersion();
}
use of org.apache.flink.shaded.netty4.io.netty.handler.ssl.SslHandler in project async-http-client by AsyncHttpClient.
the class ChannelManager method createSslHandler.
private SslHandler createSslHandler(String peerHost, int peerPort) {
SSLEngine sslEngine = sslEngineFactory.newSslEngine(config, peerHost, peerPort);
SslHandler sslHandler = new SslHandler(sslEngine);
if (handshakeTimeout > 0)
sslHandler.setHandshakeTimeoutMillis(handshakeTimeout);
return sslHandler;
}
use of org.apache.flink.shaded.netty4.io.netty.handler.ssl.SslHandler in project camel by apache.
the class DefaultClientInitializerFactory method initChannel.
protected void initChannel(Channel ch) throws Exception {
// create a new pipeline
ChannelPipeline channelPipeline = ch.pipeline();
SslHandler sslHandler = configureClientSSLOnDemand();
if (sslHandler != null) {
//TODO must close on SSL exception
//sslHandler.setCloseOnSSLException(true);
LOG.debug("Client SSL handler configured and added to the ChannelPipeline: {}", sslHandler);
addToPipeline("ssl", channelPipeline, sslHandler);
}
List<ChannelHandler> decoders = producer.getConfiguration().getDecoders();
for (int x = 0; x < decoders.size(); x++) {
ChannelHandler decoder = decoders.get(x);
if (decoder instanceof ChannelHandlerFactory) {
// use the factory to create a new instance of the channel as it may not be shareable
decoder = ((ChannelHandlerFactory) decoder).newChannelHandler();
}
addToPipeline("decoder-" + x, channelPipeline, decoder);
}
List<ChannelHandler> encoders = producer.getConfiguration().getEncoders();
for (int x = 0; x < encoders.size(); x++) {
ChannelHandler encoder = encoders.get(x);
if (encoder instanceof ChannelHandlerFactory) {
// use the factory to create a new instance of the channel as it may not be shareable
encoder = ((ChannelHandlerFactory) encoder).newChannelHandler();
}
addToPipeline("encoder-" + x, channelPipeline, encoder);
}
// do we use request timeout?
if (producer.getConfiguration().getRequestTimeout() > 0) {
if (LOG.isTraceEnabled()) {
LOG.trace("Using request timeout {} millis", producer.getConfiguration().getRequestTimeout());
}
ChannelHandler timeout = new ReadTimeoutHandler(producer.getConfiguration().getRequestTimeout(), TimeUnit.MILLISECONDS);
addToPipeline("timeout", channelPipeline, timeout);
}
// our handler must be added last
addToPipeline("handler", channelPipeline, new ClientChannelHandler(producer));
LOG.trace("Created ChannelPipeline: {}", channelPipeline);
}
use of org.apache.flink.shaded.netty4.io.netty.handler.ssl.SslHandler in project ambry by linkedin.
the class NettyServerChannelInitializer method initChannel.
@Override
protected void initChannel(SocketChannel ch) throws Exception {
// If channel handler implementations are not annotated with @Sharable, Netty creates a new instance of every class
// in the pipeline for every connection.
// i.e. if there are a 1000 active connections there will be a 1000 NettyMessageProcessor instances.
ChannelPipeline pipeline = ch.pipeline();
// connection stats handler to track connection related metrics
pipeline.addLast("connectionStatsHandler", connectionStatsHandler);
// if SSL is enabled, add an SslHandler before the HTTP codec
if (sslFactory != null) {
InetSocketAddress peerAddress = ch.remoteAddress();
pipeline.addLast("sslHandler", new SslHandler(sslFactory.createSSLEngine(peerAddress.getHostName(), peerAddress.getPort(), SSLFactory.Mode.SERVER)));
}
pipeline.addLast("codec", new HttpServerCodec(nettyConfig.nettyServerMaxInitialLineLength, nettyConfig.nettyServerMaxHeaderSize, nettyConfig.nettyServerMaxChunkSize)).addLast("healthCheckHandler", new HealthCheckHandler(restServerState, nettyMetrics)).addLast("publicAccessLogHandler", new PublicAccessLogHandler(publicAccessLogger, nettyMetrics)).addLast("idleStateHandler", new IdleStateHandler(0, 0, nettyConfig.nettyServerIdleTimeSeconds)).addLast("chunker", new ChunkedWriteHandler()).addLast("processor", new NettyMessageProcessor(nettyMetrics, nettyConfig, requestHandler));
}
use of org.apache.flink.shaded.netty4.io.netty.handler.ssl.SslHandler in project ambry by linkedin.
the class PublicAccessLogHandler method logSSLInfo.
/**
* If this is an SSL channel, log information about the peer certificate.
* @param ctx the {@link ChannelHandlerContext} for this channel.
*/
private void logSSLInfo(ChannelHandlerContext ctx) {
if (sslLogMessage == null) {
sslLogMessage = new StringBuilder();
sslLogMessage.append("SSL (");
try {
SslHandler sslHandler = ctx.pipeline().get(SslHandler.class);
boolean sslUsed = sslHandler != null;
sslLogMessage.append("[used=").append(sslUsed).append("]");
if (sslUsed) {
SSLEngine sslEngine = sslHandler.engine();
if (sslEngine.getNeedClientAuth()) {
for (Certificate certificate : sslEngine.getSession().getPeerCertificates()) {
if (certificate instanceof X509Certificate) {
X500Principal principal = ((X509Certificate) certificate).getSubjectX500Principal();
Collection subjectAlternativeNames = ((X509Certificate) certificate).getSubjectAlternativeNames();
sslLogMessage.append(", [principal=").append(principal).append("]");
sslLogMessage.append(", [san=").append(subjectAlternativeNames).append("]");
}
}
}
}
} catch (Exception e) {
logger.error("Unexpected error while getting SSL connection info for public access logger", e);
}
sslLogMessage.append(")");
}
logMessage.append(sslLogMessage);
}
Aggregations