Class SslEngineConfigurator


  • public class SslEngineConfigurator
    extends java.lang.Object
    SSLEngineConfigurator class from Grizzly project.

    Utility class, which helps to configure SSLEngine. Should 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
    • Field Detail

      • sslContext

        protected volatile javax.net.ssl.SSLContext sslContext
      • enabledCipherSuites

        protected java.lang.String[] enabledCipherSuites
        The list of cipher suites.
      • enabledProtocols

        protected java.lang.String[] enabledProtocols
        The list of protocols.
      • clientMode

        protected boolean clientMode
        Client mode when handshaking.
      • needClientAuth

        protected boolean needClientAuth
        Require client Authentication.
      • wantClientAuth

        protected boolean wantClientAuth
        True when requesting authentication.
    • Constructor Detail

      • SslEngineConfigurator

        public SslEngineConfigurator​(javax.net.ssl.SSLContext sslContext)
        Create SSL Engine configuration basing on passed SSLContext.
        Parameters:
        sslContext - SSLContext.
      • SslEngineConfigurator

        public SslEngineConfigurator​(javax.net.ssl.SSLContext sslContext,
                                     boolean clientMode,
                                     boolean needClientAuth,
                                     boolean wantClientAuth)
        Create SSL Engine configuration based on passed SSLContext, using passed client mode, need/want client auth parameters.
        Parameters:
        sslContext - SSLContext.
        clientMode - will be configured to work in client mode.
        needClientAuth - client authentication is required.
        wantClientAuth - client should authenticate.
      • SslEngineConfigurator

        public SslEngineConfigurator​(SslContextConfigurator sslContextConfiguration,
                                     boolean clientMode,
                                     boolean needClientAuth,
                                     boolean wantClientAuth)
        Create SSL Engine configuration basing on passed SslContextConfigurator. This constructor makes possible to initialize SSLEngine and SSLContext in lazy fashion on first createSSLEngine(String) call.
        Parameters:
        sslContextConfiguration - SslContextConfigurator.
        clientMode - will be configured to work in client mode.
        needClientAuth - client authentication is required.
        wantClientAuth - client should authenticate.
      • SslEngineConfigurator

        protected SslEngineConfigurator()
        Default constructor.
    • Method Detail

      • createSSLEngine

        public javax.net.ssl.SSLEngine createSSLEngine​(java.lang.String serverHost)
        Create and configure SSLEngine, based on current settings.
        Parameters:
        serverHost - server host, which will be used to verify authenticity of the server (the provided host name will compared to the host in the certificate provided by the server).
        Returns:
        SSLEngine.
      • configure

        public javax.net.ssl.SSLEngine configure​(javax.net.ssl.SSLEngine sslEngine)
        Configure passed SSLEngine, using current configurator settings, excluding Hostname Verification.
        Parameters:
        sslEngine - SSLEngine to configure.
        Returns:
        configured SSLEngine.
      • isClientMode

        public boolean isClientMode()
        Will SSLEngine be configured to work in client mode.
        Returns:
        true, if SSLEngine will be configured to work in client mode, or false for server mode.
      • setClientMode

        public SslEngineConfigurator setClientMode​(boolean clientMode)
        Set SSLEngine to be configured to work in client mode.
        Parameters:
        clientMode - true, if SSLEngine will be configured to work in client mode, or false for server mode.
        Returns:
        updated SslEngineConfigurator.
      • isNeedClientAuth

        public boolean isNeedClientAuth()
        Get "need client auth" property.
        Returns:
        need client auth property value;
      • setNeedClientAuth

        public SslEngineConfigurator setNeedClientAuth​(boolean needClientAuth)
        Set "need client auth" property.
        Parameters:
        needClientAuth - value to be set.
        Returns:
        updated SslEngineConfigurator.
      • isWantClientAuth

        public boolean isWantClientAuth()
        Get "want client auth" property.
        Returns:
        need client auth property value;
      • setWantClientAuth

        public SslEngineConfigurator setWantClientAuth​(boolean wantClientAuth)
        Set "want client auth" property.
        Parameters:
        wantClientAuth - value to be set.
        Returns:
        updated SslEngineConfigurator.
      • getEnabledCipherSuites

        public java.lang.String[] getEnabledCipherSuites()
        Get enabled cipher suites.
        Returns:
        String array with enabled cipher suites.
      • setEnabledCipherSuites

        public SslEngineConfigurator setEnabledCipherSuites​(java.lang.String[] enabledCipherSuites)
        Set enabled cipher suites.
        Parameters:
        enabledCipherSuites - String array with cipher suites.
        Returns:
        updated SslEngineConfigurator.
      • getEnabledProtocols

        public java.lang.String[] getEnabledProtocols()
        Get enabled protocols.
        Returns:
        String array with enabled protocols.
      • setEnabledProtocols

        public SslEngineConfigurator setEnabledProtocols​(java.lang.String[] enabledProtocols)
        Set enabled protocols.
        Parameters:
        enabledProtocols - String array with protocols.
        Returns:
        updated SslEngineConfigurator.
      • isCipherConfigured

        public boolean isCipherConfigured()
      • isProtocolConfigured

        public boolean isProtocolConfigured()
      • setProtocolConfigured

        public SslEngineConfigurator setProtocolConfigured​(boolean isProtocolConfigured)
      • isHostVerificationEnabled

        public boolean isHostVerificationEnabled()
        Get the hostname verification state.
        Returns:
        true if the hostname verification is enabled, false otherwise.
      • setHostVerificationEnabled

        public SslEngineConfigurator setHostVerificationEnabled​(boolean hostVerificationEnabled)
        Set hostname verification.
        Parameters:
        hostVerificationEnabled - when true, servers hostname will be verified using JDK default HostnameVerifier. When false, hostname verification won't be performed unless custom HostnameVerifier is set.
        Returns:
        updated SslEngineConfigurator.
        See Also:
        setHostnameVerifier(HostnameVerifier)
      • getHostnameVerifier

        public javax.net.ssl.HostnameVerifier getHostnameVerifier()
        Get custom hostname verifier.
        Returns:
        user provided hostname verifier instance.
      • setHostnameVerifier

        public SslEngineConfigurator setHostnameVerifier​(javax.net.ssl.HostnameVerifier hostnameVerifier)
        Set custom hostname verifier.

        When custom HostnameVerifier instance is registered, it will be used to perform hostname verification, no matter on the state of hostname verification flag (see isHostVerificationEnabled()) and JDK default hostname verifier won't be used.

        Parameters:
        hostnameVerifier - custom hostname verifier.
        Returns:
        updated SslEngineConfigurator.
      • getSslContext

        public javax.net.ssl.SSLContext getSslContext()
        Create SSLContext and store it for further invocation of this method.
        Returns:
        created ssl context.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object