Top Description Fields Constructors Methods
io.netty5.handler.ssl

pack-priv final Class SslUtils

extends Object
Class Inheritance
Imports
io.netty5.buffer.Buffer, .BufferAllocator, io.netty5.channel.ChannelHandlerContext, io.netty5.handler.codec.base64.Base64, .Base64Dialect, io.netty5.util.NetUtil, io.netty5.util.internal.EmptyArrays, .StringUtil, io.netty5.util.internal.logging.InternalLogger, .InternalLoggerFactory, javax.net.ssl.SSLContext, .SSLHandshakeException, .SSLSession, .TrustManager, java.nio.ByteBuffer, .ByteOrder, java.security.KeyManagementException, .NoSuchAlgorithmException, .NoSuchProviderException, .Provider, java.util.Collections, .LinkedHashSet, .List, .Set

Constants for SSL packets.

Field Summary

Modifier and TypeField and Description
pack-priv static final String[]
pack-priv static final String[]
pack-priv static final TrustManager[]
pack-priv static final int
GMSSL_PROTOCOL_VERSION

GMSSL Protocol Version

pack-priv static final String
private static final InternalLogger
pack-priv static final int
NOT_ENCRYPTED

data is not encrypted

pack-priv static final int
NOT_ENOUGH_DATA

Not enough data in buffer to parse the record length

pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
SSL_RECORD_HEADER_LENGTH

the length of the ssl record header (in bytes)

pack-priv static final String[]
pack-priv static final Set<String>
private static final boolean
private static final boolean

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv static void
addIfSupported(Set<String> supported, List<String> enabled, String... names)

Add elements from names into enabled if they are in supported.

pack-priv static boolean
arrayContains(String[] array, String value)

pack-priv static int

Returns:

length The length of the encrypted packet that is included in the buffer or SslUtils#NOT_ENOUGH_DATA if not enough data is present in the Buffer. This will return SslUtils#NOT_ENCRYPTED if the given Buffer is not encrypted at all.
getEncryptedPacketLength
(Buffer
The Buffer to read from. Be aware it must have at least SSL_RECORD_HEADER_LENGTH bytes to read, otherwise it will throw an IllegalArgumentException.
buffer
,
int offset)

Return how many bytes can be read out of the encrypted data.

pack-priv static int
getEncryptedPacketLength(ByteBuffer[] buffers, int offset)

private static int
pack-priv static SSLContext
private static String
pack-priv static void
handleHandshakeFailure(ChannelHandlerContext ctx, SSLSession session, String applicationProtocol, Throwable cause, boolean notify)

pack-priv static boolean
isTLSv13Cipher(String cipher)

Returns true if the given cipher (in openssl format) is for TLSv1.3, false otherwise.

pack-priv static boolean
isTLSv13EnabledByJDK(Provider provider)

Returns true if the JDK itself supports TLSv1.3 and enabled it by default, false otherwise.

private static boolean
pack-priv static boolean
isTLSv13SupportedByJDK(Provider provider)

Returns true if the JDK itself supports TLSv1.3, false otherwise.

private static boolean
pack-priv static boolean
isValidHostNameForSNI(String hostname)

Validate that the given hostname can be used in SNI extension.

private static SSLContext
private static short
shortBE(ByteBuffer buffer, int offset)

pack-priv static Buffer
toBase64(BufferAllocator allocator, Buffer src)

Same as Base64#encode(Buffer, boolean) but uses Buffer and allows the use of a custom BufferAllocator.

pack-priv static SSLHandshakeException
toSSLHandshakeException(Throwable e)

Converts the given exception to a SSLHandshakeException, if it isn't already.

private static short
unsignedByte(byte b)

private static int
unsignedShortBE(ByteBuffer buffer, int offset)

pack-priv static void
useFallbackCiphersIfDefaultIsEmpty(List<String> defaultCiphers, Iterable<String> fallbackCiphers)

pack-priv static void
useFallbackCiphersIfDefaultIsEmpty(List<String> defaultCiphers, String... fallbackCiphers)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEFAULT_CIPHER_SUITESback to summary
pack-priv static final String[] DEFAULT_CIPHER_SUITES
DEFAULT_TLSV13_CIPHER_SUITESback to summary
pack-priv static final String[] DEFAULT_TLSV13_CIPHER_SUITES
EMPTY_TRUST_MANAGERSback to summary
pack-priv static final TrustManager[] EMPTY_TRUST_MANAGERS
GMSSL_PROTOCOL_VERSIONback to summary
pack-priv static final int GMSSL_PROTOCOL_VERSION

GMSSL Protocol Version

INVALID_CIPHERback to summary
pack-priv static final String INVALID_CIPHER
loggerback to summary
private static final InternalLogger logger
NOT_ENCRYPTEDback to summary
pack-priv static final int NOT_ENCRYPTED

data is not encrypted

NOT_ENOUGH_DATAback to summary
pack-priv static final int NOT_ENOUGH_DATA

Not enough data in buffer to parse the record length

SSL_CONTENT_TYPE_ALERTback to summary
pack-priv static final int SSL_CONTENT_TYPE_ALERT

alert

SSL_CONTENT_TYPE_APPLICATION_DATAback to summary
pack-priv static final int SSL_CONTENT_TYPE_APPLICATION_DATA

application data

