1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
|
.\" $OpenBSD: OBJ_create.3,v 1.6 2022/01/01 02:06:07 jsg Exp $
.\" full merge up to:
.\" OpenSSL OBJ_nid2obj.pod 9b86974e Aug 17 15:21:33 2015 -0400
.\" selective merge up to:
.\" OpenSSL OBJ_nid2obj.pod 35fd9953 May 28 14:49:38 2019 +0200
.\"
.\" This file is a derived work.
.\" The changes are covered by the following Copyright and license:
.\"
.\" Copyright (c) 2017, 2021 Ingo Schwarze <schwarze@openbsd.org>
.\"
.\" Permission to use, copy, modify, and distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
.\" copyright notice and this permission notice appear in all copies.
.\"
.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
.\" The original file was written by Dr. Stephen Henson <steve@openssl.org>.
.\" Copyright (c) 2002, 2006 The OpenSSL Project.
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\"
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\"
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in
.\" the documentation and/or other materials provided with the
.\" distribution.
.\"
.\" 3. All advertising materials mentioning features or use of this
.\" software must display the following acknowledgment:
.\" "This product includes software developed by the OpenSSL Project
.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
.\"
.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
.\" endorse or promote products derived from this software without
.\" prior written permission. For written permission, please contact
.\" openssl-core@openssl.org.
.\"
.\" 5. Products derived from this software may not be called "OpenSSL"
.\" nor may "OpenSSL" appear in their names without prior written
.\" permission of the OpenSSL Project.
.\"
.\" 6. Redistributions of any form whatsoever must retain the following
.\" acknowledgment:
.\" "This product includes software developed by the OpenSSL Project
.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
.\" OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd $Mdocdate: January 1 2022 $
.Dt OBJ_CREATE 3
.Os
.Sh NAME
.Nm OBJ_new_nid ,
.Nm OBJ_add_object ,
.Nm OBJ_create ,
.\" OBJ_create_and_add_object is a deprecated, unused alias for OBJ_create(3).
.Nm OBJ_create_objects ,
.Nm obj_cleanup_defer ,
.Nm OBJ_cleanup ,
.Nm check_defer
.Nd modify the table of ASN.1 object identifiers
.Sh SYNOPSIS
.In openssl/objects.h
.Ft int
.Fn OBJ_new_nid "int increment"
.Ft int
.Fn OBJ_add_object "const ASN1_OBJECT *object"
.Ft int
.Fo OBJ_create
.Fa "const char *oid"
.Fa "const char *sn"
.Fa "const char *ln"
.Fc
.Ft int
.Fn OBJ_create_objects "BIO *in_bio"
.Vt extern int obj_cleanup_defer ;
.Ft void
.Fn OBJ_cleanup void
.Ft void
.Fn check_defer "int nid"
.Sh DESCRIPTION
.Fn OBJ_new_nid
returns the smallest currently unassigned ASN.1 numeric
object identifier (NID) and reserves
.Fa increment
consecutive NIDs starting with it.
Passing an argument of 1 is usually recommended.
The return value can be assigned to a new object by passing it as the
.Fa nid
argument to
.Xr ASN1_OBJECT_create 3
and by passing the resulting object to
.Fn OBJ_add_object .
.Pp
.Fn OBJ_add_object
adds a copy of the
.Fa object
to the internal table of ASN.1 object identifiers for use by
.Xr OBJ_nid2obj 3
and related functions.
.Pp
.Fn OBJ_create
provides a simpler way to add a new object to the internal table.
.Fa oid
is the numerical form of the object,
.Fa sn
the short name and
.Fa ln
the long name.
A new NID is automatically assigned using
.Fn OBJ_new_nid .
.Pp
.Fn OBJ_create_objects
reads text lines of the form
.Pp
.D1 Fa oid sn ln
.Pp
from
.Fa in_bio
and calls
.Fn OBJ_create oid sn ln
for every line read.
The three fields of the input lines
are separated by one or more whitespace characters.
.Pp
For all three functions, the objects added to the internal table and
all the data contained in them is marked as not dynamically allocated.
Consequently, retrieving them with
.Xr OBJ_nid2obj 3
or a similar function and then calling
.Xr ASN1_OBJECT_free 3
on the returned pointer will have no effect.
.Pp
The global variable
.Va obj_cleanup_defer
controls the behaviour of
.Fn OBJ_cleanup
and
.Xr EVP_cleanup 3 .
.Pp
If
.Va obj_cleanup_defer
has the default value of 0,
.Fn OBJ_cleanup
resets the internal object table to its default state,
removing and freeing all objects that were added with
.Fn OBJ_add_object ,
.Fn OBJ_create ,
or
.Fn OBJ_create_objects .
Otherwise,
.Fn OBJ_cleanup
only sets
.Va obj_cleanup_defer
to 2, which defers the cleanup of the internal object table
to the next call of
.Xr EVP_cleanup 3 .
.Pp
By default,
.Xr EVP_cleanup 3
has no effect on the internal object table.
Only if
.Va obj_cleanup_defer
is 2, it resets
.Va obj_cleanup_defer
to 0 and calls
.Fn OBJ_cleanup ,
which then resets the table to its default state.
.Pp
The function
.Fn check_defer
sets
.Va obj_cleanup_defer
to 1 unless
.Fa nid
is a built-in numeric identifier, but it has no effect if
.Va obj_cleanup_defer
already differs from 0.
This function is called internally by various functions
in the EVP library, in particular by subroutines of
.Xr OpenSSL_add_all_ciphers 3
and
.Xr OpenSSL_add_all_digests 3 .
.Pp
To reliably reset the internal object table no matter what the
current state may be, an application program needs to call both
.Fn OBJ_cleanup
and
.Xr EVP_cleanup 3 ,
in this order.
The opposite order will usually not work.
.Sh RETURN VALUES
.Fn OBJ_new_nid
returns the new NID.
.Pp
.Fn OBJ_add_object
returns the NID associated with the
.Fa object
or
.Dv NID_undef
if memory allocation fails.
.Pp
.Fn OBJ_create
returns the new NID or
.Dv NID_undef
if
.Fa oid
is not a valid representation of an object identifier
or if memory allocation fails.
.Pp
.Fn OBJ_create_objects
returns the number of objects added.
.Pp
In some cases of failure of
.Fn OBJ_add_object ,
.Fn OBJ_create ,
and
.Fn OBJ_create_objects ,
the reason can be determined with
.Xr ERR_get_error 3 .
.Sh EXAMPLES
Create a new NID and initialize an object from it:
.Bd -literal -offset indent
int new_nid;
ASN1_OBJECT *obj;
new_nid = OBJ_create("1.2.3.4", "NewOID", "New Object Identifier");
obj = OBJ_nid2obj(new_nid);
.Ed
.Sh SEE ALSO
.Xr ASN1_OBJECT_new 3 ,
.Xr EVP_cleanup 3 ,
.Xr OBJ_add_sigid 3 ,
.Xr OBJ_NAME_add 3 ,
.Xr OBJ_nid2obj 3
.Sh HISTORY
.Fn OBJ_new_nid ,
.Fn OBJ_add_object ,
and
.Fn OBJ_cleanup
first appeared in SSLeay 0.8.0 and
.Fn OBJ_create
in SSLeay 0.9.0.
These functions have been available since
.Ox 2.4 .
.Pp
.Va obj_cleanup_defer
and
.Fn check_defer
first appeared in OpenSSL 1.0.0 and have been available since
.Ox 4.9 .
.Sh BUGS
.Fn OBJ_new_nid
does not reserve any return value to indicate an error.
Consequently, to avoid conflicting NID assignments and integer overflows,
care must be taken to not pass negative, zero, or large arguments to
.Fn OBJ_new_nid .
.Pp
.Fn OBJ_create_objects
does not distinguish between end of file, I/O errors, temporary
unavailability of data on a non-blocking BIO, invalid input syntax,
and memory allocation failure.
In all these cases, reading is aborted and the number of objects
that were already added is returned.
|