Class SslContextConfigurator


  • public class SslContextConfigurator
    extends java.lang.Object
    Utility class, which helps to configure ssl context.

    Used to configure SslEngineConfigurator, which will be passed to client via configuration properties. Example:

          SslContextConfigurator sslContextConfigurator = new SslContextConfigurator();
          sslContextConfigurator.setTrustStoreFile("...");
          sslContextConfigurator.setTrustStorePassword("...");
          sslContextConfigurator.setTrustStoreType("...");
          sslContextConfigurator.setKeyStoreFile("...");
          sslContextConfigurator.setKeyStorePassword("...");
          sslContextConfigurator.setKeyStoreType("...");
          SslEngineConfigurator sslEngineConfigurator = new SslEngineConfigurator(sslContextConfigurator, true, false,
     false);
          client.getProperties().put(ClientManager.SSL_ENGINE_CONFIGURATOR, sslEngineConfigurator);
     
    Author:
    Alexey Stashok, Hubert Iwaniuk, Bruno Harbulot, Marek Potociar
    • Field Detail

      • TRUST_STORE_PROVIDER

        public static final java.lang.String TRUST_STORE_PROVIDER
        Trust store provider name.

        The value MUST be a String representing the name of a trust store provider.

        No default value is set.

        The name of the configuration property is "javax.net.ssl.trustStoreProvider".

        See Also:
        Constant Field Values
      • KEY_STORE_PROVIDER

        public static final java.lang.String KEY_STORE_PROVIDER
        Key store provider name.

        The value MUST be a String representing the name of a trust store provider.

        No default value is set.

        The name of the configuration property is "javax.net.ssl.keyStoreProvider".

        See Also:
        Constant Field Values
      • TRUST_STORE_FILE

        public static final java.lang.String TRUST_STORE_FILE
        Trust store file name.

        The value MUST be a String representing the name of a trust store file.

        No default value is set.

        The name of the configuration property is "javax.net.ssl.trustStore".

        See Also:
        Constant Field Values
      • KEY_STORE_FILE

        public static final java.lang.String KEY_STORE_FILE
        Key store file name.

        The value MUST be a String representing the name of a key store file.

        No default value is set.

        The name of the configuration property is "javax.net.ssl.keyStore".

        See Also:
        Constant Field Values
      • TRUST_STORE_PASSWORD

        public static final java.lang.String TRUST_STORE_PASSWORD
        Trust store file password - the password used to unlock the trust store file.

        The value MUST be a String representing the trust store file password.

        No default value is set.

        The name of the configuration property is "javax.net.ssl.trustStorePassword".

        See Also:
        Constant Field Values
      • KEY_STORE_PASSWORD

        public static final java.lang.String KEY_STORE_PASSWORD
        Key store file password - the password used to unlock the trust store file.

        The value MUST be a String representing the key store file password.

        No default value is set.

        The name of the configuration property is "javax.net.ssl.keyStorePassword".

        See Also:
        Constant Field Values
      • TRUST_STORE_TYPE

        public static final java.lang.String TRUST_STORE_TYPE
        Trust store type (see KeyStore.getType() for more info).

        The value MUST be a String representing the trust store type name.

        No default value is set.

        The name of the configuration property is "javax.net.ssl.trustStoreType".

        See Also:
        Constant Field Values
      • KEY_STORE_TYPE

        public static final java.lang.String KEY_STORE_TYPE
        Key store type (see KeyStore.getType() for more info).

        The value MUST be a String representing the key store type name.

        No default value is set.

        The name of the configuration property is "javax.net.ssl.keyStoreType".

        See Also:
        Constant Field Values
      • KEY_FACTORY_MANAGER_ALGORITHM

        public static final java.lang.String KEY_FACTORY_MANAGER_ALGORITHM
        Key manager factory algorithm name.

        The value MUST be a String representing the key manager factory algorithm name.

        No default value is set.

        The name of the configuration property is "ssl.KeyManagerFactory.algorithm".

        See Also:
        Constant Field Values
      • TRUST_FACTORY_MANAGER_ALGORITHM

        public static final java.lang.String TRUST_FACTORY_MANAGER_ALGORITHM
        Trust manager factory algorithm name.

        The value MUST be a String representing the trust manager factory algorithm name.

        No default value is set.

        The name of the configuration property is "ssl.TrustManagerFactory.algorithm".

        See Also:
        Constant Field Values
    • Constructor Detail

      • SslContextConfigurator

        public SslContextConfigurator()
        Default constructor. Reads configuration properties from System.getProperties(). Calls SslContextConfigurator(boolean) with true.
      • SslContextConfigurator

        public SslContextConfigurator​(boolean readSystemProperties)
        Constructor that allows you creating empty configuration.
        Parameters:
        readSystemProperties - If true populates configuration from System.getProperties(), else you have empty configuration.
    • Method Detail

      • setTrustStoreProvider

        public SslContextConfigurator setTrustStoreProvider​(java.lang.String trustStoreProvider)
        Sets the trust store provider name.
        Parameters:
        trustStoreProvider - Trust store provider to set.
        Returns:
        updated SslContextConfigurator instance.
      • setKeyStoreProvider

        public SslContextConfigurator setKeyStoreProvider​(java.lang.String keyStoreProvider)
        Sets the key store provider name.
        Parameters:
        keyStoreProvider - Key store provider to set.
        Returns:
        updated SslContextConfigurator instance.
      • setTrustStoreType

        public SslContextConfigurator setTrustStoreType​(java.lang.String trustStoreType)
        Type of trust store.
        Parameters:
        trustStoreType - Type of trust store to set.
        Returns:
        updated SslContextConfigurator instance.
      • setKeyStoreType

        public SslContextConfigurator setKeyStoreType​(java.lang.String keyStoreType)
        Type of key store.
        Parameters:
        keyStoreType - Type of key store to set.
        Returns:
        updated SslContextConfigurator instance.
      • setTrustStorePassword

        public SslContextConfigurator setTrustStorePassword​(java.lang.String trustStorePassword)
        Password of trust store.
        Parameters:
        trustStorePassword - Password of trust store to set.
        Returns:
        updated SslContextConfigurator instance.
      • setKeyStorePassword

        public SslContextConfigurator setKeyStorePassword​(java.lang.String keyStorePassword)
        Password of key store.
        Parameters:
        keyStorePassword - Password of key store to set.
        Returns:
        updated SslContextConfigurator instance.
      • setKeyStorePassword

        public SslContextConfigurator setKeyStorePassword​(char[] keyStorePassword)
        Password of key store.
        Parameters:
        keyStorePassword - Password of key store to set.
        Returns:
        updated SslContextConfigurator instance.
      • setKeyPassword

        public SslContextConfigurator setKeyPassword​(java.lang.String keyPassword)
        Password of the key in the key store.
        Parameters:
        keyPassword - Password of key to set.
        Returns:
        updated SslContextConfigurator instance.
      • setKeyPassword

        public SslContextConfigurator setKeyPassword​(char[] keyPassword)
        Password of the key in the key store.
        Parameters:
        keyPassword - Password of key to set.
        Returns:
        updated SslContextConfigurator instance.
      • setTrustStoreFile

        public SslContextConfigurator setTrustStoreFile​(java.lang.String trustStoreFile)
        Sets trust store file name, also makes sure that if other trust store configuration parameters are not set to set them to default values. Method resets trust store bytes if any have been set before via setTrustStoreBytes(byte[]).
        Parameters:
        trustStoreFile - File name of trust store.
        Returns:
        updated SslContextConfigurator instance.
      • setKeyStoreFile

        public SslContextConfigurator setKeyStoreFile​(java.lang.String keyStoreFile)
        Sets key store file name, also makes sure that if other key store configuration parameters are not set to set them to default values. Method resets key store bytes if any have been set before via setKeyStoreBytes(byte[]).
        Parameters:
        keyStoreFile - File name of key store.
        Returns:
        updated SslContextConfigurator instance.
      • setTrustManagerFactoryAlgorithm

        public SslContextConfigurator setTrustManagerFactoryAlgorithm​(java.lang.String trustManagerFactoryAlgorithm)
        Sets the trust manager factory algorithm.
        Parameters:
        trustManagerFactoryAlgorithm - the trust manager factory algorithm.
        Returns:
        updated SslContextConfigurator instance.
      • setKeyManagerFactoryAlgorithm

        public SslContextConfigurator setKeyManagerFactoryAlgorithm​(java.lang.String keyManagerFactoryAlgorithm)
        Sets the key manager factory algorithm.
        Parameters:
        keyManagerFactoryAlgorithm - the key manager factory algorithm.
        Returns:
        updated SslContextConfigurator instance.
      • setSecurityProtocol

        public SslContextConfigurator setSecurityProtocol​(java.lang.String securityProtocol)
        Sets the SSLContext protocol. The default value is TLS if this is null.
        Parameters:
        securityProtocol - Protocol for SSLContext.getProtocol().
        Returns:
        updated SslContextConfigurator instance.
      • validateConfiguration

        public boolean validateConfiguration()
        Validates SslContextConfigurator configuration.
        Returns:
        true if configuration is valid, else false.
      • validateConfiguration

        public boolean validateConfiguration​(boolean needsKeyStore)
        Validates SslContextConfigurator configuration.
        Parameters:
        needsKeyStore - forces failure if no keystore is specified.
        Returns:
        true if configuration is valid, else false.
      • createSSLContext

        public javax.net.ssl.SSLContext createSSLContext()
        Create SSLContext from current configuration.
        Returns:
        created SSLContext.
      • retrieve

        public SslContextConfigurator retrieve​(java.util.Properties props)
        Retrieve settings from (system) properties.
        Parameters:
        props - property map (usually taken from System.getProperties()).
        Returns:
        updated SslContextConfigurator instance.