1 .\" $OpenBSD: X509_NAME_get_index_by_NID.3,v 1.10 2018/07/09 09:57:41 tb Exp $
2 .\" OpenSSL aebb9aac Jul 19 09:27:53 2016 -0400
4 .\" This file was written by Dr. Stephen Henson <steve@openssl.org>.
5 .\" Copyright (c) 2002, 2006, 2014, 2015, 2016 The OpenSSL Project.
6 .\" All rights reserved.
8 .\" Redistribution and use in source and binary forms, with or without
9 .\" modification, are permitted provided that the following conditions
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\" notice, this list of conditions and the following disclaimer.
15 .\" 2. Redistributions in binary form must reproduce the above copyright
16 .\" notice, this list of conditions and the following disclaimer in
17 .\" the documentation and/or other materials provided with the
20 .\" 3. All advertising materials mentioning features or use of this
21 .\" software must display the following acknowledgment:
22 .\" "This product includes software developed by the OpenSSL Project
23 .\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
25 .\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 .\" endorse or promote products derived from this software without
27 .\" prior written permission. For written permission, please contact
28 .\" openssl-core@openssl.org.
30 .\" 5. Products derived from this software may not be called "OpenSSL"
31 .\" nor may "OpenSSL" appear in their names without prior written
32 .\" permission of the OpenSSL Project.
34 .\" 6. Redistributions of any form whatsoever must retain the following
36 .\" "This product includes software developed by the OpenSSL Project
37 .\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
39 .\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 .\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 .\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 .\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 .\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 .\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 .\" OF THE POSSIBILITY OF SUCH DAMAGE.
52 .Dd $Mdocdate: July 9 2018 $
53 .Dt X509_NAME_GET_INDEX_BY_NID 3
56 .Nm X509_NAME_get_index_by_NID ,
57 .Nm X509_NAME_get_index_by_OBJ ,
58 .Nm X509_NAME_entry_count ,
59 .Nm X509_NAME_get_entry ,
60 .Nm X509_NAME_get_text_by_NID ,
61 .Nm X509_NAME_get_text_by_OBJ
62 .Nd X509_NAME lookup and enumeration functions
66 .Fo X509_NAME_get_index_by_NID
67 .Fa "const X509_NAME *name"
72 .Fo X509_NAME_get_index_by_OBJ
73 .Fa "const X509_NAME *name"
74 .Fa "const ASN1_OBJECT *obj"
78 .Fo X509_NAME_entry_count
79 .Fa "const X509_NAME *name"
82 .Fo X509_NAME_get_entry
83 .Fa "const X509_NAME *name"
87 .Fo X509_NAME_get_text_by_NID
94 .Fo X509_NAME_get_text_by_OBJ
96 .Fa "const ASN1_OBJECT *obj"
101 These functions allow an
103 structure to be examined.
106 structure is the same as the ASN.1
108 type defined in RFC 2459 (and elsewhere) and used, for example,
109 in certificate subject and issuer names.
111 .Fn X509_NAME_get_index_by_NID
113 .Fn X509_NAME_get_index_by_OBJ
114 retrieve the next index matching
121 should initially be set to -1.
122 If there are no more entries, -1 is returned.
125 is invalid (doesn't correspond to a valid OID), -2 is returned.
127 .Fn X509_NAME_entry_count
128 returns the total number of entries in
131 .Fn X509_NAME_get_entry
136 corresponding to index
138 Acceptable values for
141 .Fn X509_NAME_entry_count name
143 The value returned is an internal pointer which must not be freed.
145 .Fn X509_NAME_get_text_by_NID
147 .Fn X509_NAME_get_text_by_OBJ
148 retrieve the "text" from the first entry in
154 If no such entry exists, -1 is returned.
157 bytes will be written and the text written to
159 will be NUL terminated.
160 The length of the output string written is returned excluding the
166 then the amount of space needed in
168 (excluding the final NUL) is returned.
174 codes can be found in the header files
175 .In openssl/obj_mac.h
177 .In openssl/objects.h .
179 Applications which could pass invalid NIDs to
180 .Fn X509_NAME_get_index_by_NID
181 should check for the return value of -2.
182 Alternatively the NID validity can be determined first by checking that
187 .Fn X509_NAME_get_index_by_NID
189 .Fn X509_NAME_get_index_by_OBJ
190 return the index of the next matching entry or -1 if not found.
192 .Fn X509_NAME_entry_count
193 returns the total number of entries.
195 .Fn X509_NAME_get_entry
198 pointer to the requested entry or
200 if the index is invalid.
207 for (i = 0; i < X509_NAME_entry_count(nm); i++) {
208 e = X509_NAME_get_entry(nm, i);
209 /* Do something with e */
213 Process all commonName entries:
219 lastpos = X509_NAME_get_index_by_NID(nm, NID_commonName, lastpos);
222 e = X509_NAME_get_entry(nm, lastpos);
223 /* Do something with e */
227 .Xr d2i_X509_NAME 3 ,
228 .Xr ERR_get_error 3 ,
231 These functions first appeared in SSLeay 0.8.0
232 and have been available since
235 .Fn X509_NAME_get_text_by_NID
237 .Fn X509_NAME_get_text_by_OBJ
238 are legacy functions which have various limitations which make them of
239 minimal use in practice.
240 They can only find the first matching entry and will copy the contents
241 of the field verbatim: this can be highly confusing if the target is a
242 multicharacter string type like a
247 For a more general solution,
248 .Fn X509_NAME_get_index_by_NID
250 .Fn X509_NAME_get_index_by_OBJ
251 should be used, followed by
252 .Fn X509_NAME_get_entry
253 on any matching indices and then the various
255 utility functions on the result.