Top Description Fields Constructors Methods
org.glassfish.tyrus.client

public Class SslEngineConfigurator

extends Object
Class Inheritance
Imports
java.util.ArrayList, .Arrays, javax.net.ssl.HostnameVerifier, .SSLContext, .SSLEngine

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 Summary

Modifier and TypeField and Description
protected boolean
clientMode

Client mode when handshaking.

protected String[]
enabledCipherSuites

The list of cipher suites.

protected String[]
enabledProtocols

The list of protocols.

private HostnameVerifier
hostnameVerifier

A custom hostname verifier.

private boolean
hostVerificationEnabled

true if host should be verified.

private boolean
isCipherConfigured

Has the enabled Cipher configured.

private boolean
isProtocolConfigured

Has the enabled protocol configured.

protected boolean
needClientAuth

Require client Authentication.

protected volatile SSLContext
protected volatile SslContextConfigurator
private final Object
protected boolean
wantClientAuth

True when requesting authentication.

Constructor Summary

AccessConstructor and Description
public
SslEngineConfigurator(SSLContext sslContext)

Create SSL Engine configuration basing on passed SSLContext.

public
SslEngineConfigurator(final SSLContext sslContext, final boolean
will be configured to work in client mode.
clientMode
,
final boolean
client authentication is required.
needClientAuth
,
final boolean
client should authenticate.
wantClientAuth
)

Create SSL Engine configuration based on passed SSLContext, using passed client mode, need/want client auth parameters.

public
SslEngineConfigurator(SslContextConfigurator sslContextConfiguration)

Create SSL Engine configuration based on passed SslContextConfigurator.

public
SslEngineConfigurator(SslContextConfigurator sslContextConfiguration, boolean
will be configured to work in client mode.
clientMode
,
boolean
client authentication is required.
needClientAuth
,
boolean
client should authenticate.
wantClientAuth
)

Create SSL Engine configuration basing on passed SslContextConfigurator.

public
SslEngineConfigurator(SslEngineConfigurator
original SslEngineConfigurator instance to be copied.
original
)

Copy constructor.

protected
SslEngineConfigurator()

Default constructor.

Method Summary

Modifier and TypeMethod and Description
public SSLEngine

Returns:

configured SSLEngine.
configure
(final SSLEngine
SSLEngine to configure.
sslEngine
)

Configure passed SSLEngine, using current configurator settings, excluding Hostname Verification.

private static String[]

Returns:

Array of SSL cipher suites to be enabled, or null if none of the requested ciphers are supported.
configureEnabledCiphers
(SSLEngine
ssl engine.
sslEngine
,
String[]
requested ciphers.
requestedCiphers
)

Determines the SSL cipher suites to be enabled.

private static String[]

Returns:

String[] an array of supported protocols.
configureEnabledProtocols
(SSLEngine
ssl engine.
sslEngine
,
String[]
requested protocols.
requestedProtocols
)

Return the list of allowed protocol.

public SslEngineConfigurator
copy()

public SSLEngine

Returns:

SSLEngine.
createSSLEngine
(String
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).
serverHost
)

Create and configure SSLEngine, based on current settings.

public String[]

Returns:

String array with enabled cipher suites.
getEnabledCipherSuites
()

Get enabled cipher suites.

public String[]

Returns:

String array with enabled protocols.
getEnabledProtocols
()

Get enabled protocols.

public HostnameVerifier

Returns:

user provided hostname verifier instance.
getHostnameVerifier
()

Get custom hostname verifier.

public SSLContext

Returns:

created ssl context.
getSslContext
()

Create SSLContext and store it for further invocation of this method.

public boolean
public boolean

Returns:

true, if SSLEngine will be configured to work in client mode, or false for server mode.
isClientMode
()

Will SSLEngine be configured to work in client mode.

public boolean

Returns:

true if the hostname verification is enabled, false otherwise.
isHostVerificationEnabled
()

Get the hostname verification state.

public boolean

Returns:

need client auth property value;
isNeedClientAuth
()

Get "need client auth" property.

public boolean
public boolean

Returns:

need client auth property value;
isWantClientAuth
()

Get "want client auth" property.

public SslEngineConfigurator
setCipherConfigured(boolean isCipherConfigured)

public SslEngineConfigurator

Returns:

updated SslEngineConfigurator.
setClientMode
(boolean
true, if SSLEngine will be configured to work in client mode, or false for server mode.
clientMode
)

Set SSLEngine to be configured to work in client mode.

public SslEngineConfigurator

Returns:

