---
name: "libressl-SSL_CTX_new"
section: "3"
platform: "linux"
package: "libressl"
version: "4.4.0-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/libressl-SSL_CTX_new"
---

# libressl-SSL\_CTX\_new(3)

create a new SSL\_CTX object as a framework for TLS enabled functions

## NAME

**SSL\_CTX\_new**, **SSL\_CTX\_up\_ref**, **TLS\_method**, **TLS\_server\_method**, **TLS\_client\_method**, **SSLv23\_method**, **SSLv23\_server\_method**, **SSLv23\_client\_method**, **TLSv1\_method**, **TLSv1\_server\_method**, **TLSv1\_client\_method**, **TLSv1\_1\_method**, **TLSv1\_1\_server\_method**, **TLSv1\_1\_client\_method**, **TLSv1\_2\_method**, **TLSv1\_2\_server\_method**, **TLSv1\_2\_client\_method**, **DTLS\_method**, **DTLS\_server\_method**, **DTLS\_client\_method**, **DTLSv1\_method**, **DTLSv1\_server\_method**, **DTLSv1\_client\_method**, **DTLSv1\_2\_method**, **DTLSv1\_2\_server\_method**, **DTLSv1\_2\_client\_method** – create a new SSL\_CTX object as a framework for TLS enabled functions

## SYNOPSIS

SSL Library (libssl, -lssl) libcrypto

**#include \<openssl/ssl.h\>**

*SSL\_CTX* *\**\

**SSL\_CTX\_new**(*const SSL\_METHOD \*method*);

*int*\

**SSL\_CTX\_up\_ref**(*SSL\_CTX \*ctx*);

*const* *SSL\_METHOD* *\**\

**TLS\_method**(*void*);

*const* *SSL\_METHOD* *\**\

**TLS\_server\_method**(*void*);

*const* *SSL\_METHOD* *\**\

**TLS\_client\_method**(*void*);

*const* *SSL\_METHOD* *\**\

**SSLv23\_method**(*void*);

*const* *SSL\_METHOD* *\**\

**SSLv23\_server\_method**(*void*);

*const* *SSL\_METHOD* *\**\

**SSLv23\_client\_method**(*void*);

*const* *SSL\_METHOD* *\**\

**TLSv1\_method**(*void*);

*const* *SSL\_METHOD* *\**\

**TLSv1\_server\_method**(*void*);

*const* *SSL\_METHOD* *\**\

**TLSv1\_client\_method**(*void*);

*const* *SSL\_METHOD* *\**\

**TLSv1\_1\_method**(*void*);

*const* *SSL\_METHOD* *\**\

**TLSv1\_1\_server\_method**(*void*);

*const* *SSL\_METHOD* *\**\

**TLSv1\_1\_client\_method**(*void*);

*const* *SSL\_METHOD* *\**\

**TLSv1\_2\_method**(*void*);

*const* *SSL\_METHOD* *\**\

**TLSv1\_2\_server\_method**(*void*);

*const* *SSL\_METHOD* *\**\

**TLSv1\_2\_client\_method**(*void*);

*const* *SSL\_METHOD* *\**\

**DTLS\_method**(*void*);

*const* *SSL\_METHOD* *\**\

**DTLS\_server\_method**(*void*);

*const* *SSL\_METHOD* *\**\

**DTLS\_client\_method**(*void*);

*const* *SSL\_METHOD* *\**\

**DTLSv1\_method**(*void*);

*const* *SSL\_METHOD* *\**\

**DTLSv1\_server\_method**(*void*);

*const* *SSL\_METHOD* *\**\

**DTLSv1\_client\_method**(*void*);

*const* *SSL\_METHOD* *\**\

**DTLSv1\_2\_method**(*void*);

*const* *SSL\_METHOD* *\**\

**DTLSv1\_2\_server\_method**(*void*);

*const* *SSL\_METHOD* *\**\

**DTLSv1\_2\_client\_method**(*void*);

## DESCRIPTION

**SSL\_CTX\_new**() creates a new *SSL\_CTX* object as a framework to establish TLS or DTLS enabled connections. It initializes the list of ciphers, the session cache setting, the callbacks, the keys and certificates, the options, and the security level to its default values.

An *SSL\_CTX* object is reference counted. Creating a new *SSL\_CTX* object sets its reference count to 1. Calling **SSL\_CTX\_up\_ref**() on it increments the reference count by 1. Calling SSL\_CTX\_free(3) on it decrements the reference count by 1. When the reference count drops to zero, any memory or resources allocated to the *SSL\_CTX* object are freed.

The *SSL\_CTX* object uses *method* as its connection method, which can be:

- **TLS\_method**()

  The general-purpose version-flexible TLS method. The protocol version used will be negotiated to the highest version mutually supported by the client and the server. The supported protocols are TLSv1, TLSv1.1, TLSv1.2, and TLSv1.3.

