---
name: "libressl-X509_STORE_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-X509_STORE_CTX_new"
---

# libressl-X509\_STORE\_CTX\_new(3)

X509\_STORE\_CTX initialisation

## NAME

**X509\_STORE\_CTX\_new**, **X509\_STORE\_CTX\_init**, **X509\_STORE\_CTX\_cleanup**, **X509\_STORE\_CTX\_free**, **X509\_STORE\_CTX\_get0\_store**, **X509\_STORE\_CTX\_set0\_trusted\_stack**, **X509\_STORE\_CTX\_trusted\_stack**, **X509\_STORE\_CTX\_set\_cert**, **X509\_STORE\_CTX\_get0\_cert**, **X509\_STORE\_CTX\_set\_chain**, **X509\_STORE\_CTX\_set0\_untrusted**, **X509\_STORE\_CTX\_get0\_untrusted**, **X509\_STORE\_CTX\_set0\_crls** – X509\_STORE\_CTX initialisation

## SYNOPSIS

Crypto Library (libcrypto, -lcrypto)

**#include \<openssl/x509\_vfy.h\>**

*X509\_STORE\_CTX* *\**\

**X509\_STORE\_CTX\_new**(*void*);

*int*\

**X509\_STORE\_CTX\_init**(*X509\_STORE\_CTX \*ctx*, *X509\_STORE \*store*, *X509 \*x*, *STACK\_OF(X509) \*untrusted*);

*void*\

**X509\_STORE\_CTX\_cleanup**(*X509\_STORE\_CTX \*ctx*);

*void*\

**X509\_STORE\_CTX\_free**(*X509\_STORE\_CTX \*ctx*);

*X509\_STORE* *\**\

**X509\_STORE\_CTX\_get0\_store**(*X509\_STORE\_CTX \*ctx*);

*void*\

**X509\_STORE\_CTX\_set0\_trusted\_stack**(*X509\_STORE\_CTX \*ctx*, *STACK\_OF(X509) \*trusted*);

*void*\

**X509\_STORE\_CTX\_trusted\_stack**(*X509\_STORE\_CTX \*ctx*, *STACK\_OF(X509) \*trusted*);

*void*\

**X509\_STORE\_CTX\_set\_cert**(*X509\_STORE\_CTX \*ctx*, *X509 \*x*);

*X509* *\**\

**X509\_STORE\_CTX\_get0\_cert**(*X509\_STORE\_CTX \*ctx*);

*void*\

**X509\_STORE\_CTX\_set\_chain**(*X509\_STORE\_CTX \*ctx*, *STACK\_OF(X509) \*untrusted*);

*void*\

**X509\_STORE\_CTX\_set0\_untrusted**(*X509\_STORE\_CTX \*ctx*, *STACK\_OF(X509) \*untrusted*);

*STACK\_OF(X509)* *\**\

**X509\_STORE\_CTX\_get0\_untrusted**(*X509\_STORE\_CTX \*ctx*);

*void*\

**X509\_STORE\_CTX\_set0\_crls**(*X509\_STORE\_CTX \*ctx*, *STACK\_OF(X509\_CRL) \*crls*);

## DESCRIPTION

These functions set up an *X509\_STORE\_CTX* object for subsequent use by X509\_verify\_cert(3).

**X509\_STORE\_CTX\_new**() allocates an empty *X509\_STORE\_CTX* object not yet containing the subobjects required for normal operation.

**X509\_STORE\_CTX\_init**() needs to be called on each new *ctx* before any of the other functions become useful. It prepares *ctx* for one single verification operation using X509\_verify\_cert(3). The trusted certificate *store* to be used, the end entity certificate *x* to be verified, and a set of additional *untrusted* certificates, to be used for building the chain, can be supplied, or any or all of them can be set to NULL. The three pointers passed in are stored internally, the three objects pointed to are not copied, their reference count is not incremented, and the caller remains responsible for managing their storage and for not freeing them before **X509\_STORE\_CTX\_free**() is called on *ctx*. If a *store* is provided, the verification parameters contained in it are copied using X509\_VERIFY\_PARAM\_inherit(3).

**X509\_STORE\_CTX\_cleanup**() internally cleans up *ctx*, returning it to an empty state similar to the one after **X509\_STORE\_CTX\_new**(). It can then be reused with a new call to **X509\_STORE\_CTX\_init**().

**X509\_STORE\_CTX\_free**() calls **X509\_STORE\_CTX\_cleanup**() and frees the storage pointed to by *ctx*. If *ctx* is a NULL pointer, no action occurs.

**X509\_STORE\_CTX\_get0\_store**() returns the internal pointer to the trusted certificate *store* that was set with **X509\_STORE\_CTX\_init**().

