use of org.apache.flink.shaded.netty4.io.netty.handler.ssl.SslHandler in project cassandra by apache.
the class PipelineConfigurator method encryptionConfig.
protected EncryptionConfig encryptionConfig() {
final EncryptionOptions encryptionOptions = DatabaseDescriptor.getNativeProtocolEncryptionOptions();
switch(tlsEncryptionPolicy) {
case UNENCRYPTED:
// if encryption is not enabled, no further steps are required after the initial setup
return channel -> {
};
case OPTIONAL:
// If optional, install a handler which detects whether or not the client is sending
// encrypted bytes. If so, on receipt of the next bytes, replace that handler with
// an SSL Handler, otherwise just remove it and proceed with an unencrypted channel.
logger.debug("Enabling optionally encrypted CQL connections between client and server");
return channel -> {
SslContext sslContext = SSLFactory.getOrCreateSslContext(encryptionOptions, encryptionOptions.require_client_auth, ISslContextFactory.SocketType.SERVER);
channel.pipeline().addFirst(SSL_HANDLER, new ByteToMessageDecoder() {
@Override
protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> list) throws Exception {
if (byteBuf.readableBytes() < 5) {
// once more bytes a ready.
return;
}
if (SslHandler.isEncrypted(byteBuf)) {
// Connection uses SSL/TLS, replace the detection handler with a SslHandler and so use
// encryption.
SslHandler sslHandler = sslContext.newHandler(channel.alloc());
channelHandlerContext.pipeline().replace(SSL_HANDLER, SSL_HANDLER, sslHandler);
} else {
// Connection use no TLS/SSL encryption, just remove the detection handler and continue without
// SslHandler in the pipeline.
channelHandlerContext.pipeline().remove(SSL_HANDLER);
}
}
});
};
case ENCRYPTED:
logger.debug("Enabling encrypted CQL connections between client and server");
return channel -> {
SslContext sslContext = SSLFactory.getOrCreateSslContext(encryptionOptions, encryptionOptions.require_client_auth, ISslContextFactory.SocketType.SERVER);
channel.pipeline().addFirst(SSL_HANDLER, sslContext.newHandler(channel.alloc()));
};
default:
throw new IllegalStateException("Unrecognized TLS encryption policy: " + this.tlsEncryptionPolicy);
}
}
use of org.apache.flink.shaded.netty4.io.netty.handler.ssl.SslHandler in project cassandra by apache.
the class ServerConnection method certificates.
private X509Certificate[] certificates() {
SslHandler sslHandler = (SslHandler) channel().pipeline().get("ssl");
X509Certificate[] certificates = null;
if (sslHandler != null) {
try {
certificates = sslHandler.engine().getSession().getPeerCertificateChain();
} catch (SSLPeerUnverifiedException e) {
logger.debug("Failed to get peer certificates for peer {}", channel().remoteAddress(), e);
}
}
return certificates;
}
use of org.apache.flink.shaded.netty4.io.netty.handler.ssl.SslHandler in project neo4j by neo4j.
the class ClientSideOnConnectSslHandler method connect.
/**
* Main event that is triggered for connections and swapping out SslHandler for this handler. channelActive and handlerAdded handlers are
* secondary boundary cases to this.
*
* @param ctx Context of the existing channel
* @param remoteAddress the address used for initating a connection to a remote host (has type InetSocketAddress)
* @param localAddress the local address that will be used for receiving responses from the remote host
* @param promise the Channel promise to notify once the operation completes
* @throws Exception when there is an error of any sort
*/
@Override
public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) throws Exception {
SslHandler sslHandler = createSslHandler(ctx, (InetSocketAddress) remoteAddress);
replaceSelfWith(sslHandler);
ctx.connect(remoteAddress, localAddress, promise);
}
use of org.apache.flink.shaded.netty4.io.netty.handler.ssl.SslHandler in project neo4j by neo4j.
the class TransportSelectionHandlerTest method channelHandlerContextMockSslAlreadyConfigured.
private static ChannelHandlerContext channelHandlerContextMockSslAlreadyConfigured() {
Channel channel = mock(Channel.class);
ChannelHandlerContext context = mock(ChannelHandlerContext.class);
ChannelPipeline pipeline = mock(ChannelPipeline.class);
SslHandler sslHandler = mock(SslHandler.class);
when(context.channel()).thenReturn(channel);
when(context.pipeline()).thenReturn(pipeline);
when(context.pipeline().get(SslHandler.class)).thenReturn(sslHandler);
return context;
}
use of org.apache.flink.shaded.netty4.io.netty.handler.ssl.SslHandler in project spring-framework by spring-projects.
the class ReactorServerHttpRequest method initSslInfo.
@Override
@Nullable
protected SslInfo initSslInfo() {
Channel channel = ((Connection) this.request).channel();
SslHandler sslHandler = channel.pipeline().get(SslHandler.class);
if (sslHandler == null && channel.parent() != null) {
// HTTP/2
sslHandler = channel.parent().pipeline().get(SslHandler.class);
}
if (sslHandler != null) {
SSLSession session = sslHandler.engine().getSession();
return new DefaultSslInfo(session);
}
return null;
}
Aggregations