Home / Class/ SslClientHelloHandler Class — netty Architecture

SslClientHelloHandler Class — netty Architecture

Architecture documentation for the SslClientHelloHandler class in SslClientHelloHandler.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  4135ba3a_6a80_65ac_0a45_d76f228bf4b3["SslClientHelloHandler"]
  a4a32ba9_a932_f968_3581_82580b35b9c4["SslClientHelloHandler.java"]
  4135ba3a_6a80_65ac_0a45_d76f228bf4b3 -->|defined in| a4a32ba9_a932_f968_3581_82580b35b9c4
  4b866222_7fd5_ad93_a679_b3a4ea12ecc7["SslClientHelloHandler()"]
  4135ba3a_6a80_65ac_0a45_d76f228bf4b3 -->|method| 4b866222_7fd5_ad93_a679_b3a4ea12ecc7
  fc4692ec_d0ce_218f_173c_dac045c2e3db["decode()"]
  4135ba3a_6a80_65ac_0a45_d76f228bf4b3 -->|method| fc4692ec_d0ce_218f_173c_dac045c2e3db
  251405e8_5602_8f5c_dc00_d78362a2ad46["releaseHandshakeBuffer()"]
  4135ba3a_6a80_65ac_0a45_d76f228bf4b3 -->|method| 251405e8_5602_8f5c_dc00_d78362a2ad46
  aad0c403_9665_0039_bb8e_9dc3ca43c8f9["releaseIfNotNull()"]
  4135ba3a_6a80_65ac_0a45_d76f228bf4b3 -->|method| aad0c403_9665_0039_bb8e_9dc3ca43c8f9
  0d8db5ff_601a_a9ee_8f6b_b642c82a3338["select()"]
  4135ba3a_6a80_65ac_0a45_d76f228bf4b3 -->|method| 0d8db5ff_601a_a9ee_8f6b_b642c82a3338
  c453295c_f31f_5ce7_47d1_4eaa8146e6f4["handlerRemoved0()"]
  4135ba3a_6a80_65ac_0a45_d76f228bf4b3 -->|method| c453295c_f31f_5ce7_47d1_4eaa8146e6f4
  fe7fefdf_0409_b17b_3b5c_9b5bdd163e17["lookup()"]
  4135ba3a_6a80_65ac_0a45_d76f228bf4b3 -->|method| fe7fefdf_0409_b17b_3b5c_9b5bdd163e17
  3bf6f621_6e8a_91c3_a949_a3b14cedf419["onLookupComplete()"]
  4135ba3a_6a80_65ac_0a45_d76f228bf4b3 -->|method| 3bf6f621_6e8a_91c3_a949_a3b14cedf419
  5e320866_c45e_a161_a4a6_288d9108c0f0["read()"]
  4135ba3a_6a80_65ac_0a45_d76f228bf4b3 -->|method| 5e320866_c45e_a161_a4a6_288d9108c0f0
  bfed7d7b_7e34_256c_eea1_100b21dbebb4["bind()"]
  4135ba3a_6a80_65ac_0a45_d76f228bf4b3 -->|method| bfed7d7b_7e34_256c_eea1_100b21dbebb4
  42fe4bb3_8fc3_2474_094a_0c87afe16249["connect()"]
  4135ba3a_6a80_65ac_0a45_d76f228bf4b3 -->|method| 42fe4bb3_8fc3_2474_094a_0c87afe16249
  edec83cf_f4b9_d740_7054_ac621e0274be["disconnect()"]
  4135ba3a_6a80_65ac_0a45_d76f228bf4b3 -->|method| edec83cf_f4b9_d740_7054_ac621e0274be
  5cafedcb_885d_df8a_c7c4_eac181ae59a0["close()"]
  4135ba3a_6a80_65ac_0a45_d76f228bf4b3 -->|method| 5cafedcb_885d_df8a_c7c4_eac181ae59a0

Relationship Graph

