decode() — netty Function Reference
Architecture documentation for the decode() function in SslClientHelloHandler.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD fc4692ec_d0ce_218f_173c_dac045c2e3db["decode()"] 4135ba3a_6a80_65ac_0a45_d76f228bf4b3["SslClientHelloHandler"] fc4692ec_d0ce_218f_173c_dac045c2e3db -->|defined in| 4135ba3a_6a80_65ac_0a45_d76f228bf4b3 0d8db5ff_601a_a9ee_8f6b_b642c82a3338["select()"] fc4692ec_d0ce_218f_173c_dac045c2e3db -->|calls| 0d8db5ff_601a_a9ee_8f6b_b642c82a3338 style fc4692ec_d0ce_218f_173c_dac045c2e3db fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
handler/src/main/java/io/netty/handler/ssl/SslClientHelloHandler.java lines 67–204
@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) {
if (readerIndex + 4 > endOffset) {
// Need more data to read HandshakeType and handshakeLength (4 bytes)
return;
}
final int handshakeType = in.getUnsignedByte(readerIndex +
SslUtils.SSL_RECORD_HEADER_LENGTH);
// Check if this is a clientHello(1)
// See https://tools.ietf.org/html/rfc5246#section-7.4
if (handshakeType != 1) {
select(ctx, null);
return;
}
// Read the length of the handshake as it may arrive in fragments
// See https://tools.ietf.org/html/rfc5246#section-7.4
handshakeLength = in.getUnsignedMedium(readerIndex +
SslUtils.SSL_RECORD_HEADER_LENGTH + 1);
if (handshakeLength > maxClientHelloLength && maxClientHelloLength != 0) {
TooLongFrameException e = new TooLongFrameException(
"ClientHello length exceeds " + maxClientHelloLength +
": " + handshakeLength);
in.skipBytes(in.readableBytes());
ctx.fireUserEventTriggered(new SniCompletionEvent(e));
SslUtils.handleHandshakeFailure(ctx, e, true);
throw e;
Domain
Subdomains
Calls
Source
Frequently Asked Questions
What does decode() do?
decode() is a function in the netty codebase, defined in handler/src/main/java/io/netty/handler/ssl/SslClientHelloHandler.java.
Where is decode() defined?
decode() is defined in handler/src/main/java/io/netty/handler/ssl/SslClientHelloHandler.java at line 67.
What does decode() call?
decode() calls 1 function(s): select.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free