java.lang.Object
org.seppiko.commons.utils.http.TLSUtil
HTTP TLS (SSLContext) utility
- Author:
- Leonard Woo
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final TrustManager[]Default Trust Managers, with trust all certificates.static final SSLContextDisableSSLContext -
Method Summary
Modifier and TypeMethodDescriptionstatic CertificateFactorygetCertFactory(Provider provider) Get X.509 certificate factorystatic SSLContextgetSSLContext(File certFile, String certPass) HTTP TLS Factory with TLS v1.2 and PKCS 12static SSLContextgetSSLContext(TLSProtocol protocol, KeyManager[] kms, TrustManager[] tms) HTTP TLS Factorystatic SSLContextgetSSLContext(TLSProtocol protocol, KeyManager[] kms, TrustManager[] tms, SecureRandom secRand) HTTP TLS Factorystatic SSLContextgetSSLContext(TLSProtocol protocol, KeyStoreAlgorithms storeAlgorithms, InputStream certIs, String password, TrustManager[] tms) HTTP TLS Factorystatic SSLContextgetSSLContext(TLSProtocol protocol, KeyStoreAlgorithms storeAlgorithms, TrustManager[] tms) HTTP TLS Factory without cert file.static TrustManagerFactorygetTrustManagerFactory(String algorithm, Provider provider) Get trust manager factorystatic KeyManagerFactorykeyManagerFactory(String algorithm, Provider provider) Returns aKeyManagerFactoryobject that acts as a factory for key managers.static KeyManagerFactorykeyManagerFactory(Provider provider) Returns aKeyManagerFactoryobject that acts as a factory for key managers.static KeyManager[]keyManagers(KeyStore store, char[] password) KeyManager array utilstatic KeyManager[]KeyManager array util
-
Field Details
-
DEFAULT_TRUST_MANAGERS
Default Trust Managers, with trust all certificates.- See Also:
-
NULL_SSL_CONTEXT
DisableSSLContext
-
-
Method Details
-
keyManagerFactory
public static KeyManagerFactory keyManagerFactory(Provider provider) throws NoSuchAlgorithmException Returns aKeyManagerFactoryobject that acts as a factory for key managers. And use standard name.- Parameters:
provider- an instance of the provider.- Returns:
- KeyManagerFactory instance.
- Throws:
NoSuchAlgorithmException- if noProvidersupports aKeyManagerFactorySpiimplementation for the specified algorithm.- See Also:
-
keyManagerFactory
public static KeyManagerFactory keyManagerFactory(String algorithm, Provider provider) throws NoSuchAlgorithmException Returns aKeyManagerFactoryobject that acts as a factory for key managers. If algorithm is empty or null, use the default KeyManagerFactory algorithm name.- Parameters:
algorithm- the standard name of the requested algorithm.provider- an instance of the provider.- Returns:
- KeyManagerFactory instance.
- Throws:
NoSuchAlgorithmException- if noProvidersupports aKeyManagerFactorySpiimplementation for the specified algorithm.- See Also:
-
keyManagers
public static KeyManager[] keyManagers(KeyStore store, char[] password) throws NoSuchAlgorithmException, UnrecoverableKeyException, KeyStoreException KeyManager array util- Parameters:
store- KeyStore instance.password- the password for recovering keys in the KeyStore.- Returns:
- KeyManager array
- Throws:
NoSuchAlgorithmException- if noProvidersupports aKeyManagerFactorySpiimplementation for the specified algorithm. Or the specified algorithm is not available from the specified provider.UnrecoverableKeyException- if the key cannot be recovered (e.g. the given password is wrong).KeyStoreException- if this operation fails.- See Also:
-
keyManagers
public static KeyManager[] keyManagers(ManagerFactoryParameters spec) throws NoSuchAlgorithmException, UnrecoverableKeyException, KeyStoreException, InvalidAlgorithmParameterException KeyManager array util- Parameters:
spec- an implementation of a provider-specific parameter specification.- Returns:
- KeyManager array
- Throws:
NoSuchAlgorithmException- if noProvidersupports aKeyManagerFactorySpiimplementation for the specified algorithm. Or the specified algorithm is not available from the specified provider.UnrecoverableKeyException- if the key cannot be recovered (e.g. the given password is wrong).KeyStoreException- if this operation fails.InvalidAlgorithmParameterException- if an error is encountered.- See Also:
-
getSSLContext
HTTP TLS Factory with TLS v1.2 and PKCS 12- Parameters:
certFile- Certificate file.certPass- Certificate password.- Returns:
- SSLContext instance. if file is null or exception return null.
-
getSSLContext
public static SSLContext getSSLContext(TLSProtocol protocol, KeyStoreAlgorithms storeAlgorithms, InputStream certIs, String password, TrustManager[] tms) throws HttpTLSException, NullPointerException HTTP TLS Factory- Parameters:
protocol- TLS protocol.storeAlgorithms- KeyStore algorithm.certIs- Certificate InputStream.password- Certificate password.tms- the sources of peer authentication trust decisions or null.- Returns:
- SSLContext instance.
- Throws:
HttpTLSException- TLS key, provider, I/O or operation is fails.NullPointerException- some parameter is null.
-
getSSLContext
public static SSLContext getSSLContext(TLSProtocol protocol, KeyStoreAlgorithms storeAlgorithms, TrustManager[] tms) HTTP TLS Factory without cert file.- Parameters:
protocol- TLS protocol.storeAlgorithms- KeyStore algorithm.tms- the sources of peer authentication trust decisions or null.- Returns:
- SSLContext instance.
- Throws:
HttpTLSException- TLS key, provider, I/O or operation is fails.NullPointerException- some parameter is null.
-
getSSLContext
public static SSLContext getSSLContext(TLSProtocol protocol, KeyManager[] kms, TrustManager[] tms) throws NoSuchAlgorithmException, KeyManagementException HTTP TLS Factory- Parameters:
protocol- TLS protocol.kms- the sources of authentication key or null.tms- the sources of peer authentication trust decisions or null.- Returns:
- SSLContext instance.
- Throws:
NoSuchAlgorithmException- if this operation fails.KeyManagementException- if noProvidersupports aSSLContextSpiimplementation for the specified protocol.
-
getSSLContext
public static SSLContext getSSLContext(TLSProtocol protocol, KeyManager[] kms, TrustManager[] tms, SecureRandom secRand) throws KeyManagementException, NoSuchAlgorithmException HTTP TLS Factory- Parameters:
protocol- TLS protocol.kms- the sources of authentication key or null.tms- the sources of peer authentication trust decisions or null.secRand- the source of randomness for this generator or null.- Returns:
- SSLContext instance.
- Throws:
KeyManagementException- if this operation fails.NoSuchAlgorithmException- if noProvidersupports aSSLContextSpiimplementation for the specified protocol.
-
getCertFactory
Get X.509 certificate factory- Parameters:
provider- X.509 certificate provider, if you do not need this setnullorCryptoUtil.NONPROVIDER.- Returns:
- CertificateFactory instance.
- Throws:
CertificateException- if no Provider supports a CertificateFactorySpi implementation for the specified type.- See Also:
-
getTrustManagerFactory
public static TrustManagerFactory getTrustManagerFactory(String algorithm, Provider provider) throws NoSuchAlgorithmException Get trust manager factory- Parameters:
algorithm- the standard name of the requested trust management algorithm. Java Security Standard Algorithm Names Specification for this standard algorithm name is"PKIX".provider- an instance of the provider. If ou do not need this setnullorCryptoUtil.NONPROVIDER.- Returns:
- TrustManagerFactory instance.
- Throws:
NoSuchAlgorithmException- if no Provider supports a TrustManagerFactorySpi implementation for the specified algorithm.- See Also:
-