Source Code

handler/src/main/java/io/netty/handler/ssl/SslClientHelloHandler.java lines 39–341

public abstract class SslClientHelloHandler<T> extends ByteToMessageDecoder implements ChannelOutboundHandler {

    /**
     * The maximum length of client hello message as defined by
     * <a href="https://www.rfc-editor.org/rfc/rfc5246#section-6.2.1">RFC5246</a>.
     */
    public static final int MAX_CLIENT_HELLO_LENGTH = 0xFFFFFF;

    private static final InternalLogger logger =
            InternalLoggerFactory.getInstance(SslClientHelloHandler.class);

    private final int maxClientHelloLength;
    private boolean handshakeFailed;
    private boolean suppressRead;
    private boolean readPending;
    private ByteBuf handshakeBuffer;

    public SslClientHelloHandler() {
        this(MAX_CLIENT_HELLO_LENGTH);
    }

    protected SslClientHelloHandler(int maxClientHelloLength) {
        // 16MB is the maximum as per RFC:
        // See https://www.rfc-editor.org/rfc/rfc5246#section-6.2.1
        this.maxClientHelloLength =
                ObjectUtil.checkInRange(maxClientHelloLength, 0, MAX_CLIENT_HELLO_LENGTH, "maxClientHelloLength");
    }

    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
        if (!suppressRead && !handshakeFailed) {
            try {
                int readerIndex = in.readerIndex();
                int readableBytes = in.readableBytes();
                int handshakeLength = -1;

                // Check if we have enough data to determine the record type and length.
                while (readableBytes >= SslUtils.SSL_RECORD_HEADER_LENGTH) {
                    final int contentType = in.getUnsignedByte(readerIndex);
                    switch (contentType) {
                        case SslUtils.SSL_CONTENT_TYPE_CHANGE_CIPHER_SPEC:
                            // fall-through
                        case SslUtils.SSL_CONTENT_TYPE_ALERT:
                            final int len = SslUtils.getEncryptedPacketLength(in, readerIndex, true);

                            // Not an SSL/TLS packet
                            if (len == SslUtils.NOT_ENCRYPTED) {
                                handshakeFailed = true;
                                NotSslRecordException e = new NotSslRecordException(
                                        "not an SSL/TLS record: " + ByteBufUtil.hexDump(in));
                                in.skipBytes(in.readableBytes());
                                ctx.fireUserEventTriggered(new SniCompletionEvent(e));
                                SslUtils.handleHandshakeFailure(ctx, e, true);
                                throw e;
                            }
                            if (len == SslUtils.NOT_ENOUGH_DATA) {
                                // Not enough data
                                return;
                            }
                            // No ClientHello
                            select(ctx, null);
                            return;
                        case SslUtils.SSL_CONTENT_TYPE_HANDSHAKE:
                            final int majorVersion = in.getUnsignedByte(readerIndex + 1);
                            // SSLv3 or TLS
                            if (majorVersion == 3) {
                                int packetLength = in.getUnsignedShort(readerIndex + 3) +
                                        SslUtils.SSL_RECORD_HEADER_LENGTH;

                                if (readableBytes < packetLength) {
                                    // client hello incomplete; try again to decode once more data is ready.
                                    return;
                                } else if (packetLength == SslUtils.SSL_RECORD_HEADER_LENGTH) {
                                    select(ctx, null);
                                    return;
                                }

                                final int endOffset = readerIndex + packetLength;

                                // Let's check if we already parsed the handshake length or not.
                                if (handshakeLength == -1) {

Frequently Asked Questions

What is the SslClientHelloHandler class?
SslClientHelloHandler is a class in the netty codebase, defined in handler/src/main/java/io/netty/handler/ssl/SslClientHelloHandler.java.
Where is SslClientHelloHandler defined?
SslClientHelloHandler is defined in handler/src/main/java/io/netty/handler/ssl/SslClientHelloHandler.java at line 39.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free