updated SslEngineConfigurator.
setEnabledCipherSuites
(String[]
String array with cipher suites.
enabledCipherSuites
)

Set enabled cipher suites.

public SslEngineConfigurator

Returns:

updated SslEngineConfigurator.
setEnabledProtocols
(String[]
String array with protocols.
enabledProtocols
)

Set enabled protocols.

public SslEngineConfigurator

Returns:

updated SslEngineConfigurator.
setHostnameVerifier
(HostnameVerifier
custom hostname verifier.
hostnameVerifier
)

Set custom hostname verifier.

public SslEngineConfigurator

Returns:

updated SslEngineConfigurator.
setHostVerificationEnabled
(boolean
when true, servers hostname will be verified using JDK default HostnameVerifier. When false, hostname verification won't be performed unless custom HostnameVerifier is set.
hostVerificationEnabled
)

Set hostname verification.

public SslEngineConfigurator

Returns:

updated SslEngineConfigurator.
setNeedClientAuth
(boolean
value to be set.
needClientAuth
)

Set "need client auth" property.

public SslEngineConfigurator
setProtocolConfigured(boolean isProtocolConfigured)

public SslEngineConfigurator

Returns:

updated SslEngineConfigurator.
setWantClientAuth
(boolean
value to be set.
wantClientAuth
)

Set "want client auth" property.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

clientModeback to summary
protected boolean clientMode

Client mode when handshaking.

enabledCipherSuitesback to summary
protected String[] enabledCipherSuites

The list of cipher suites.

enabledProtocolsback to summary
protected String[] enabledProtocols

The list of protocols.

hostnameVerifierback to summary
private HostnameVerifier hostnameVerifier

A custom hostname verifier.

hostVerificationEnabledback to summary
private boolean hostVerificationEnabled

true if host should be verified.

isCipherConfiguredback to summary
private boolean isCipherConfigured

Has the enabled Cipher configured.

isProtocolConfiguredback to summary
private boolean isProtocolConfigured

Has the enabled protocol configured.

needClientAuthback to summary
protected boolean needClientAuth

Require client Authentication.

sslContextback to summary
protected volatile SSLContext sslContext
sslContextConfigurationback to summary
protected volatile SslContextConfigurator sslContextConfiguration
syncback to summary
private final Object sync
wantClientAuthback to summary
protected boolean wantClientAuth

True when requesting authentication.

Constructor Detail

SslEngineConfiguratorback to summary
public SslEngineConfigurator(SSLContext sslContext)

Create SSL Engine configuration basing on passed SSLContext.

Parameters
sslContext:SSLContext

SSLContext.

SslEngineConfiguratorback to summary
public SslEngineConfigurator(final SSLContext sslContext, final boolean clientMode, final boolean needClientAuth, final boolean wantClientAuth)

Create SSL Engine configuration based on passed SSLContext, using passed client mode, need/want client auth parameters.

Parameters
sslContext:SSLContext

SSLContext.

clientMode:boolean

will be configured to work in client mode.

needClientAuth:boolean

client authentication is required.

wantClientAuth:boolean

client should authenticate.

SslEngineConfiguratorback to summary
public SslEngineConfigurator(SslContextConfigurator sslContextConfiguration)

Create SSL Engine configuration based on passed SslContextConfigurator. This constructor makes possible to initialize SSLEngine and SSLContext in lazy fashion on first createSSLEngine(String) call.

Parameters
sslContextConfiguration:SslContextConfigurator

SslContextConfigurator.

SslEngineConfiguratorback to summary
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

SslContextConfigurator.

clientMode:boolean

will be configured to work in client mode.

needClientAuth:boolean

client authentication is required.

wantClientAuth:boolean

client should authenticate.

SslEngineConfiguratorback to summary
public SslEngineConfigurator(SslEngineConfigurator original)

Copy constructor.

Parameters
original:SslEngineConfigurator

original SslEngineConfigurator instance to be copied.

SslEngineConfiguratorback to summary
protected SslEngineConfigurator()

Default constructor.

Method Detail

configureback to summary
public SSLEngine configure(final SSLEngine sslEngine)

Configure passed SSLEngine, using current configurator settings, excluding Hostname Verification.

Parameters
sslEngine:SSLEngine

SSLEngine to configure.

Returns:SSLEngine

configured SSLEngine.

configureEnabledCiphersback to summary
private static String[] configureEnabledCiphers(SSLEngine sslEngine, String[] requestedCiphers)

Determines the SSL cipher suites to be enabled.