- **DTLS\_method**()

  The version-flexible DTLS method. The currently supported protocols are DTLSv1 and DTLSv1.2.

The following *method* arguments are deprecated:

-

  **TLS\_server\_method**(), **TLS\_client\_method**(), **SSLv23\_method**(), **SSLv23\_server\_method**(), **SSLv23\_client\_method**() Deprecated aliases for **TLS\_method**().

-

  **DTLS\_server\_method**(), **DTLS\_client\_method**() Deprecated aliases for **DTLS\_method**().

-

  **TLSv1\_method**(), **TLSv1\_server\_method**(), **TLSv1\_client\_method**() A connection established with these methods will only understand the TLSv1 protocol.

-

  **TLSv1\_1\_method**(), **TLSv1\_1\_server\_method**(), **TLSv1\_1\_client\_method**() A connection established with these methods will only understand the TLSv1.1 protocol.

-

  **TLSv1\_2\_method**(), **TLSv1\_2\_server\_method**(), **TLSv1\_2\_client\_method**() A connection established with these methods will only understand the TLSv1.2 protocol.

-

  **DTLSv1\_method**(), **DTLSv1\_server\_method**(), **DTLSv1\_client\_method**() These are the version-specific methods for DTLSv1.

-

  **DTLSv1\_2\_method**(), **DTLSv1\_2\_server\_method**(), **DTLSv1\_2\_client\_method**() These are the version-specific methods for DTLSv1.2.

In LibreSSL, the methods containing the substrings “\_server” or “\_client” in their names return the same objects as the methods without these substrings.

The list of protocols available can also be limited using the SSL\_OP\_NO\_TLSv1, SSL\_OP\_NO\_TLSv1\_1, and SSL\_OP\_NO\_TLSv1\_2 options of the SSL\_CTX\_set\_options(3) or SSL\_set\_options(3) functions, but this approach is not recommended. Clients should avoid creating "holes" in the set of protocols they support. When disabling a protocol, make sure that you also disable either all previous or all subsequent protocol versions. In clients, when a protocol version is disabled without disabling all previous protocol versions, the effect is to also disable all subsequent protocol versions.

DTLSv1 and DTLSv1.2 can be disabled with SSL\_CTX\_set\_options(3) or SSL\_set\_options(3) using the SSL\_OP\_NO\_DTLSv1 and SSL\_OP\_NO\_DTLSv1\_2 options, respectively.

## RETURN VALUES

**SSL\_CTX\_new**() returns a pointer to the newly allocated object or NULL on failure. Check the error stack to find out the reason for failure.

**SSL\_CTX\_up\_ref**() returns 1 for success or 0 for failure.

**TLS\_method**() and the other **\*\_method**() functions return pointers to constant static objects.

## SEE ALSO

[ssl(3)](/ssl/3.md), SSL\_accept(3), SSL\_CTX\_free(3), SSL\_CTX\_set\_min\_proto\_version(3), SSL\_CTX\_set\_options(3), SSL\_CTX\_set\_security\_level(3), SSL\_set\_connect\_state(3)

## HISTORY

**SSL\_CTX\_new**() first appeared in SSLeay 0.5.1. **SSLv23\_method**(), **SSLv23\_server\_method**(), and **SSLv23\_client\_method**() first appeared in SSLeay 0.8.0. **TLSv1\_method**(), **TLSv1\_server\_method**(), and **TLSv1\_client\_method**() first appeared in SSLeay 0.9.0. All these functions have been available since OpenBSD 2.4.

**DTLSv1\_method**(), **DTLSv1\_server\_method**(), and **DTLSv1\_client\_method**() first appeared in OpenSSL 0.9.8 and have been available since OpenBSD 4.5.

**TLSv1\_1\_method**(), **TLSv1\_1\_server\_method**(), **TLSv1\_1\_client\_method**(), **TLSv1\_2\_method**(), **TLSv1\_2\_server\_method**(), and **TLSv1\_2\_client\_method**() first appeared in OpenSSL 1.0.1 and have been available since OpenBSD 5.3.

**DTLS\_method**(), **DTLS\_server\_method**(), and **DTLS\_client\_method**() first appeared in OpenSSL 1.0.2 and have been available since OpenBSD 6.5.

**TLS\_method**(), **TLS\_server\_method**(), and **TLS\_client\_method**() first appeared in OpenSSL 1.1.0 and have been available since OpenBSD 5.8.

**SSL\_CTX\_up\_ref**() first appeared in OpenSSL 1.1.0 and has been available since OpenBSD 6.3.

**DTLSv1\_2\_method**(), **DTLSv1\_2\_server\_method**(), and **DTLSv1\_2\_client\_method**() first appeared in OpenSSL 1.1.0 and have been available since OpenBSD 6.9.
