# SSLContextSpi

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Summary:[Ctors](https://developer.android.com/reference/javax/net/ssl/SSLContextSpi#pubctors)\|[Protected Methods](https://developer.android.com/reference/javax/net/ssl/SSLContextSpi#promethods)\|[Inherited Methods](https://developer.android.com/reference/javax/net/ssl/SSLContextSpi#inhmethods)  

# SSLContextSpi

`
public


abstract
class
SSLContextSpi
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object)`


``


`

|---|-----------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | javax.net.ssl.SSLContextSpi |

<br />

*** ** * ** ***

This class defines the*Service Provider Interface* (**SPI** ) for the`SSLContext`class.

All the abstract methods in this class must be implemented by each cryptographic service provider who wishes to supply the implementation of a particular SSL context.  
**See also:**

- [SSLContext](https://developer.android.com/reference/javax/net/ssl/SSLContext)

## Summary

|                                             ### Public constructors                                             ||
|--------------------------------------------------------------------------------------------------------------|---|
| ` `[SSLContextSpi](https://developer.android.com/reference/javax/net/ssl/SSLContextSpi#SSLContextSpi())`() ` |

|                                                                                                                                                                                                                                                                                                 ### Protected methods                                                                                                                                                                                                                                                                                                 ||
|--------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` abstract `[SSLEngine](https://developer.android.com/reference/javax/net/ssl/SSLEngine)                           | ` `[engineCreateSSLEngine](https://developer.android.com/reference/javax/net/ssl/SSLContextSpi#engineCreateSSLEngine())`() ` Creates a new`SSLEngine`using this context.                                                                                                                                                                                                                                                                                                                          |
| ` abstract `[SSLEngine](https://developer.android.com/reference/javax/net/ssl/SSLEngine)                           | ` `[engineCreateSSLEngine](https://developer.android.com/reference/javax/net/ssl/SSLContextSpi#engineCreateSSLEngine(java.lang.String,%20int))`(`[String](https://developer.android.com/reference/java/lang/String)` host, int port) ` Creates a`SSLEngine`using this context.                                                                                                                                                                                                                    |
| ` abstract `[SSLSessionContext](https://developer.android.com/reference/javax/net/ssl/SSLSessionContext)           | ` `[engineGetClientSessionContext](https://developer.android.com/reference/javax/net/ssl/SSLContextSpi#engineGetClientSessionContext())`() ` Returns a client`SSLSessionContext`object for this context.                                                                                                                                                                                                                                                                                          |
| ` `[SSLParameters](https://developer.android.com/reference/javax/net/ssl/SSLParameters)                            | ` `[engineGetDefaultSSLParameters](https://developer.android.com/reference/javax/net/ssl/SSLContextSpi#engineGetDefaultSSLParameters())`() ` Returns a copy of the SSLParameters indicating the default settings for this SSL context.                                                                                                                                                                                                                                                            |
| ` abstract `[SSLSessionContext](https://developer.android.com/reference/javax/net/ssl/SSLSessionContext)           | ` `[engineGetServerSessionContext](https://developer.android.com/reference/javax/net/ssl/SSLContextSpi#engineGetServerSessionContext())`() ` Returns a server`SSLSessionContext`object for this context.                                                                                                                                                                                                                                                                                          |
| ` abstract `[SSLServerSocketFactory](https://developer.android.com/reference/javax/net/ssl/SSLServerSocketFactory) | ` `[engineGetServerSocketFactory](https://developer.android.com/reference/javax/net/ssl/SSLContextSpi#engineGetServerSocketFactory())`() ` Returns a`ServerSocketFactory`object for this context.                                                                                                                                                                                                                                                                                                 |
| ` abstract `[SSLSocketFactory](https://developer.android.com/reference/javax/net/ssl/SSLSocketFactory)             | ` `[engineGetSocketFactory](https://developer.android.com/reference/javax/net/ssl/SSLContextSpi#engineGetSocketFactory())`() ` Returns a`SocketFactory`object for this context.                                                                                                                                                                                                                                                                                                                   |
| ` `[SSLParameters](https://developer.android.com/reference/javax/net/ssl/SSLParameters)                            | ` `[engineGetSupportedSSLParameters](https://developer.android.com/reference/javax/net/ssl/SSLContextSpi#engineGetSupportedSSLParameters())`() ` Returns a copy of the SSLParameters indicating the maximum supported settings for this SSL context.                                                                                                                                                                                                                                              |
| ` abstract void`                                                                                                   | ` `[engineInit](https://developer.android.com/reference/javax/net/ssl/SSLContextSpi#engineInit(javax.net.ssl.KeyManager[],%20javax.net.ssl.TrustManager[],%20java.security.SecureRandom))`(`[KeyManager[]](https://developer.android.com/reference/javax/net/ssl/KeyManager)` km, `[TrustManager[]](https://developer.android.com/reference/javax/net/ssl/TrustManager)` tm, `[SecureRandom](https://developer.android.com/reference/java/security/SecureRandom)` sr) ` Initializes this context. |

| ### Inherited methods |
|-----------------------|---|
| From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                           | | ` void`                                                                        | ` `[finalize](https://developer.android.com/reference/java/lang/Object#finalize())`() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.                                                          | | ` final `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                            | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long,%20int))`(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed. | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long))`(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed.                   | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait())`() ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*.                                                                                             | ||

## Public constructors

### SSLContextSpi

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public SSLContextSpi ()
```