Parameters
sslEngine:SSLEngine

ssl engine.

requestedCiphers:String[]

requested ciphers.

Returns:String[]

Array of SSL cipher suites to be enabled, or null if none of the requested ciphers are supported.

configureEnabledProtocolsback to summary
private static String[] configureEnabledProtocols(SSLEngine sslEngine, String[] requestedProtocols)

Return the list of allowed protocol.

Parameters
sslEngine:SSLEngine

ssl engine.

requestedProtocols:String[]

requested protocols.

Returns:String[]

String[] an array of supported protocols.

copyback to summary
public SslEngineConfigurator copy()
createSSLEngineback to summary
public SSLEngine createSSLEngine(String serverHost)

Create and configure SSLEngine, based on current settings.

Parameters
serverHost:String

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

SSLEngine.

getEnabledCipherSuitesback to summary
public String[] getEnabledCipherSuites()

Get enabled cipher suites.

Returns:String[]

String array with enabled cipher suites.

getEnabledProtocolsback to summary
public String[] getEnabledProtocols()

Get enabled protocols.

Returns:String[]

String array with enabled protocols.

getHostnameVerifierback to summary
public HostnameVerifier getHostnameVerifier()

Get custom hostname verifier.

Returns:HostnameVerifier

user provided hostname verifier instance.

getSslContextback to summary
public SSLContext getSslContext()

Create SSLContext and store it for further invocation of this method.

Returns:SSLContext

created ssl context.

isCipherConfiguredback to summary
public boolean isCipherConfigured()
isClientModeback to summary
public boolean isClientMode()

Will SSLEngine be configured to work in client mode.

Returns:boolean

true, if SSLEngine will be configured to work in client mode, or false for server mode.

isHostVerificationEnabledback to summary
public boolean isHostVerificationEnabled()

Get the hostname verification state.

Returns:boolean

true if the hostname verification is enabled, false otherwise.

isNeedClientAuthback to summary
public boolean isNeedClientAuth()

Get "need client auth" property.

Returns:boolean

need client auth property value;

isProtocolConfiguredback to summary
public boolean isProtocolConfigured()
isWantClientAuthback to summary
public boolean isWantClientAuth()

Get "want client auth" property.

Returns:boolean

need client auth property value;

setCipherConfiguredback to summary
public SslEngineConfigurator setCipherConfigured(boolean isCipherConfigured)
setClientModeback to summary
public SslEngineConfigurator setClientMode(boolean clientMode)

Set SSLEngine to be configured to work in client mode.

Parameters
clientMode:boolean

true, if SSLEngine will be configured to work in client mode, or false for server mode.

Returns:SslEngineConfigurator

updated SslEngineConfigurator.

setEnabledCipherSuitesback to summary
public SslEngineConfigurator setEnabledCipherSuites(String[] enabledCipherSuites)

Set enabled cipher suites.

Parameters
enabledCipherSuites:String[]

String array with cipher suites.

Returns:SslEngineConfigurator

updated SslEngineConfigurator.

setEnabledProtocolsback to summary
public SslEngineConfigurator setEnabledProtocols(String[] enabledProtocols)

Set enabled protocols.

Parameters
enabledProtocols:String[]

String array with protocols.

Returns:SslEngineConfigurator

updated SslEngineConfigurator.

setHostnameVerifierback to summary
public SslEngineConfigurator setHostnameVerifier(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:HostnameVerifier

custom hostname verifier.

Returns:SslEngineConfigurator

updated SslEngineConfigurator.

setHostVerificationEnabledback to summary
public SslEngineConfigurator setHostVerificationEnabled(boolean hostVerificationEnabled)

Set hostname verification.

Parameters
hostVerificationEnabled:boolean

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:SslEngineConfigurator

updated SslEngineConfigurator.

See Also
setHostnameVerifier(HostnameVerifier)
setNeedClientAuthback to summary
public SslEngineConfigurator setNeedClientAuth(boolean needClientAuth)

Set "need client auth" property.

Parameters
needClientAuth:boolean

value to be set.

Returns:SslEngineConfigurator

updated SslEngineConfigurator.

setProtocolConfiguredback to summary
public SslEngineConfigurator setProtocolConfigured(boolean isProtocolConfigured)
setWantClientAuthback to summary
public SslEngineConfigurator setWantClientAuth(boolean wantClientAuth)

Set "want client auth" property.

Parameters
wantClientAuth:boolean

value to be set.

Returns:SslEngineConfigurator

updated SslEngineConfigurator.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override