org.restlet.engine.security

## Class DefaultSslContextFactory

- java.lang.Object
- - org.restlet.engine.security.SslContextFactory
  - - org.restlet.engine.security.DefaultSslContextFactory

    public class DefaultSslContextFactory
    extends SslContextFactory

This SslContextFactory makes it possible to configure most basic options when building an SSLContext.

In short, two instances of KeyStore are used when configuring an SSLContext: the keystore (which contains the public and private keys and certificates to be used locally) and the trust store (which generally holds the CA certificates to be trusted when connecting to a remote host). Both keystore and trust store are KeyStores. When not explicitly set using the setters of this class, the values will default to the default system properties, following the behavior described in the JSSE reference guide.

There is more information in the JSSE Reference Guide.

Author:
  Bruno Harbulot (Bruno.Harbulot@manchester.ac.uk)
See Also:
  `SSLContext`, `KeyStore`

### Constructor Summary

Constructors
Constructor and Description
`DefaultSslContextFactory()`

### Method Summary

Methods
`protected DefaultSslContextFactory` `clone()` This class is likely to contain sensitive information; cloning is therefore not allowed.
`javax.net.ssl.SSLContext` `createSslContext()` Creates a configured and initialised SSLContext from the values set via the various setters of this class.
`java.lang.String` `getSecureSocketProtocol()` Returns the secure socket protocol name, "TLS" by default.
`void` `init(Series<Parameter> helperParameters)` Sets the following options according to parameters that may have been set up directly in the HttpsServerHelper parameters.
`void` `setKeyManagerAlgorithm(java.lang.String keyManagerAlgorithm)` Sets the KeyManager algorithm.
`void` `setKeyStoreKeyPassword(char[] keyStoreKeyPassword)` Sets the password of the key in the keystore.
`void` `setKeyStoreKeyPassword(java.lang.String keyStoreKeyPassword)` Sets the password of the key in the keystore.
`void` `setKeyStorePassword(char[] keyStorePassword)` Sets the keystore password.
`void` `setKeyStorePassword(java.lang.String keyStorePassword)` Sets the keystore password.
`void` `setKeyStorePath(java.lang.String keyStorePath)` Sets the path to the keystore file.
`void` `setKeyStoreProvider(java.lang.String keyStoreProvider)` Sets the name of the keystore provider.
`void` `setKeyStoreType(java.lang.String keyStoreType)` Sets the KeyStore type of the keystore.
`void` `setSecureRandomAlgorithm(java.lang.String secureRandomAlgorithm)` Sets the SecureRandom algorithm.
`void` `setSecureSocketProtocol(java.lang.String secureSocketProtocol)` Sets the secure socket protocol name, "TLS" by default.
`void` `setTrustManagerAlgorithm(java.lang.String trustManagerAlgorithm)` Sets the TrustManager algorithm.
`void` `setTrustStorePassword(char[] trustStorePassword)` Sets the password of the trust store KeyStore.
`void` `setTrustStorePassword(java.lang.String trustStorePassword)` Sets the password of the trust store KeyStore.
`void` `setTrustStorePath(java.lang.String trustStorePath)` Sets the path to the trust store KeyStore.
`void` `setTrustStoreProvider(java.lang.String trustStoreProvider)` Sets the name of the trust store provider.
`void` `setTrustStoreType(java.lang.String trustStoreType)` Sets the KeyStore type of the trust store.

### Methods inherited from class java.lang.Object

`equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### DefaultSslContextFactory

    public DefaultSslContextFactory()

### Method Detail

#### clone

    protected final DefaultSslContextFactory clone()
                                            throws java.lang.CloneNotSupportedException

This class is likely to contain sensitive information; cloning is therefore not allowed.

Overrides:
  `clone` in class `java.lang.Object`
Throws:
  `java.lang.CloneNotSupportedException`

#### createSslContext

    public javax.net.ssl.SSLContext createSslContext()
                                              throws java.lang.Exception

Creates a configured and initialised SSLContext from the values set via the various setters of this class. If `keyStorePath`, `keyStoreProvider`, `keyStoreType` are all `null`, the SSLContext will be initialised with a `null</core> array of `KeyManager`s. Similarly, if `trustStorePath`, `trustStoreProvider`, `trustStoreType` are all `null`, a `null` array of `TrustManager`s will be used.`

Specified by:
  `createSslContext` in class `SslContextFactory`
Returns:
  A configured and initialized SSLContext.
Throws:
  `java.lang.Exception`
See Also:
  `SSLContext.init(javax.net.ssl.KeyManager[], javax.net.ssl.TrustManager[], SecureRandom)`

#### getSecureSocketProtocol

    public java.lang.String getSecureSocketProtocol()

Returns the secure socket protocol name, "TLS" by default.

Returns:
  The secure socket protocol.

#### init

    public void init(Series<Parameter> helperParameters)

Sets the following options according to parameters that may have been set up directly in the HttpsServerHelper parameters.

Setter of this class | Parameter name | Value type | Default value | Description
--- | --- | --- | --- | ---
setKeyStorePath | keystorePath | String | ${user.home}/.keystore | SSL keystore path.
setKeyStorePassword | keystorePassword | String |  | SSL keystore password.
setKeyStoreType | keystoreType | String | JKS | SSL keystore type
setKeyStoreKeyPassword | keyPassword | String |  | SSL key password.
setKeyManagerAlgorithm | certAlgorithm | String | SunX509 | SSL certificate algorithm.
setSecureSocketProtocol | sslProtocol | String | TLS | SSL protocol.

Specified by:
  `init` in class `SslContextFactory`
Parameters:
  `helperParameters` - Typically, the parameters that would have been obtained from HttpsServerHelper.getParameters()

#### setKeyManagerAlgorithm

    public void setKeyManagerAlgorithm(java.lang.String keyManagerAlgorithm)

Sets the KeyManager algorithm. The default value is that of the ssl.KeyManagerFactory.algorithm system property, or "SunX509" if the system property has not been set up.

Parameters:
  `keyManagerAlgorithm` - The KeyManager algorithm.

#### setKeyStoreKeyPassword

    public final void setKeyStoreKeyPassword(char[] keyStoreKeyPassword)

Sets the password of the key in the keystore. The default value is that of the javax.net.ssl.keyPassword system property, falling back to javax.net.ssl.keyStorePassword. This system property name is not standard.

Parameters:
  `keyStoreKeyPassword` - The password of the key in the keystore.

#### setKeyStoreKeyPassword

    public final void setKeyStoreKeyPassword(java.lang.String keyStoreKeyPassword)

Sets the password of the key in the keystore. The default value is that of the javax.net.ssl.keyPassword system property, falling back to javax.net.ssl.keyStorePassword. This system property name is not standard.

Parameters:
  `keyStoreKeyPassword` - The password of the key in the keystore.

#### setKeyStorePassword

    public final void setKeyStorePassword(char[] keyStorePassword)

Sets the keystore password. The default value is that of the javax.net.ssl.keyStorePassword system property.

Parameters:
  `keyStorePassword` - Sets the keystore password.

#### setKeyStorePassword

    public final void setKeyStorePassword(java.lang.String keyStorePassword)

Sets the keystore password. The default value is that of the javax.net.ssl.keyStorePassword system property.

Parameters:
  `keyStorePassword` - Sets the keystore password.

#### setKeyStorePath

    public final void setKeyStorePath(java.lang.String keyStorePath)

Sets the path to the keystore file. The default value is that of the javax.net.ssl.keyStore system property.

Parameters:
  `keyStorePath` - The path to the keystore file.

#### setKeyStoreProvider

    public void setKeyStoreProvider(java.lang.String keyStoreProvider)

Sets the name of the keystore provider. The default value is that of the javax.net.ssl.keyStoreProvider system property.

Parameters:
  `keyStoreProvider` - The name of the keystore provider.

#### setKeyStoreType

    public final void setKeyStoreType(java.lang.String keyStoreType)

Sets the KeyStore type of the keystore. The default value is that of the javax.net.ssl.keyStoreType system property.

Parameters:
  `keyStoreType` - The KeyStore type of the keystore.

#### setSecureRandomAlgorithm

    public void setSecureRandomAlgorithm(java.lang.String secureRandomAlgorithm)

Sets the SecureRandom algorithm. The default value is null, in which case the default SecureRandom would be used.

Parameters:
  `secureRandomAlgorithm` - The SecureRandom algorithm.

#### setSecureSocketProtocol

    public void setSecureSocketProtocol(java.lang.String secureSocketProtocol)

Sets the secure socket protocol name, "TLS" by default. Typically, this will be either "TLS" or "SSLv3". This is the name used when instantiating the SSLContext.

Parameters:
  `secureSocketProtocol` - Name of the secure socket protocol to use.

#### setTrustManagerAlgorithm

    public void setTrustManagerAlgorithm(java.lang.String trustManagerAlgorithm)

Sets the TrustManager algorithm. The default value is that of the ssl.TrustManagerFactory.algorithm system property, or "SunX509" if the system property has not been set up.

Parameters:
  `trustManagerAlgorithm` - The TrustManager algorithm.

#### setTrustStorePassword

    public final void setTrustStorePassword(char[] trustStorePassword)

Sets the password of the trust store KeyStore. The default value is that of the javax.net.ssl.trustStorePassword system property.

Parameters:
  `trustStorePassword` - The password of the trust store KeyStore.

#### setTrustStorePassword

    public final void setTrustStorePassword(java.lang.String trustStorePassword)

Sets the password of the trust store KeyStore. The default value is that of the javax.net.ssl.trustStorePassword system property.

Parameters:
  `trustStorePassword` - The password of the trust store KeyStore.

#### setTrustStorePath

    public final void setTrustStorePath(java.lang.String trustStorePath)

Sets the path to the trust store KeyStore. The default value is that of the javax.net.ssl.trustStore system property.

Parameters:
  `trustStorePath` - The trustStorePath to set

#### setTrustStoreProvider

    public final void setTrustStoreProvider(java.lang.String trustStoreProvider)

Sets the name of the trust store provider. The default value is that of the javax.net.ssl.trustStoreProvider system property.

Parameters:
  `trustStoreProvider` - The name of the trust store provider.

#### setTrustStoreType

    public final void setTrustStoreType(java.lang.String trustStoreType)

Sets the KeyStore type of the trust store. The default value is that of the javax.net.ssl.trustStoreType system property.

Parameters:
  `trustStoreType` - The KeyStore type of the trust store.