<br />

<br />

## Protected methods

### engineCreateSSLEngine

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
protected abstract SSLEngine engineCreateSSLEngine ()
```

Creates a new`SSLEngine`using this context.

Applications using this factory method are providing no hints for an internal session reuse strategy. If hints are desired,[engineCreateSSLEngine(java.lang.String, int)](https://developer.android.com/reference/javax/net/ssl/SSLContextSpi#engineCreateSSLEngine(java.lang.String,%20int))should be used instead.

Some cipher suites (such as Kerberos) require remote hostname information, in which case this factory method should not be used.

<br />

|                                                  Returns                                                  ||
|------------------------------------------------------------------------------|-----------------------------|
| [SSLEngine](https://developer.android.com/reference/javax/net/ssl/SSLEngine) | the`SSLEngine`Object <br /> |

|                                                                                          Throws                                                                                          ||
|--------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------|
| [IllegalStateException](https://developer.android.com/reference/java/lang/IllegalStateException) | if the SSLContextImpl requires initialization and the`engineInit()`has not been called |

**See also:**

- [SSLContext.createSSLEngine()](https://developer.android.com/reference/javax/net/ssl/SSLContext#createSSLEngine())  

### engineCreateSSLEngine

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
protected abstract SSLEngine engineCreateSSLEngine (String host, 
                int port)
```

Creates a`SSLEngine`using this context.

Applications using this factory method are providing hints for an internal session reuse strategy.

Some cipher suites (such as Kerberos) require remote hostname information, in which case peerHost needs to be specified.

<br />

|                           Parameters                            ||
|--------|---------------------------------------------------------|
| `host` | `String`: the non-authoritative name of the host <br /> |
| `port` | `int`: the non-authoritative port <br />                |

