1.\" $OpenBSD: X509v3_get_ext_by_NID.3,v 1.11 2019/06/06 01:06:59 schwarze Exp $ 2.\" full merge up to: OpenSSL fd38836b Jun 20 15:25:43 2018 +0100 3.\" 4.\" This file was written by Dr. Stephen Henson <steve@openssl.org>. 5.\" Copyright (c) 2015 The OpenSSL Project. All rights reserved. 6.\" 7.\" Redistribution and use in source and binary forms, with or without 8.\" modification, are permitted provided that the following conditions 9.\" are met: 10.\" 11.\" 1. Redistributions of source code must retain the above copyright 12.\" notice, this list of conditions and the following disclaimer. 13.\" 14.\" 2. Redistributions in binary form must reproduce the above copyright 15.\" notice, this list of conditions and the following disclaimer in 16.\" the documentation and/or other materials provided with the 17.\" distribution. 18.\" 19.\" 3. All advertising materials mentioning features or use of this 20.\" software must display the following acknowledgment: 21.\" "This product includes software developed by the OpenSSL Project 22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)" 23.\" 24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 25.\" endorse or promote products derived from this software without 26.\" prior written permission. For written permission, please contact 27.\" openssl-core@openssl.org. 28.\" 29.\" 5. Products derived from this software may not be called "OpenSSL" 30.\" nor may "OpenSSL" appear in their names without prior written 31.\" permission of the OpenSSL Project. 32.\" 33.\" 6. Redistributions of any form whatsoever must retain the following 34.\" acknowledgment: 35.\" "This product includes software developed by the OpenSSL Project 36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)" 37.\" 38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 49.\" OF THE POSSIBILITY OF SUCH DAMAGE. 50.\" 51.Dd $Mdocdate: June 6 2019 $ 52.Dt X509V3_GET_EXT_BY_NID 3 53.Os 54.Sh NAME 55.Nm X509v3_get_ext_count , 56.Nm X509v3_get_ext , 57.Nm X509v3_get_ext_by_NID , 58.Nm X509v3_get_ext_by_OBJ , 59.Nm X509v3_get_ext_by_critical , 60.Nm X509v3_delete_ext , 61.Nm X509v3_add_ext , 62.Nm X509_get_ext_count , 63.Nm X509_get_ext , 64.Nm X509_get_ext_by_NID , 65.Nm X509_get_ext_by_OBJ , 66.Nm X509_get_ext_by_critical , 67.Nm X509_delete_ext , 68.Nm X509_add_ext , 69.Nm X509_CRL_get_ext_count , 70.Nm X509_CRL_get_ext , 71.Nm X509_CRL_get_ext_by_NID , 72.Nm X509_CRL_get_ext_by_OBJ , 73.Nm X509_CRL_get_ext_by_critical , 74.Nm X509_CRL_delete_ext , 75.Nm X509_CRL_add_ext , 76.Nm X509_REVOKED_get_ext_count , 77.Nm X509_REVOKED_get_ext , 78.Nm X509_REVOKED_get_ext_by_NID , 79.Nm X509_REVOKED_get_ext_by_OBJ , 80.Nm X509_REVOKED_get_ext_by_critical , 81.Nm X509_REVOKED_delete_ext , 82.Nm X509_REVOKED_add_ext 83.Nd extension stack utility functions 84.Sh SYNOPSIS 85.In openssl/x509.h 86.Ft int 87.Fo X509v3_get_ext_count 88.Fa "const STACK_OF(X509_EXTENSION) *x" 89.Fc 90.Ft X509_EXTENSION * 91.Fo X509v3_get_ext 92.Fa "const STACK_OF(X509_EXTENSION) *x" 93.Fa "int loc" 94.Fc 95.Ft int 96.Fo X509v3_get_ext_by_NID 97.Fa "const STACK_OF(X509_EXTENSION) *x" 98.Fa "int nid" 99.Fa "int lastpos" 100.Fc 101.Ft int 102.Fo X509v3_get_ext_by_OBJ 103.Fa "const STACK_OF(X509_EXTENSION) *x" 104.Fa "const ASN1_OBJECT *obj" 105.Fa "int lastpos" 106.Fc 107.Ft int 108.Fo X509v3_get_ext_by_critical 109.Fa "const STACK_OF(X509_EXTENSION) *x" 110.Fa "int crit" 111.Fa "int lastpos" 112.Fc 113.Ft X509_EXTENSION * 114.Fo X509v3_delete_ext 115.Fa "STACK_OF(X509_EXTENSION) *x" 116.Fa "int loc" 117.Fc 118.Ft STACK_OF(X509_EXTENSION) * 119.Fo X509v3_add_ext 120.Fa "STACK_OF(X509_EXTENSION) **x" 121.Fa "X509_EXTENSION *ex" 122.Fa "int loc" 123.Fc 124.Ft int 125.Fo X509_get_ext_count 126.Fa "const X509 *x" 127.Fc 128.Ft X509_EXTENSION * 129.Fo X509_get_ext 130.Fa "const X509 *x" 131.Fa "int loc" 132.Fc 133.Ft int 134.Fo X509_get_ext_by_NID 135.Fa "const X509 *x" 136.Fa "int nid" 137.Fa "int lastpos" 138.Fc 139.Ft int 140.Fo X509_get_ext_by_OBJ 141.Fa "const X509 *x" 142.Fa "const ASN1_OBJECT *obj" 143.Fa "int lastpos" 144.Fc 145.Ft int 146.Fo X509_get_ext_by_critical 147.Fa "const X509 *x" 148.Fa "int crit" 149.Fa "int lastpos" 150.Fc 151.Ft X509_EXTENSION * 152.Fo X509_delete_ext 153.Fa "X509 *x" 154.Fa "int loc" 155.Fc 156.Ft int 157.Fo X509_add_ext 158.Fa "X509 *x" 159.Fa "X509_EXTENSION *ex" 160.Fa "int loc" 161.Fc 162.Ft int 163.Fo X509_CRL_get_ext_count 164.Fa "const X509_CRL *x" 165.Fc 166.Ft X509_EXTENSION * 167.Fo X509_CRL_get_ext 168.Fa "const X509_CRL *x" 169.Fa "int loc" 170.Fc 171.Ft int 172.Fo X509_CRL_get_ext_by_NID 173.Fa "const X509_CRL *x" 174.Fa "int nid" 175.Fa "int lastpos" 176.Fc 177.Ft int 178.Fo X509_CRL_get_ext_by_OBJ 179.Fa "const X509_CRL *x" 180.Fa "const ASN1_OBJECT *obj" 181.Fa "int lastpos" 182.Fc 183.Ft int 184.Fo X509_CRL_get_ext_by_critical 185.Fa "const X509_CRL *x" 186.Fa "int crit" 187.Fa "int lastpos" 188.Fc 189.Ft X509_EXTENSION * 190.Fo X509_CRL_delete_ext 191.Fa "X509_CRL *x" 192.Fa "int loc" 193.Fc 194.Ft int 195.Fo X509_CRL_add_ext 196.Fa "X509_CRL *x" 197.Fa "X509_EXTENSION *ex" 198.Fa "int loc" 199.Fc 200.Ft int 201.Fo X509_REVOKED_get_ext_count 202.Fa "const X509_REVOKED *x" 203.Fc 204.Ft X509_EXTENSION * 205.Fo X509_REVOKED_get_ext 206.Fa "const X509_REVOKED *x" 207.Fa "int loc" 208.Fc 209.Ft int 210.Fo X509_REVOKED_get_ext_by_NID 211.Fa "const X509_REVOKED *x" 212.Fa "int nid" 213.Fa "int lastpos" 214.Fc 215.Ft int 216.Fo X509_REVOKED_get_ext_by_OBJ 217.Fa "const X509_REVOKED *x" 218.Fa "const ASN1_OBJECT *obj" 219.Fa "int lastpos" 220.Fc 221.Ft int 222.Fo X509_REVOKED_get_ext_by_critical 223.Fa "const X509_REVOKED *x" 224.Fa "int crit" 225.Fa "int lastpos" 226.Fc 227.Ft X509_EXTENSION * 228.Fo X509_REVOKED_delete_ext 229.Fa "X509_REVOKED *x" 230.Fa "int loc" 231.Fc 232.Ft int 233.Fo X509_REVOKED_add_ext 234.Fa "X509_REVOKED *x" 235.Fa "X509_EXTENSION *ex" 236.Fa "int loc" 237.Fc 238.Sh DESCRIPTION 239.Fn X509v3_get_ext_count 240retrieves the number of extensions in 241.Fa x . 242.Pp 243.Fn X509v3_get_ext 244retrieves extension 245.Fa loc 246from 247.Fa x . 248The index 249.Fa loc 250can take any value from 0 to 251.Fn X509_get_ext_count x No - 1 . 252The returned extension is an internal pointer which must not be 253freed up by the application. 254.Pp 255.Fn X509v3_get_ext_by_NID 256and 257.Fn X509v3_get_ext_by_OBJ 258look for an extension with 259.Fa nid 260or 261.Fa obj 262from extension stack 263.Fa x . 264The search starts from the extension after 265.Fa lastpos 266or from the beginning if 267.Fa lastpos 268is -1. 269If the extension is found, its index is returned; otherwise, -1 is 270returned. 271.Pp 272.Fn X509v3_get_ext_by_critical 273is similar to 274.Fn X509v3_get_ext_by_NID 275except that it looks for an extension of criticality 276.Fa crit . 277A zero value for 278.Fa crit 279looks for a non-critical extension; a non-zero value looks for a 280critical extension. 281.Pp 282.Fn X509v3_delete_ext 283deletes the extension with index 284.Fa loc 285from 286.Fa x . 287The deleted extension is returned and must be freed by the caller. 288If 289.Fa loc 290is an invalid index value, 291.Dv NULL 292is returned. 293.Pp 294.Fn X509v3_add_ext 295adds the extension 296.Fa ex 297to the stack 298.Pf * Fa x 299at position 300.Fa loc . 301If 302.Fa loc 303is -1, the new extension is added to the end. 304If 305.Pf * Fa x 306is 307.Dv NULL , 308a new stack will be allocated. 309The passed extension 310.Fa ex 311is duplicated internally so it must be freed after use. 312.Pp 313.Fn X509_get_ext_count , 314.Fn X509_get_ext , 315.Fn X509_get_ext_by_NID , 316.Fn X509_get_ext_by_OBJ , 317.Fn X509_get_ext_by_critical , 318.Fn X509_delete_ext , 319and 320.Fn X509_add_ext 321operate on the extensions of certificate 322.Fa x . 323They are otherwise identical to the X509v3 functions. 324.Pp 325.Fn X509_CRL_get_ext_count , 326.Fn X509_CRL_get_ext , 327.Fn X509_CRL_get_ext_by_NID , 328.Fn X509_CRL_get_ext_by_OBJ , 329.Fn X509_CRL_get_ext_by_critical , 330.Fn X509_CRL_delete_ext , 331and 332.Fn X509_CRL_add_ext 333operate on the extensions of the CRL 334.Fa x . 335They are otherwise identical to the X509v3 functions. 336.Pp 337.Fn X509_REVOKED_get_ext_count , 338.Fn X509_REVOKED_get_ext , 339.Fn X509_REVOKED_get_ext_by_NID , 340.Fn X509_REVOKED_get_ext_by_OBJ , 341.Fn X509_REVOKED_get_ext_by_critical , 342.Fn X509_REVOKED_delete_ext , 343and 344.Fn X509_REVOKED_add_ext 345operate on the extensions of the CRL entry 346.Fa x . 347They are otherwise identical to the X509v3 functions. 348.Pp 349These functions are used to examine stacks of extensions directly. 350Many applications will want to parse or encode and add an extension: 351they should use the extension encode and decode functions instead 352such as 353.Xr X509_get_ext_d2i 3 . 354.Pp 355Extension indices start from zero, so a zero index return value is 356not an error. 357These search functions start from the extension 358.Em after 359the 360.Fa lastpos 361parameter, so it should initially be set to -1. 362If it is set to 0, the initial extension will not be checked. 363.Sh RETURN VALUES 364.Fn X509v3_get_ext_count 365returns the extension count. 366.Pp 367.Fn X509v3_get_ext , 368.Fn X509v3_delete_ext , 369and 370.Fn X509_delete_ext 371return an 372.Vt X509_EXTENSION 373pointer or 374.Dv NULL 375if an error occurs. 376.Pp 377.Fn X509v3_get_ext_by_NID , 378.Fn X509v3_get_ext_by_OBJ , 379and 380.Fn X509v3_get_ext_by_critical 381return the extension index or -1 if an error occurs. 382.Pp 383.Fn X509v3_add_ext 384returns a stack of extensions or 385.Dv NULL 386on error. 387.Pp 388.Fn X509_add_ext 389returns 1 on success or 0 on error. 390.Sh SEE ALSO 391.Xr X509_CRL_new 3 , 392.Xr X509_EXTENSION_new 3 , 393.Xr X509_new 3 , 394.Xr X509_REVOKED_new 3 , 395.Xr X509V3_get_d2i 3 396.Sh HISTORY 397These functions first appeared in SSLeay 0.8.0 398and have been available since 399.Ox 2.4 . 400