Package anbxj
Class Channel_SSLChannelUtils
java.lang.Object
anbxj.Channel_SSLChannelUtils
Utility methods for SSL/TLS channel setup, eliminating duplication across
client, server, proto-server and multi-threaded server implementations.
-
Method Summary
Modifier and TypeMethodDescriptionstatic SSLContextBuilds anSSLContextfrom the keystore settings and algorithm embedded in the givenChannel_Properties.static SSLServerSocketcreateSSLServerSocket(int port, Channel_Properties cp) Creates and configures anSSLServerSocketusing the channel properties.static String[]filterCipherSuites(Channel_SSLChannelType type, String[] supported) Filters the given list of supported cipher suites according to the desired SSL channel type.static SSLSocketwrapSocket(Socket plainSocket, Channel_Properties cp, boolean clientMode) Wraps an existing plain TCP socket in a TLS/SSL connection, performing the full handshake.
-
Method Details
-
createSSLContext
Builds anSSLContextfrom the keystore settings and algorithm embedded in the givenChannel_Properties.- Parameters:
cp- the channel properties (must contain TLS keystore settings)- Returns:
- a fully initialised
SSLContext - Throws:
RuntimeException- if the context cannot be created
-
wrapSocket
public static SSLSocket wrapSocket(Socket plainSocket, Channel_Properties cp, boolean clientMode) throws IOException Wraps an existing plain TCP socket in a TLS/SSL connection, performing the full handshake. This replaces the previous static method inChannel_SSLContextBuilderand the inline logic inChannel_Server.openStream(int).- Parameters:
plainSocket- the already-connected plain socket to upgradecp- channel properties determining SSL type, cipher suites, etc.clientMode-trueto set the socket into client mode,falsefor server mode- Returns:
- the handshaken
SSLSocket - Throws:
IOException- if the handshake fails or the socket cannot be wrapped
-
createSSLServerSocket
public static SSLServerSocket createSSLServerSocket(int port, Channel_Properties cp) throws IOException Creates and configures anSSLServerSocketusing the channel properties. This can be used directly byChannel_ProtoServerandChannel_MultiThreadedServer.- Parameters:
port- the port to listen oncp- the channel properties (used for cipher suites, client auth, etc.)- Returns:
- a configured
SSLServerSocket - Throws:
IOException- if the server socket cannot be created
-
filterCipherSuites
Filters the given list of supported cipher suites according to the desired SSL channel type. This replaces the logic previously inChannel_Settings.getEnabledCipherSuites(java.lang.String[]).- Parameters:
type- the SSL channel type (determines which suites are allowed)supported- all supported suites (must not benull)- Returns:
- the filtered array of suites to enable (never
null) - Throws:
NullPointerException- ifsupportedisnull
-