Java Code Examples for io.netty.handler.ssl.SslHandler#isEncrypted()

The following examples show how to use io.netty.handler.ssl.SslHandler#isEncrypted() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NonSslHandler.java    From hivemq-community-edition with Apache License 2.0 5 votes vote down vote up
@Override
protected void decode(final ChannelHandlerContext ctx, final ByteBuf in, final List<Object> out) throws Exception {

    //Needs minimum 5 bytes to be able to tell what it is.
    if (in.readableBytes() < 11) {
        return;
    }

    //Check for SSL bytes
    final boolean encrypted = SslHandler.isEncrypted(in);

    //With MQTT5 it is possible to craft a valid CONNECT packet, that matches an SSLv2 packet
    final boolean isConnectPacket = in.getUnsignedByte(0) == 16;
    final boolean isMqttPacket = in.getUnsignedByte(7) == 'M' &&
            in.getUnsignedByte(8) == 'Q' &&
            in.getUnsignedByte(9) == 'T' &&
            in.getUnsignedByte(10) == 'T';

    if (encrypted && !(isConnectPacket && isMqttPacket)) {
        log.debug("SSL connection on non-SSL listener, dropping connection.");
        in.clear();
        eventLog.clientWasDisconnected(ctx.channel(), "SSL connection to non-SSL listener");
        ctx.close();
        return;
    }

    ctx.pipeline().remove(this);
}
 
Example 2
Source File: PortUnificationServerHandler.java    From netty-4.1.22 with Apache License 2.0 4 votes vote down vote up
private boolean isSsl(ByteBuf buf) {
    if (detectSsl) {
        return SslHandler.isEncrypted(buf);
    }
    return false;
}
 
Example 3
Source File: PortUnificationServerHandler.java    From sctalk with Apache License 2.0 4 votes vote down vote up
private boolean isSsl(ByteBuf buf) {
    if (detectSsl) {
        return SslHandler.isEncrypted(buf);
    }
    return false;
}
 
Example 4
Source File: PortUnificationServerHandler.java    From netty4.0.27Learn with Apache License 2.0 4 votes vote down vote up
private boolean isSsl(ByteBuf buf) {
    if (detectSsl) {
        return SslHandler.isEncrypted(buf);
    }
    return false;
}