Package org.omegazero.net.util
Class TrustManagerUtil
java.lang.Object
org.omegazero.net.util.TrustManagerUtil
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
Adds the certificates that the default trust manager trusts to the givenKeyStore
.static TrustManager[]
Returns a trust manager array containing a single trust manager that accepts all certificates.
Warning: Trusting all certificates when using SSL is inherently dangerous as it defeats most of the purpose of it.static TrustManager[]
getTrustManagersWithAdditionalCertificateFiles
(Collection<String> additionalTrustCertificateFiles) Loads the certificates from the given file paths usingSSLUtil.loadCertificateFromPEM(String)
and generates an array of trust managers usinggetTrustManagersWithAdditionalCertificates(Collection)
.
The given certificate files must only contain a single certificate each.static TrustManager[]
getTrustManagersWithAdditionalCertificates
(Collection<X509Certificate> additionalTrustCertificates) Generates an array of trust managers which are configured to accept all certificates that the default trust manager trusts in addition to the certificates passed in additionalTrustCertificates.
-
Constructor Details
-
TrustManagerUtil
public TrustManagerUtil()
-
-
Method Details
-
getTrustManagersWithAdditionalCertificates
public static TrustManager[] getTrustManagersWithAdditionalCertificates(Collection<X509Certificate> additionalTrustCertificates) throws GeneralSecurityException, IOException Generates an array of trust managers which are configured to accept all certificates that the default trust manager trusts in addition to the certificates passed in additionalTrustCertificates.- Parameters:
additionalTrustCertificates
- The collection of certificates to trust in addition to the default ones. May benull
to not trust any additional certificates- Returns:
- The trust manager array
- Throws:
GeneralSecurityException
IOException
- See Also:
-
getTrustManagersWithAdditionalCertificateFiles
public static TrustManager[] getTrustManagersWithAdditionalCertificateFiles(Collection<String> additionalTrustCertificateFiles) throws GeneralSecurityException, IOException Loads the certificates from the given file paths usingSSLUtil.loadCertificateFromPEM(String)
and generates an array of trust managers usinggetTrustManagersWithAdditionalCertificates(Collection)
.
The given certificate files must only contain a single certificate each.- Parameters:
additionalTrustCertificateFiles
- The collection of file paths to load additional certificates from- Returns:
- The trust manager array
- Throws:
GeneralSecurityException
IOException
- See Also:
-
addDefaultCertificates
Adds the certificates that the default trust manager trusts to the givenKeyStore
.- Parameters:
ks
-- Throws:
GeneralSecurityException
-
getTrustAllManager
Returns a trust manager array containing a single trust manager that accepts all certificates.
Warning: Trusting all certificates when using SSL is inherently dangerous as it defeats most of the purpose of it. This should be used for testing purposes only.- Returns:
- The trust manager array
-