Class SslContextFactory
java.lang.Object
com.loomcache.common.config.SslContextFactory
Factory for creating SSLContext, SSLServerSocket, SSLSocket, and optional
Netty SslContext instances from LoomCache TlsConfig.
The existing socket transport uses standard JDK SSLSocket (blocking I/O) which pairs well with Java 25 virtual threads — virtual threads unmount on blocking socket ops, so we get the simplicity of blocking TLS with the scalability of async. Netty SslContext creation is available for transports that can consume Netty's OpenSSL/BoringSSL provider via netty-tcnative.
Thread-safe: SSLContext is safe for concurrent use after initialization.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic SocketcreateClientSocket(TlsConfig config, SSLContext sslContext, String host, int port, int connectTimeoutMs) Create an SSL client socket connected to the given host:port.static io.netty.handler.ssl.SslContextcreateNettyClientContext(TlsConfig config) Create a Netty client SslContext from TlsConfig.static io.netty.handler.ssl.SslContextcreateNettyServerContext(TlsConfig config) Create a Netty server SslContext from TlsConfig.static ServerSocketcreateServerSocket(TlsConfig config, SSLContext sslContext, int port) Create an SSL server socket bound to the given port.static ServerSocketcreateServerSocket(TlsConfig config, SSLContext sslContext, @Nullable String bindHost, int port) static SSLContextcreateSslContext(TlsConfig config) Create an SSLContext from TlsConfig.static booleanWhether Netty's OpenSSL/BoringSSL provider is available in this process.static StringHuman-readable OpenSSL/BoringSSL provider status for diagnostics.
-
Constructor Details
-
SslContextFactory
public SslContextFactory()
-
-
Method Details
-
createSslContext
public static SSLContext createSslContext(TlsConfig config) throws GeneralSecurityException, IOException Create an SSLContext from TlsConfig.- Parameters:
config- TLS configuration (must be enabled)- Returns:
- initialized SSLContext
- Throws:
GeneralSecurityException- if keystore/truststore loading failsIOException- if keystore/truststore files cannot be read
-
createNettyServerContext
public static io.netty.handler.ssl.SslContext createNettyServerContext(TlsConfig config) throws GeneralSecurityException, IOException Create a Netty server SslContext from TlsConfig.- Parameters:
config- TLS configuration (must be enabled)- Returns:
- initialized Netty SslContext
- Throws:
GeneralSecurityException- if keystore/truststore loading or provider selection failsIOException- if keystore/truststore files cannot be read
-
createNettyClientContext
public static io.netty.handler.ssl.SslContext createNettyClientContext(TlsConfig config) throws GeneralSecurityException, IOException Create a Netty client SslContext from TlsConfig.- Parameters:
config- TLS configuration (must be enabled)- Returns:
- initialized Netty SslContext
- Throws:
GeneralSecurityException- if keystore/truststore loading or provider selection failsIOException- if keystore/truststore files cannot be read
-
isOpenSslAvailable
public static boolean isOpenSslAvailable()Whether Netty's OpenSSL/BoringSSL provider is available in this process.- Returns:
- true if Netty can create OpenSSL-backed contexts
-
openSslAvailabilityDescription
Human-readable OpenSSL/BoringSSL provider status for diagnostics.- Returns:
- availability description
-
createServerSocket
public static ServerSocket createServerSocket(TlsConfig config, SSLContext sslContext, int port) throws IOException Create an SSL server socket bound to the given port.- Parameters:
config- TLS configurationsslContext- the SSLContext to useport- the port to bind to- Returns:
- bound SSLServerSocket with configured protocols and cipher suites
- Throws:
IOException
-
createServerSocket
public static ServerSocket createServerSocket(TlsConfig config, SSLContext sslContext, @Nullable String bindHost, int port) throws IOException - Throws:
IOException
-
createClientSocket
public static Socket createClientSocket(TlsConfig config, SSLContext sslContext, String host, int port, int connectTimeoutMs) throws IOException Create an SSL client socket connected to the given host:port.- Parameters:
config- TLS configurationsslContext- the SSLContext to usehost- target hostport- target portconnectTimeoutMs- connection timeout in milliseconds- Returns:
- connected SSLSocket with configured protocols
- Throws:
IOException- if connection fails or hostname verification fails
-