# SSLManager

<a id="sslmanager"></a>

# SSLManager

```cpp
#include <icy/net/sslmanager.h>

class SSLManager
```

[Defined in src/net/include/icy/net/sslmanager.h:31](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/sslmanager.h#L31)

[Singleton](https://auscaster.com/icey/docs/api-reference/icy-Singleton.md#singleton) that owns the default client/server TLS contexts and related callbacks.

## Friends

| Name | Description |
|------|-------------|
| [`Singleton< SSLManager >`](#singletonsslmanager)  |  |
| [`SSLContext`](#sslcontext-7)  |  |

---

<a id="singletonsslmanager"></a>

### Singleton< SSLManager >

```cpp
friend class Singleton< SSLManager >
```

[Defined in src/net/include/icy/net/sslmanager.h:122](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/sslmanager.h#L122)

---

<a id="sslcontext-7"></a>

### SSLContext

```cpp
friend class SSLContext
```

[Defined in src/net/include/icy/net/sslmanager.h:125](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/sslmanager.h#L125)

## Public Attributes

| Return | Name | Description |
|--------|------|-------------|
| [`ThreadSignal`](https://auscaster.com/icey/docs/api-reference/base.md#threadsignal)< void([`VerificationErrorDetails`](https://auscaster.com/icey/docs/api-reference/icy-net-VerificationErrorDetails.md#verificationerrordetails) &)> | [`ServerVerificationError`](#serververificationerror)  | Fired whenever a certificate verification error is detected by the server during a handshake. |
| [`ThreadSignal`](https://auscaster.com/icey/docs/api-reference/base.md#threadsignal)< void([`VerificationErrorDetails`](https://auscaster.com/icey/docs/api-reference/icy-net-VerificationErrorDetails.md#verificationerrordetails) &)> | [`ClientVerificationError`](#clientverificationerror)  | Fired whenever a certificate verification error is detected by the client during a handshake. |
| [`ThreadSignal`](https://auscaster.com/icey/docs/api-reference/base.md#threadsignal)< void(std::string &)> | [`PrivateKeyPassphraseRequired`](#privatekeypassphraserequired)  | Fired when an encrypted certificate or private key is loaded. Not setting the password in the event parameter will result in a failure to load the certificate. |

---

<a id="serververificationerror"></a>

### ServerVerificationError

```cpp
ThreadSignal< void(VerificationErrorDetails &)> ServerVerificationError
```

Type: [`ThreadSignal`](https://auscaster.com/icey/docs/api-reference/base.md#threadsignal)< void([`VerificationErrorDetails`](https://auscaster.com/icey/docs/api-reference/icy-net-VerificationErrorDetails.md#verificationerrordetails) &)>

[Defined in src/net/include/icy/net/sslmanager.h:49](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/sslmanager.h#L49)

Fired whenever a certificate verification error is detected by the server during a handshake.

---

<a id="clientverificationerror"></a>

### ClientVerificationError

```cpp
ThreadSignal< void(VerificationErrorDetails &)> ClientVerificationError
```

Type: [`ThreadSignal`](https://auscaster.com/icey/docs/api-reference/base.md#threadsignal)< void([`VerificationErrorDetails`](https://auscaster.com/icey/docs/api-reference/icy-net-VerificationErrorDetails.md#verificationerrordetails) &)>

[Defined in src/net/include/icy/net/sslmanager.h:53](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/sslmanager.h#L53)

Fired whenever a certificate verification error is detected by the client during a handshake.

---

<a id="privatekeypassphraserequired"></a>

### PrivateKeyPassphraseRequired

```cpp
ThreadSignal< void(std::string &)> PrivateKeyPassphraseRequired
```

Type: [`ThreadSignal`](https://auscaster.com/icey/docs/api-reference/base.md#threadsignal)< void(std::string &)>

[Defined in src/net/include/icy/net/sslmanager.h:57](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/sslmanager.h#L57)

Fired when an encrypted certificate or private key is loaded. Not setting the password in the event parameter will result in a failure to load the certificate.

## Public Methods

| Return | Name | Description |
|--------|------|-------------|
| `void` | [`initializeServer`](#initializeserver)  | Initializes the server side of the [SSLManager](#sslmanager) server-side [SSLContext](https://auscaster.com/icey/docs/api-reference/icy-net-SSLContext.md#sslcontext). |
| `void` | [`initializeClient`](#initializeclient)  | Initializes the client side of the [SSLManager](#sslmanager) with a default client-side [SSLContext](https://auscaster.com/icey/docs/api-reference/icy-net-SSLContext.md#sslcontext). |
| [`SSLContext::Ptr`](https://auscaster.com/icey/docs/api-reference/icy-net-SSLContext.md#ptr-11) | [`defaultServerContext`](#defaultservercontext)  | Returns the default context used by the server if initialized. |
| [`SSLContext::Ptr`](https://auscaster.com/icey/docs/api-reference/icy-net-SSLContext.md#ptr-11) | [`defaultClientContext`](#defaultclientcontext)  | Returns the default context used by the client if initialized. |
| `void` | [`shutdown`](#shutdown-5)  | Shuts down the [SSLManager](#sslmanager) and releases the default context objects. After a call to [shutdown()](#shutdown-5), the [SSLManager](#sslmanager) can no longer be used. |

---

<a id="initializeserver"></a>

### initializeServer

```cpp
void initializeServer(SSLContext::Ptr ptrContext)
```

[Defined in src/net/include/icy/net/sslmanager.h:35](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/sslmanager.h#L35)

Initializes the server side of the [SSLManager](#sslmanager) server-side [SSLContext](https://auscaster.com/icey/docs/api-reference/icy-net-SSLContext.md#sslcontext).

---

<a id="initializeclient"></a>

### initializeClient

```cpp
void initializeClient(SSLContext::Ptr ptrContext)
```

[Defined in src/net/include/icy/net/sslmanager.h:39](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/sslmanager.h#L39)

Initializes the client side of the [SSLManager](#sslmanager) with a default client-side [SSLContext](https://auscaster.com/icey/docs/api-reference/icy-net-SSLContext.md#sslcontext).

---

<a id="defaultservercontext"></a>

### defaultServerContext

```cpp
SSLContext::Ptr defaultServerContext()
```

[Defined in src/net/include/icy/net/sslmanager.h:42](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/sslmanager.h#L42)

Returns the default context used by the server if initialized.

---

<a id="defaultclientcontext"></a>

### defaultClientContext

```cpp
SSLContext::Ptr defaultClientContext()
```

[Defined in src/net/include/icy/net/sslmanager.h:45](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/sslmanager.h#L45)

Returns the default context used by the client if initialized.

---

<a id="shutdown-5"></a>

### shutdown

```cpp
void shutdown()
```

[Defined in src/net/include/icy/net/sslmanager.h:66](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/sslmanager.h#L66)

Shuts down the [SSLManager](#sslmanager) and releases the default context objects. After a call to [shutdown()](#shutdown-5), the [SSLManager](#sslmanager) can no longer be used.

Normally, it's not necessary to call this method directly, as this will be called either by uninitializeSSL(), or when the [SSLManager](#sslmanager) instance is destroyed.

## Public Static Methods

| Return | Name | Description |
|--------|------|-------------|
| [`SSLManager`](#sslmanager) & | [`instance`](#instance-6) `static` | Returns the instance of the [SSLManager](#sslmanager) singleton. |
| `void` | [`destroy`](#destroy-4) `static` | Shuts down and destroys the [SSLManager](#sslmanager) singleton instance. |
| `void` | [`initNoVerifyClient`](#initnoverifyclient) `static` | Initializes a default no-verify client context that's useful for testing. |
| `void` | [`initNoVerifyServer`](#initnoverifyserver) `static` | Initializes a default no-verify server context that's useful for testing. Optionally accepts private key and certificate file paths for server identity; if omitted, no certificate is loaded. |

---

<a id="instance-6"></a>

### instance

`static`

```cpp
static SSLManager & instance()
```

[Defined in src/net/include/icy/net/sslmanager.h:69](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/sslmanager.h#L69)

Returns the instance of the [SSLManager](#sslmanager) singleton.

---

<a id="destroy-4"></a>

### destroy

`static`

```cpp
static void destroy()
```

[Defined in src/net/include/icy/net/sslmanager.h:72](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/sslmanager.h#L72)

Shuts down and destroys the [SSLManager](#sslmanager) singleton instance.

---

<a id="initnoverifyclient"></a>

### initNoVerifyClient

`static`

```cpp
static void initNoVerifyClient()
```

[Defined in src/net/include/icy/net/sslmanager.h:76](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/sslmanager.h#L76)

Initializes a default no-verify client context that's useful for testing.

---

<a id="initnoverifyserver"></a>

### initNoVerifyServer

`static`

```cpp
static void initNoVerifyServer(const std::string & privateKeyFile = "", const std::string & certificateFile = "")
```

[Defined in src/net/include/icy/net/sslmanager.h:81](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/sslmanager.h#L81)

Initializes a default no-verify server context that's useful for testing. Optionally accepts private key and certificate file paths for server identity; if omitted, no certificate is loaded.

## Private Attributes

| Return | Name | Description |
|--------|------|-------------|
| [`SSLContext::Ptr`](https://auscaster.com/icey/docs/api-reference/icy-net-SSLContext.md#ptr-11) | [`_defaultServerContext`](#_defaultservercontext)  |  |
| [`SSLContext::Ptr`](https://auscaster.com/icey/docs/api-reference/icy-net-SSLContext.md#ptr-11) | [`_defaultClientContext`](#_defaultclientcontext)  |  |
| `std::mutex` | [`_mutex`](#_mutex-13)  |  |

---

<a id="_defaultservercontext"></a>

### _defaultServerContext

```cpp
SSLContext::Ptr _defaultServerContext
```

Type: [`SSLContext::Ptr`](https://auscaster.com/icey/docs/api-reference/icy-net-SSLContext.md#ptr-11)

[Defined in src/net/include/icy/net/sslmanager.h:120](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/sslmanager.h#L120)

---

<a id="_defaultclientcontext"></a>

### _defaultClientContext

```cpp
SSLContext::Ptr _defaultClientContext
```

Type: [`SSLContext::Ptr`](https://auscaster.com/icey/docs/api-reference/icy-net-SSLContext.md#ptr-11)

[Defined in src/net/include/icy/net/sslmanager.h:121](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/sslmanager.h#L121)

---

<a id="_mutex-13"></a>

### _mutex

```cpp
std::mutex _mutex
```

[Defined in src/net/include/icy/net/sslmanager.h:122](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/sslmanager.h#L122)

## Private Methods

| Return | Name | Description |
|--------|------|-------------|
|  | [`SSLManager`](#sslmanager-1)  | Creates the [SSLManager](#sslmanager). |
|  | [`~SSLManager`](#sslmanager-2) `noexcept` | Destroys the [SSLManager](#sslmanager). |
|  | [`SSLManager`](#sslmanager-3)  | Deleted constructor. |
| [`SSLManager`](#sslmanager) & | [`operator=`](#operator-185)  | Deleted assignment operator. |
|  | [`SSLManager`](#sslmanager-4)  | Deleted constructor. |
| [`SSLManager`](#sslmanager) & | [`operator=`](#operator-186)  | Deleted assignment operator. |

---

<a id="sslmanager-1"></a>

### SSLManager

```cpp
SSLManager()
```

[Defined in src/net/include/icy/net/sslmanager.h:105](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/sslmanager.h#L105)

Creates the [SSLManager](#sslmanager).

---

<a id="sslmanager-2"></a>

### ~SSLManager

`noexcept`

```cpp
~SSLManager() noexcept
```

[Defined in src/net/include/icy/net/sslmanager.h:108](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/sslmanager.h#L108)

Destroys the [SSLManager](#sslmanager).

---

<a id="sslmanager-3"></a>

### SSLManager

```cpp
SSLManager(const SSLManager &) = delete
```

[Defined in src/net/include/icy/net/sslmanager.h:110](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/sslmanager.h#L110)

Deleted constructor.

---

<a id="operator-185"></a>

### operator=

```cpp
SSLManager & operator=(const SSLManager &) = delete
```

[Defined in src/net/include/icy/net/sslmanager.h:111](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/sslmanager.h#L111)

Deleted assignment operator.

---

<a id="sslmanager-4"></a>

### SSLManager

```cpp
SSLManager(SSLManager &&) = delete
```

[Defined in src/net/include/icy/net/sslmanager.h:112](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/sslmanager.h#L112)

Deleted constructor.

---

<a id="operator-186"></a>

### operator=

```cpp
SSLManager & operator=(SSLManager &&) = delete
```

[Defined in src/net/include/icy/net/sslmanager.h:113](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/sslmanager.h#L113)

Deleted assignment operator.

## Private Static Methods

| Return | Name | Description |
|--------|------|-------------|
| `int` | [`verifyCallback`](#verifycallback) `static` | The return value of this method defines how errors in verification are handled. Return 0 to terminate the handshake, or 1 to continue despite the error. |

---

<a id="verifycallback"></a>

### verifyCallback

`static`

```cpp
static int verifyCallback(bool server, int ok, X509_STORE_CTX * pStore)
```

[Defined in src/net/include/icy/net/sslmanager.h:118](https://github.com/auscaster/icey/blob/main/src/net/include/icy/net/sslmanager.h#L118)

The return value of this method defines how errors in verification are handled. Return 0 to terminate the handshake, or 1 to continue despite the error.