**X509\_STORE\_CTX\_set0\_trusted\_stack**() sets the set of *trusted* certificates used by *ctx*. This is an alternative way of specifying trusted certificates instead of using the *store*. **X509\_STORE\_CTX\_trusted\_stack**() is a deprecated alias for **X509\_STORE\_CTX\_set0\_trusted\_stack**().

**X509\_STORE\_CTX\_set\_cert**() sets the certificate to be verified in *ctx* to *x*, overriding the certificate that was set with **X509\_STORE\_CTX\_init**(). Again, the certificate is not copied and its reference count is not incremented.

**X509\_STORE\_CTX\_get0\_cert**() retrieves the internal pointer to the certificate being verified by *ctx*, i.e. the last one set using either **X509\_STORE\_CTX\_init**() or **X509\_STORE\_CTX\_set\_cert**().

**X509\_STORE\_CTX\_set\_chain**() and **X509\_STORE\_CTX\_set0\_untrusted**() are identical and set the additional, *untrusted* certificates used by *ctx*, overriding the set of additional, untrusted certificates that was set with **X509\_STORE\_CTX\_init**(). Again, the set and the certificates contained in it are not copied and their reference counts are not incremented.

**X509\_STORE\_CTX\_get0\_untrusted**() retrieves the internal pointer to the set of additional, untrusted certificates associated with *ctx*, i.e. the last one set using either **X509\_STORE\_CTX\_init**(), **X509\_STORE\_CTX\_set\_chain**(), or **X509\_STORE\_CTX\_set0\_untrusted**().

**X509\_STORE\_CTX\_set0\_crls**() sets a set of *crls* to use during certificate verification. These CRLs will only be used if CRL verification is enabled in the associated *X509\_VERIFY\_PARAM* structure. This might be used where additional "useful" CRLs are supplied as part of a protocol, for example in a PKCS#7 structure.

Legacy applications might implicitly use an *X509\_STORE\_CTX* like this:

```
X509_STORE_CTX ctx;
X509_STORE_CTX_init(&ctx, store, cert, chain);
```

This is **not** recommended in new applications. They should instead do:

```
X509_STORE_CTX *ctx;
ctx = X509_STORE_CTX_new();
if (ctx == NULL)
	/* Bad error */
X509_STORE_CTX_init(ctx, store, cert, chain);
```

## RETURN VALUES

**X509\_STORE\_CTX\_new**() returns a newly allocated context or NULL if an error occurred.

**X509\_STORE\_CTX\_init**() returns 1 for success or 0 if an error occurred.

**X509\_STORE\_CTX\_get0\_store**() returns the internal pointer to the trusted certificate store or NULL if none was set.

**X509\_STORE\_CTX\_get0\_cert**() returns the internal pointer to the certificate to be verified or NULL if no such certificate was set.

**X509\_STORE\_CTX\_get0\_untrusted**() returns the internal pointer to the set of additional, untrusted certificates or NULL if no set of additional certificates was provided.

## SEE ALSO

X509\_CRL\_new(3), X509\_STORE\_CTX\_get\_error(3), X509\_STORE\_CTX\_get\_ex\_new\_index(3), X509\_STORE\_CTX\_set\_flags(3), X509\_STORE\_CTX\_set\_verify(3), X509\_STORE\_CTX\_set\_verify\_cb(3), X509\_STORE\_get\_by\_subject(3), X509\_STORE\_new(3), X509\_STORE\_set1\_param(3), X509\_STORE\_set\_verify\_cb(3), X509\_verify\_cert(3), X509\_VERIFY\_PARAM\_inherit(3), X509\_VERIFY\_PARAM\_set\_flags(3)

## HISTORY

**X509\_STORE\_CTX\_init**(), **X509\_STORE\_CTX\_cleanup**(), **X509\_STORE\_CTX\_set\_cert**(), and **X509\_STORE\_CTX\_set\_chain**() first appeared in SSLeay 0.8.0 and have been available since OpenBSD 2.4.

**X509\_STORE\_CTX\_new**() and **X509\_STORE\_CTX\_free**() first appeared in OpenSSL 0.9.5 and have been available since OpenBSD 2.7.

**X509\_STORE\_CTX\_trusted\_stack**() first appeared in OpenSSL 0.9.6 and has been available since OpenBSD 2.9.

**X509\_STORE\_CTX\_get0\_store**() first appeared in OpenSSL 1.0.2. **X509\_STORE\_CTX\_set0\_trusted\_stack**(), **X509\_STORE\_CTX\_get0\_cert**(), **X509\_STORE\_CTX\_set0\_untrusted**(), and **X509\_STORE\_CTX\_get0\_untrusted**() first appeared in OpenSSL 1.1.0. These functions have been available since OpenBSD 6.3.