SSL_CONTENT_TYPE_CHANGE_CIPHER_SPECback to summary
pack-priv static final int SSL_CONTENT_TYPE_CHANGE_CIPHER_SPEC

change cipher spec

SSL_CONTENT_TYPE_EXTENSION_HEARTBEATback to summary
pack-priv static final int SSL_CONTENT_TYPE_EXTENSION_HEARTBEAT

HeartBeat Extension

SSL_CONTENT_TYPE_HANDSHAKEback to summary
pack-priv static final int SSL_CONTENT_TYPE_HANDSHAKE

handshake

SSL_RECORD_HEADER_LENGTHback to summary
pack-priv static final int SSL_RECORD_HEADER_LENGTH

the length of the ssl record header (in bytes)

TLSV13_CIPHER_SUITESback to summary
pack-priv static final String[] TLSV13_CIPHER_SUITES
TLSV13_CIPHERSback to summary
pack-priv static final Set<String> TLSV13_CIPHERS
TLSV1_3_JDK_DEFAULT_ENABLEDback to summary
private static final boolean TLSV1_3_JDK_DEFAULT_ENABLED
TLSV1_3_JDK_SUPPORTEDback to summary
private static final boolean TLSV1_3_JDK_SUPPORTED

Constructor Detail

SslUtilsback to summary
private SslUtils()

Method Detail

addIfSupportedback to summary
pack-priv static void addIfSupported(Set<String> supported, List<String> enabled, String... names)

Add elements from names into enabled if they are in supported.

arrayContainsback to summary
pack-priv static boolean arrayContains(String[] array, String value)
getEncryptedPacketLengthback to summary
pack-priv static int getEncryptedPacketLength(Buffer buffer, int offset)

Return how many bytes can be read out of the encrypted data. Be aware this method will not increase the readerIndex of the given Buffer.

Parameters
buffer:Buffer

The Buffer to read from. Be aware it must have at least SSL_RECORD_HEADER_LENGTH bytes to read, otherwise it will throw an IllegalArgumentException.

Returns:int

length The length of the encrypted packet that is included in the buffer or SslUtils#NOT_ENOUGH_DATA if not enough data is present in the Buffer. This will return SslUtils#NOT_ENCRYPTED if the given Buffer is not encrypted at all.

Exceptions
IllegalArgumentException:
Is thrown if the given Buffer has not at least SSL_RECORD_HEADER_LENGTH bytes to read.
getEncryptedPacketLengthback to summary
pack-priv static int getEncryptedPacketLength(ByteBuffer[] buffers, int offset)
getEncryptedPacketLengthback to summary
private static int getEncryptedPacketLength(ByteBuffer buffer)
getSSLContextback to summary
pack-priv static SSLContext getSSLContext(String provider) throws NoSuchAlgorithmException, KeyManagementException, NoSuchProviderException
getTlsVersionback to summary
private static String getTlsVersion()
handleHandshakeFailureback to summary
pack-priv static void handleHandshakeFailure(ChannelHandlerContext ctx, SSLSession session, String applicationProtocol, Throwable cause, boolean notify)
isTLSv13Cipherback to summary
pack-priv static boolean isTLSv13Cipher(String cipher)

Returns true if the given cipher (in openssl format) is for TLSv1.3, false otherwise.

isTLSv13EnabledByJDKback to summary
pack-priv static boolean isTLSv13EnabledByJDK(Provider provider)

Returns true if the JDK itself supports TLSv1.3 and enabled it by default, false otherwise.

isTLSv13EnabledByJDK0back to summary
private static boolean isTLSv13EnabledByJDK0(Provider provider)
isTLSv13SupportedByJDKback to summary
pack-priv static boolean isTLSv13SupportedByJDK(Provider provider)

Returns true if the JDK itself supports TLSv1.3, false otherwise.

isTLSv13SupportedByJDK0back to summary
private static boolean isTLSv13SupportedByJDK0(Provider provider)
isValidHostNameForSNIback to summary
pack-priv static boolean isValidHostNameForSNI(String hostname)

Validate that the given hostname can be used in SNI extension.

newInitContextback to summary
private static SSLContext newInitContext(Provider provider) throws NoSuchAlgorithmException, KeyManagementException
shortBEback to summary
private static short shortBE(ByteBuffer buffer, int offset)
toBase64back to summary
pack-priv static Buffer toBase64(BufferAllocator allocator, Buffer src)

Same as Base64#encode(Buffer, boolean) but uses Buffer and allows the use of a custom BufferAllocator.

See Also
Base64#encode(Buffer, boolean)
toSSLHandshakeExceptionback to summary
pack-priv static SSLHandshakeException toSSLHandshakeException(Throwable e)

Converts the given exception to a SSLHandshakeException, if it isn't already.

unsignedByteback to summary
private static short unsignedByte(byte b)
unsignedShortBEback to summary
private static int unsignedShortBE(ByteBuffer buffer, int offset)
useFallbackCiphersIfDefaultIsEmptyback to summary
pack-priv static void useFallbackCiphersIfDefaultIsEmpty(List<String> defaultCiphers, Iterable<String> fallbackCiphers)
useFallbackCiphersIfDefaultIsEmptyback to summary
pack-priv static void useFallbackCiphersIfDefaultIsEmpty(List<String> defaultCiphers, String... fallbackCiphers)