public class SSLUtilities
extends java.lang.Object
SSLContext
and SSLSocket
objects using JKS files (Or other supported formats).Constructor and Description |
---|
SSLUtilities() |
Modifier and Type | Method and Description |
---|---|
static javax.net.ssl.SSLSocket |
getSSLClientSocket(javax.net.ssl.SSLContext sslContext,
java.lang.String host,
int port)
Creates a new
SSLSocket using the specified SSLContext , host and port. |
static javax.net.ssl.SSLContext |
getSSLContext(java.lang.String algorithmName,
java.security.KeyStore unifiedKeyStore,
char[] keyStorePassword)
Gets the SSL context merged with the JRE Trust Store using a unified
KeyStore . |
static javax.net.ssl.SSLContext |
getSSLContext(java.lang.String algorithmName,
java.security.KeyStore privateKeyStore,
char[] privateKeyStorePassword,
java.security.KeyStore trustKeyStore)
Gets the SSL context merged with the JRE Trust Store using separate private and trust
KeyStore s. |
static javax.net.ssl.SSLContext |
getSSLContextNoJRETrust(java.lang.String algorithmName,
java.security.KeyStore unifiedKeyStore,
char[] keyStorePassword)
Gets the SSL context without the JRE Trust Store using a unified
KeyStore . |
static javax.net.ssl.SSLContext |
getSSLContextNoJRETrust(java.lang.String algorithmName,
java.security.KeyStore privateKeyStore,
char[] privateKeyStorePassword,
java.security.KeyStore trustKeyStore)
Gets the SSL context without the JRE Trust Store using separate private and trust
KeyStore s. |
static javax.net.ssl.SSLServerSocket |
getSSLServerSocket(javax.net.ssl.SSLContext sslContext,
int port,
int backlog,
java.net.InetAddress ifAddress)
Gets the SSL Server socket for the specified
SSLContext , port, backlog and InetAddress . |
static java.security.KeyStore |
loadKeyStore(java.lang.String type,
java.io.File file,
java.lang.String password)
Loads a Keystore of a certain type from a file given the password.
|
static javax.net.ssl.SSLSocket |
upgradeClientSocketToSSL(javax.net.ssl.SSLContext sslContext,
java.net.Socket socket,
java.lang.String host,
int port,
boolean autoClose)
Upgrades an existing
Socket to an SSLSocket using the specified SSLContext ,
Socket , host, port and if the specified socket should be closed when the returned socket is closed. |
static javax.net.ssl.SSLSocket |
upgradeClientSocketToSSL(javax.net.ssl.SSLContext sslContext,
java.net.Socket socket,
java.lang.String host,
int port,
boolean autoClose,
boolean onClient)
Upgrades an existing
Socket to an SSLSocket using the specified SSLContext ,
Socket , host, port and if the specified socket should be closed when the returned socket is closed. |
public static java.security.KeyStore loadKeyStore(java.lang.String type, java.io.File file, java.lang.String password) throws SSLUtilityException
type
- The type of keystore (pass null for the default type).file
- The file to load the keystore from.password
- The password of the keystore (Can be null).java.lang.NullPointerException
- file is null.SSLUtilityException
- An Exception has occurred.public static javax.net.ssl.SSLContext getSSLContextNoJRETrust(java.lang.String algorithmName, java.security.KeyStore unifiedKeyStore, char[] keyStorePassword) throws SSLUtilityException
KeyStore
.algorithmName
- The name of the context protocol or null for the JRE Default (TLSv1).unifiedKeyStore
- The keystore for use with the private and trust stores.keyStorePassword
- The password of the key store or null (Use "changeit" for JKS keystore defaults).SSLUtilityException
- An Exception has occurred.public static javax.net.ssl.SSLContext getSSLContextNoJRETrust(java.lang.String algorithmName, java.security.KeyStore privateKeyStore, char[] privateKeyStorePassword, java.security.KeyStore trustKeyStore) throws SSLUtilityException
KeyStore
s.algorithmName
- The name of the context protocol or null for the JRE Default (TLSv1).privateKeyStore
- The keystore for use with the private store.privateKeyStorePassword
- The password of the private key store or null (Use "changeit" for JKS keystore defaults).trustKeyStore
- The keystore for use with the trust store.SSLUtilityException
- An Exception has occurred.public static javax.net.ssl.SSLContext getSSLContext(java.lang.String algorithmName, java.security.KeyStore unifiedKeyStore, char[] keyStorePassword) throws SSLUtilityException
KeyStore
.algorithmName
- The name of the context protocol or null for the JRE Default (TLSv1).unifiedKeyStore
- The keystore for use with the private and trust stores.keyStorePassword
- The password of the key store or null (Use "changeit" for JKS keystore defaults).SSLUtilityException
- An Exception has occurred.public static javax.net.ssl.SSLContext getSSLContext(java.lang.String algorithmName, java.security.KeyStore privateKeyStore, char[] privateKeyStorePassword, java.security.KeyStore trustKeyStore) throws SSLUtilityException
KeyStore
s.algorithmName
- The name of the context protocol or null for the JRE Default (TLSv1).privateKeyStore
- The keystore for use with the private store.privateKeyStorePassword
- The password of the private key store or null (Use "changeit" for JKS keystore defaults).trustKeyStore
- The keystore for use with the trust store.SSLUtilityException
- An Exception has occurred.public static javax.net.ssl.SSLSocket getSSLClientSocket(javax.net.ssl.SSLContext sslContext, java.lang.String host, int port) throws SSLUtilityException
SSLSocket
using the specified SSLContext
, host and port.sslContext
- The SSL Context to create the socket from.host
- The host to connect to.port
- The port to connect to.SSLUtilityException
- An Exception has occurred.public static javax.net.ssl.SSLSocket upgradeClientSocketToSSL(javax.net.ssl.SSLContext sslContext, java.net.Socket socket, java.lang.String host, int port, boolean autoClose) throws SSLUtilityException
Socket
to an SSLSocket
using the specified SSLContext
,
Socket
, host, port and if the specified socket should be closed when the returned socket is closed.
This socket is in client mode (Upgrade for client side).sslContext
- The SSL Context to create the socket from.socket
- The socket to wrap.host
- The host to "connect" to.port
- The port to "connect" to.autoClose
- If the underlying socket should be closed when the returned socket is closed.SSLUtilityException
- An Exception has occurred.public static javax.net.ssl.SSLSocket upgradeClientSocketToSSL(javax.net.ssl.SSLContext sslContext, java.net.Socket socket, java.lang.String host, int port, boolean autoClose, boolean onClient) throws SSLUtilityException
Socket
to an SSLSocket
using the specified SSLContext
,
Socket
, host, port and if the specified socket should be closed when the returned socket is closed.sslContext
- The SSL Context to create the socket from.socket
- The socket to wrap.host
- The host to "connect" to.port
- The port to "connect" to.autoClose
- If the underlying socket should be closed when the returned socket is closed.onClient
- Is this being called on the client side.SSLUtilityException
- An Exception has occurred.public static javax.net.ssl.SSLServerSocket getSSLServerSocket(javax.net.ssl.SSLContext sslContext, int port, int backlog, java.net.InetAddress ifAddress) throws SSLUtilityException
SSLContext
, port, backlog and InetAddress
.sslContext
- The SSL Context to create the socket from.port
- The port to listen on.backlog
- The number of connections that can be queued.ifAddress
- The network interface to listen on (null means listen on all network interfaces).SSLUtilityException
- An Exception has occurred.