|                                                  Returns                                                  ||
|------------------------------------------------------------------------------|-----------------------------|
| [SSLEngine](https://developer.android.com/reference/javax/net/ssl/SSLEngine) | the`SSLEngine`Object <br /> |

|                                                                                          Throws                                                                                          ||
|--------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------|
| [IllegalStateException](https://developer.android.com/reference/java/lang/IllegalStateException) | if the SSLContextImpl requires initialization and the`engineInit()`has not been called |

**See also:**

- [SSLContext.createSSLEngine(String, int)](https://developer.android.com/reference/javax/net/ssl/SSLContext#createSSLEngine(java.lang.String,%20int))  

### engineGetClientSessionContext

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
protected abstract SSLSessionContext engineGetClientSessionContext ()
```

Returns a client`SSLSessionContext`object for this context.

<br />

|                                                              Returns                                                              ||
|----------------------------------------------------------------------------------------------|-------------------------------------|
| [SSLSessionContext](https://developer.android.com/reference/javax/net/ssl/SSLSessionContext) | the`SSLSessionContext`object <br /> |

**See also:**

- [SSLContext.getClientSessionContext()](https://developer.android.com/reference/javax/net/ssl/SSLContext#getClientSessionContext())  

### engineGetDefaultSSLParameters

Added in[API level 9](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
protected SSLParameters engineGetDefaultSSLParameters ()
```

Returns a copy of the SSLParameters indicating the default settings for this SSL context.

The parameters will always have the ciphersuite and protocols arrays set to non-null values.

The default implementation obtains the parameters from an SSLSocket created by calling the[SocketFactory.createSocket()](https://developer.android.com/reference/javax/net/SocketFactory#createSocket())method of this context's SocketFactory.

<br />

|                                                                          Returns                                                                          ||
|--------------------------------------------------------------------------------------|---------------------------------------------------------------------|
| [SSLParameters](https://developer.android.com/reference/javax/net/ssl/SSLParameters) | a copy of the SSLParameters object with the default settings <br /> |

|                                                                                 Throws                                                                                 ||
|------------------------------------------------------------------------------------------------------------------|------------------------------------------------------|
| [UnsupportedOperationException](https://developer.android.com/reference/java/lang/UnsupportedOperationException) | if the default SSL parameters could not be obtained. |

### engineGetServerSessionContext

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
protected abstract SSLSessionContext engineGetServerSessionContext ()
```

Returns a server`SSLSessionContext`object for this context.

<br />

|                                                              Returns                                                              ||
|----------------------------------------------------------------------------------------------|-------------------------------------|
| [SSLSessionContext](https://developer.android.com/reference/javax/net/ssl/SSLSessionContext) | the`SSLSessionContext`object <br /> |

**See also:**

- [SSLContext.getServerSessionContext()](https://developer.android.com/reference/javax/net/ssl/SSLContext#getServerSessionContext())  

### engineGetServerSocketFactory

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
protected abstract SSLServerSocketFactory engineGetServerSocketFactory ()
```

Returns a`ServerSocketFactory`object for this context.

<br />

|                                                                    Returns                                                                    ||
|--------------------------------------------------------------------------------------------------------|---------------------------------------|
| [SSLServerSocketFactory](https://developer.android.com/reference/javax/net/ssl/SSLServerSocketFactory) | the`ServerSocketFactory`object <br /> |

|                                                                                          Throws                                                                                          ||
|--------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------|
| [IllegalStateException](https://developer.android.com/reference/java/lang/IllegalStateException) | if the SSLContextImpl requires initialization and the`engineInit()`has not been called |

**See also:**

- [SSLContext.getServerSocketFactory()](https://developer.android.com/reference/javax/net/ssl/SSLContext#getServerSocketFactory())  

### engineGetSocketFactory

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
protected abstract SSLSocketFactory engineGetSocketFactory ()
```

Returns a`SocketFactory`object for this context.

<br />

|                                                           Returns                                                           ||
|--------------------------------------------------------------------------------------------|---------------------------------|
| [SSLSocketFactory](https://developer.android.com/reference/javax/net/ssl/SSLSocketFactory) | the`SocketFactory`object <br /> |

|                                                                                          Throws                                                                                          ||
|--------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------|
| [IllegalStateException](https://developer.android.com/reference/java/lang/IllegalStateException) | if the SSLContextImpl requires initialization and the`engineInit()`has not been called |

**See also:**

- [SSLContext.getSocketFactory()](https://developer.android.com/reference/javax/net/ssl/SSLContext#getSocketFactory())  

### engineGetSupportedSSLParameters

Added in[API level 9](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
protected SSLParameters engineGetSupportedSSLParameters ()
```

Returns a copy of the SSLParameters indicating the maximum supported settings for this SSL context.

The parameters will always have the ciphersuite and protocols arrays set to non-null values.

The default implementation obtains the parameters from an SSLSocket created by calling the[SocketFactory.createSocket()](https://developer.android.com/reference/javax/net/SocketFactory#createSocket())method of this context's SocketFactory.

<br />

|                                                                               Returns                                                                               ||
|--------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|
| [SSLParameters](https://developer.android.com/reference/javax/net/ssl/SSLParameters) | a copy of the SSLParameters object with the maximum supported settings <br /> |

|                                                                                  Throws                                                                                  ||
|------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------|
| [UnsupportedOperationException](https://developer.android.com/reference/java/lang/UnsupportedOperationException) | if the supported SSL parameters could not be obtained. |

### engineInit

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
protected abstract void engineInit (KeyManager[] km, 
                TrustManager[] tm, 
                SecureRandom sr)
```

Initializes this context.

<br />

|                                   Parameters                                    ||
|------|---------------------------------------------------------------------------|
| `km` | `KeyManager`: the sources of authentication keys <br />                   |
| `tm` | `TrustManager`: the sources of peer authentication trust decisions <br /> |
| `sr` | `SecureRandom`: the source of randomness <br />                           |

|                                                             Throws                                                              ||
|--------------------------------------------------------------------------------------------------------|-------------------------|
| [KeyManagementException](https://developer.android.com/reference/java/security/KeyManagementException) | if this operation fails |

**See also:**

- [SSLContext.init(KeyManager[], TrustManager[], SecureRandom)](https://developer.android.com/reference/javax/net/ssl/SSLContext#init(javax.net.ssl.KeyManager[],%20javax.net.ssl.TrustManager[],%20java.security.SecureRandom))