Holger's Java API

## com.antelmann.net
Class SSLHelper

    java.lang.Object
      com.antelmann.net.SSLHelper

All Implemented Interfaces:
  Handler<URLConnection,IOException>, HostnameVerifier, TrustManager, X509TrustManager

    public class SSLHelper

extends Object
implements HostnameVerifier, X509TrustManager, Handler<URLConnection,IOException>

simplifies dealing with untrusted certificates

Since:
  26.09.2013, 15:29:20
Author:
  holger

Constructor Summary
`SSLHelper()`
`SSLHelper(Filter<String> hostnameFilter)`
`SSLHelper(Filter<String> hostnameFilter, Filter<SSLSession> sessionFilter)`

Method Summary
`void` `checkClientTrusted(X509Certificate[] chain, String authType)`
`void` `checkServerTrusted(X509Certificate[] chain, String authType)`
`X509Certificate[]` `getAcceptedIssuers()`
`Filter<String>` `getHostnameFilter()`
`KeyManagerFactory` `getKeyManagerFactory()`
`SecureRandom` `getRandom()`
`Filter<SSLSession>` `getSessionFilter()`
`SSLContext` `getSSLContext()`
`SSLServerSocketFactory` `getSSLServerSocketFactory()`
`SSLSocketFactory` `getSSLSocketFactory()`
`void` `handle(Object callbackSource, URLConnection con)` configures itself to handle the encryption control aspects if the given connection is a secure one
`void` `setHostnameFilter(Filter<String> hostnameFilter)`
`void` `setKeyManagerFactory(KeyManagerFactory kmf)` resets the sslContext as a side-effect
`void` `setKeystore(File keystoreFile, char[] password)`
`void` `setKeystore(InputStream keystoreStream, char[] password)`
`static void` `setKeystoreFilePath(String keystoreFilePath)`
`static void` `setKeystorePassword(String password)`
`void` `setRandom(SecureRandom random)` resets the sslContext as a side-effect
`void` `setSessionFilter(Filter<SSLSession> sessionFilter)`
`static void` `setTrustStore(String trustStoreFilePath)`
`static void` `setTrustStorePassword(String password)`
`boolean` `verify(String hostname, SSLSession session)` checks first the sessionFilter and then the hostnameFilter

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### SSLHelper

    public SSLHelper()

### SSLHelper

    public SSLHelper(Filter<String> hostnameFilter)

### SSLHelper

    public SSLHelper(Filter<String> hostnameFilter,
                     Filter<SSLSession> sessionFilter)

Method Detail

### getHostnameFilter

    public Filter<String> getHostnameFilter()

### setHostnameFilter

    public void setHostnameFilter(Filter<String> hostnameFilter)

### getSessionFilter

    public Filter<SSLSession> getSessionFilter()

### setSessionFilter

    public void setSessionFilter(Filter<SSLSession> sessionFilter)

### getRandom

    public SecureRandom getRandom()

### setRandom

    public void setRandom(SecureRandom random)

  resets the sslContext as a side-effect

### getKeyManagerFactory

    public KeyManagerFactory getKeyManagerFactory()

### setKeyManagerFactory

    public void setKeyManagerFactory(KeyManagerFactory kmf)

  resets the sslContext as a side-effect

### setKeystore

    public void setKeystore(File keystoreFile,
                            char[] password)
                     throws GeneralSecurityException,
                            IOException

  Throws:
    `GeneralSecurityException`
    `IOException`

### setKeystore

    public void setKeystore(InputStream keystoreStream,
                            char[] password)
                     throws GeneralSecurityException,
                            IOException

  Throws:
    `GeneralSecurityException`
    `IOException`

### handle

    public void handle(Object callbackSource,
                       URLConnection con)
                throws IOException

  configures itself to handle the encryption control aspects if the given connection is a secure one

  Specified by:
    `handle` in interface `Handler<URLConnection,IOException>`
  Parameters:
    `callbackSource` - the object that initiated this call-back
    `con` - the item to be handled by this instance
  Throws:
    `IOException`

### getSSLContext

    public SSLContext getSSLContext()
                             throws KeyManagementException,
                                    NoSuchAlgorithmException

  Throws:
    `KeyManagementException`
    `NoSuchAlgorithmException`

### getSSLSocketFactory

    public SSLSocketFactory getSSLSocketFactory()
                                         throws NoSuchAlgorithmException,
                                                KeyManagementException

  Throws:
    `NoSuchAlgorithmException`
    `KeyManagementException`

### getSSLServerSocketFactory

    public SSLServerSocketFactory getSSLServerSocketFactory()
                                                     throws NoSuchAlgorithmException,
                                                            KeyManagementException

  Throws:
    `NoSuchAlgorithmException`
    `KeyManagementException`

### verify

    public boolean verify(String hostname,
                          SSLSession session)

  checks first the sessionFilter and then the hostnameFilter

  Specified by:
    `verify` in interface `HostnameVerifier`

### checkClientTrusted

    public void checkClientTrusted(X509Certificate[] chain,
                                   String authType)
                            throws CertificateException

  Specified by:
    `checkClientTrusted` in interface `X509TrustManager`
  Throws:
    `CertificateException`

### checkServerTrusted

    public void checkServerTrusted(X509Certificate[] chain,
                                   String authType)
                            throws CertificateException

  Specified by:
    `checkServerTrusted` in interface `X509TrustManager`
  Throws:
    `CertificateException`

### getAcceptedIssuers

    public X509Certificate[] getAcceptedIssuers()

  Specified by:
    `getAcceptedIssuers` in interface `X509TrustManager`

### setKeystoreFilePath

    public static void setKeystoreFilePath(String keystoreFilePath)

### setKeystorePassword

    public static void setKeystorePassword(String password)

### setTrustStore

    public static void setTrustStore(String trustStoreFilePath)

### setTrustStorePassword

    public static void setTrustStorePassword(String password)

(c) Holger Antelmann since 2001- all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads