1.\" $OpenBSD: X509_STORE_CTX_new.3,v 1.27 2022/11/16 14:55:40 schwarze Exp $ 2.\" full merge up to: OpenSSL aae41f8c Jun 25 09:47:15 2015 +0100 3.\" selective merge up to: OpenSSL 24a535ea Sep 22 13:14:20 2020 +0100 4.\" 5.\" This file is a derived work. 6.\" The changes are covered by the following Copyright and license: 7.\" 8.\" Copyright (c) 2021 Ingo Schwarze <schwarze@openbsd.org> 9.\" 10.\" Permission to use, copy, modify, and distribute this software for any 11.\" purpose with or without fee is hereby granted, provided that the above 12.\" copyright notice and this permission notice appear in all copies. 13.\" 14.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 15.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 16.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 17.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 18.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 19.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 20.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 21.\" 22.\" The original file was written by Dr. Stephen Henson <steve@openssl.org> 23.\" and Rich Salz <rsalz@openssl.org>. 24.\" Copyright (c) 2009, 2016 The OpenSSL Project. All rights reserved. 25.\" 26.\" Redistribution and use in source and binary forms, with or without 27.\" modification, are permitted provided that the following conditions 28.\" are met: 29.\" 30.\" 1. Redistributions of source code must retain the above copyright 31.\" notice, this list of conditions and the following disclaimer. 32.\" 33.\" 2. Redistributions in binary form must reproduce the above copyright 34.\" notice, this list of conditions and the following disclaimer in 35.\" the documentation and/or other materials provided with the 36.\" distribution. 37.\" 38.\" 3. All advertising materials mentioning features or use of this 39.\" software must display the following acknowledgment: 40.\" "This product includes software developed by the OpenSSL Project 41.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)" 42.\" 43.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 44.\" endorse or promote products derived from this software without 45.\" prior written permission. For written permission, please contact 46.\" openssl-core@openssl.org. 47.\" 48.\" 5. Products derived from this software may not be called "OpenSSL" 49.\" nor may "OpenSSL" appear in their names without prior written 50.\" permission of the OpenSSL Project. 51.\" 52.\" 6. Redistributions of any form whatsoever must retain the following 53.\" acknowledgment: 54.\" "This product includes software developed by the OpenSSL Project 55.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)" 56.\" 57.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 58.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 59.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 60.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 61.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 62.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 63.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 64.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 65.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 66.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 67.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 68.\" OF THE POSSIBILITY OF SUCH DAMAGE. 69.\" 70.Dd $Mdocdate: November 16 2022 $ 71.Dt X509_STORE_CTX_NEW 3 72.Os 73.Sh NAME 74.Nm X509_STORE_CTX_new , 75.Nm X509_STORE_CTX_init , 76.Nm X509_STORE_CTX_cleanup , 77.Nm X509_STORE_CTX_free , 78.Nm X509_STORE_CTX_get0_store , 79.Nm X509_STORE_CTX_set0_trusted_stack , 80.Nm X509_STORE_CTX_trusted_stack , 81.Nm X509_STORE_CTX_set_cert , 82.Nm X509_STORE_CTX_get0_cert , 83.\" X509_STORE_CTX_get0_chain moved to X509_STORE_CTX_get_error(3) 84.Nm X509_STORE_CTX_set_chain , 85.Nm X509_STORE_CTX_set0_untrusted , 86.Nm X509_STORE_CTX_get0_untrusted , 87.Nm X509_STORE_CTX_set0_crls 88.\" X509_STORE_CTX_verify_fn moved to X509_STORE_CTX_set_verify(3) 89.\" X509_STORE_CTX_set_verify moved to X509_STORE_CTX_set_verify(3) 90.Nd X509_STORE_CTX initialisation 91.Sh SYNOPSIS 92.In openssl/x509_vfy.h 93.Ft X509_STORE_CTX * 94.Fn X509_STORE_CTX_new void 95.Ft int 96.Fo X509_STORE_CTX_init 97.Fa "X509_STORE_CTX *ctx" 98.Fa "X509_STORE *store" 99.Fa "X509 *x" 100.Fa "STACK_OF(X509) *untrusted" 101.Fc 102.Ft void 103.Fo X509_STORE_CTX_cleanup 104.Fa "X509_STORE_CTX *ctx" 105.Fc 106.Ft void 107.Fo X509_STORE_CTX_free 108.Fa "X509_STORE_CTX *ctx" 109.Fc 110.Ft X509_STORE * 111.Fo X509_STORE_CTX_get0_store 112.Fa "X509_STORE_CTX *ctx" 113.Fc 114.Ft void 115.Fo X509_STORE_CTX_set0_trusted_stack 116.Fa "X509_STORE_CTX *ctx" 117.Fa "STACK_OF(X509) *trusted" 118.Fc 119.Ft void 120.Fo X509_STORE_CTX_trusted_stack 121.Fa "X509_STORE_CTX *ctx" 122.Fa "STACK_OF(X509) *trusted" 123.Fc 124.Ft void 125.Fo X509_STORE_CTX_set_cert 126.Fa "X509_STORE_CTX *ctx" 127.Fa "X509 *x" 128.Fc 129.Ft X509 * 130.Fo X509_STORE_CTX_get0_cert 131.Fa "X509_STORE_CTX *ctx" 132.Fc 133.Ft void 134.Fo X509_STORE_CTX_set_chain 135.Fa "X509_STORE_CTX *ctx" 136.Fa "STACK_OF(X509) *untrusted" 137.Fc 138.Ft void 139.Fo X509_STORE_CTX_set0_untrusted 140.Fa "X509_STORE_CTX *ctx" 141.Fa "STACK_OF(X509) *untrusted" 142.Fc 143.Ft STACK_OF(X509) * 144.Fo X509_STORE_CTX_get0_untrusted 145.Fa "X509_STORE_CTX *ctx" 146.Fc 147.Ft void 148.Fo X509_STORE_CTX_set0_crls 149.Fa "X509_STORE_CTX *ctx" 150.Fa "STACK_OF(X509_CRL) *crls" 151.Fc 152.Sh DESCRIPTION 153These functions set up an 154.Vt X509_STORE_CTX 155object for subsequent use by 156.Xr X509_verify_cert 3 . 157.Pp 158.Fn X509_STORE_CTX_new 159allocates an empty 160.Vt X509_STORE_CTX 161object not yet containing the subobjects required for normal operation. 162.Pp 163.Fn X509_STORE_CTX_init 164needs to be called on each new 165.Fa ctx 166before any of the other functions become useful. 167It prepares 168.Fa ctx 169for one single verification operation using 170.Xr X509_verify_cert 3 . 171The trusted certificate 172.Fa store 173to be used, the end entity certificate 174.Fa x 175to be verified, and a set of additional 176.Fa untrusted 177certificates, to be used for building the chain, 178can be supplied, or any or all of them can be set to 179.Dv NULL . 180The three pointers passed in are stored internally, the three objects 181pointed to are not copied, their reference count is not incremented, 182and the caller remains responsible for managing their storage and for 183not freeing them before 184.Fn X509_STORE_CTX_free 185is called on 186.Fa ctx . 187If a 188.Fa store 189is provided, the verification parameters contained in it are copied using 190.Xr X509_VERIFY_PARAM_inherit 3 . 191.Pp 192.Fn X509_STORE_CTX_cleanup 193internally cleans up 194.Fa ctx , 195returning it to an empty state similar to the one after 196.Fn X509_STORE_CTX_new . 197It can then be reused with a new call to 198.Fn X509_STORE_CTX_init . 199.Pp 200.Fn X509_STORE_CTX_free 201calls 202.Fn X509_STORE_CTX_cleanup 203and frees the storage pointed to by 204.Fa ctx . 205If 206.Fa ctx 207is a 208.Dv NULL 209pointer, no action occurs. 210.Pp 211.Fn X509_STORE_CTX_get0_store 212returns the internal pointer to the trusted certificate 213.Fa store 214that was set with 215.Fn X509_STORE_CTX_init . 216.Pp 217.Fn X509_STORE_CTX_set0_trusted_stack 218sets the set of 219.Fa trusted 220certificates used by 221.Fa ctx . 222This is an alternative way of specifying trusted certificates instead of 223using the 224.Fa store . 225.Fn X509_STORE_CTX_trusted_stack 226is a deprecated alias for 227.Fn X509_STORE_CTX_set0_trusted_stack . 228.Pp 229.Fn X509_STORE_CTX_set_cert 230sets the certificate to be verified in 231.Fa ctx 232to 233.Fa x , 234overriding the certificate that was set with 235.Fn X509_STORE_CTX_init . 236Again, the certificate is not copied 237and its reference count is not incremented. 238.Pp 239.Fn X509_STORE_CTX_get0_cert 240retrieves the internal pointer to the certificate being verified by 241.Fa ctx , 242i.e. the last one set using either 243.Fn X509_STORE_CTX_init 244or 245.Fn X509_STORE_CTX_set_cert . 246.Pp 247.Fn X509_STORE_CTX_set_chain 248and 249.Fn X509_STORE_CTX_set0_untrusted 250are identical and set the additional, 251.Fa untrusted 252certificates used by 253.Fa ctx , 254overriding the set of additional, untrusted certificates that was set with 255.Fn X509_STORE_CTX_init . 256Again, the set and the certificates contained in it are not copied 257and their reference counts are not incremented. 258.Pp 259.Fn X509_STORE_CTX_get0_untrusted 260retrieves the internal pointer 261to the set of additional, untrusted certificates associated with 262.Fa ctx , 263i.e. the last one set using either 264.Fn X509_STORE_CTX_init , 265.Fn X509_STORE_CTX_set_chain , 266or 267.Fn X509_STORE_CTX_set0_untrusted . 268.Pp 269.Fn X509_STORE_CTX_set0_crls 270sets a set of 271.Fa crls 272to use during certificate verification. 273These CRLs will only be used if CRL verification is enabled in the 274associated 275.Vt X509_VERIFY_PARAM 276structure. 277This might be used where additional "useful" CRLs are supplied as part 278of a protocol, for example in a PKCS#7 structure. 279.Pp 280Legacy applications might implicitly use an 281.Vt X509_STORE_CTX 282like this: 283.Bd -literal -offset indent 284X509_STORE_CTX ctx; 285X509_STORE_CTX_init(&ctx, store, cert, chain); 286.Ed 287.Pp 288This is 289.Sy not 290recommended in new applications. 291They should instead do: 292.Bd -literal -offset indent 293X509_STORE_CTX *ctx; 294ctx = X509_STORE_CTX_new(); 295if (ctx == NULL) 296 /* Bad error */ 297X509_STORE_CTX_init(ctx, store, cert, chain); 298.Ed 299.Sh RETURN VALUES 300.Fn X509_STORE_CTX_new 301returns a newly allocated context or 302.Dv NULL 303if an error occurred. 304.Pp 305.Fn X509_STORE_CTX_init 306returns 1 for success or 0 if an error occurred. 307.Pp 308.Fn X509_STORE_CTX_get0_store 309returns the internal pointer to the trusted certificate store or 310.Dv NULL 311if none was set. 312.Pp 313.Fn X509_STORE_CTX_get0_cert 314returns the internal pointer to the certificate to be verified or 315.Dv NULL 316if no such certificate was set. 317.Pp 318.Fn X509_STORE_CTX_get0_untrusted 319returns the internal pointer 320to the set of additional, untrusted certificates or 321.Dv NULL 322if no set of additional certificates was provided. 323.Sh SEE ALSO 324.Xr X509_CRL_new 3 , 325.Xr X509_STORE_CTX_get_error 3 , 326.Xr X509_STORE_CTX_get_ex_new_index 3 , 327.Xr X509_STORE_CTX_set_flags 3 , 328.Xr X509_STORE_CTX_set_verify 3 , 329.Xr X509_STORE_CTX_set_verify_cb 3 , 330.Xr X509_STORE_get_by_subject 3 , 331.Xr X509_STORE_new 3 , 332.Xr X509_STORE_set1_param 3 , 333.Xr X509_STORE_set_verify_cb 3 , 334.Xr X509_verify_cert 3 , 335.Xr X509_VERIFY_PARAM_inherit 3 , 336.Xr X509_VERIFY_PARAM_set_flags 3 337.Sh HISTORY 338.Fn X509_STORE_CTX_init , 339.Fn X509_STORE_CTX_cleanup , 340.Fn X509_STORE_CTX_set_cert , 341and 342.Fn X509_STORE_CTX_set_chain 343first appeared in SSLeay 0.8.0 and have been available since 344.Ox 2.4 . 345.Pp 346.Fn X509_STORE_CTX_new 347and 348.Fn X509_STORE_CTX_free 349first appeared in OpenSSL 0.9.5 and have been available since 350.Ox 2.7 . 351.Pp 352.Fn X509_STORE_CTX_trusted_stack 353first appeared in OpenSSL 0.9.6 and has been available since 354.Ox 2.9 . 355.Pp 356.Fn X509_STORE_CTX_get0_store 357first appeared in OpenSSL 1.0.2. 358.Fn X509_STORE_CTX_set0_trusted_stack , 359.Fn X509_STORE_CTX_get0_cert , 360.Fn X509_STORE_CTX_set0_untrusted , 361and 362.Fn X509_STORE_CTX_get0_untrusted 363first appeared in OpenSSL 1.1.0. 364These functions have been available since 365.Ox 6.3 . 366