summaryrefslogtreecommitdiff
path: root/lib/libcrypto/man/X509_ATTRIBUTE_set1_object.3
blob: 3555d4b16910549e0b3f57dea66b07ebf1072f4c (plain)
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
.\" $OpenBSD: X509_ATTRIBUTE_set1_object.3,v 1.3 2021/11/26 13:48:21 jsg Exp $
.\"
.\" Copyright (c) 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.
.\"
.Dd $Mdocdate: November 26 2021 $
.Dt X509_ATTRIBUTE_SET1_OBJECT 3
.Os
.Sh NAME
.Nm X509_ATTRIBUTE_set1_object ,
.Nm X509_ATTRIBUTE_set1_data ,
.Nm X509_ATTRIBUTE_create_by_OBJ ,
.Nm X509_ATTRIBUTE_create_by_NID ,
.Nm X509_ATTRIBUTE_create_by_txt
.\" In the following line, "X.501" and "Attribute" are not typos.
.\" The "Attribute" type is defined in X.501, not in X.509.
.\" The type is called "Attribute" with capital "A", not "attribute".
.Nd modify an X.501 Attribute
.Sh SYNOPSIS
.In openssl/x509.h
.Ft int
.Fo X509_ATTRIBUTE_set1_object
.Fa "X509_ATTRIBUTE *attr"
.Fa "const ASN1_OBJECT *obj"
.Fc
.Ft int
.Fo X509_ATTRIBUTE_set1_data
.Fa "X509_ATTRIBUTE *attr"
.Fa "int type"
.Fa "const void *data"
.Fa "int len"
.Fc
.Ft X509_ATTRIBUTE *
.Fo X509_ATTRIBUTE_create_by_OBJ
.Fa "X509_ATTRIBUTE **pattr"
.Fa "const ASN1_OBJECT *obj"
.Fa "int type"
.Fa "const void *data"
.Fa "int len"
.Fc
.Ft X509_ATTRIBUTE *
.Fo X509_ATTRIBUTE_create_by_NID
.Fa "X509_ATTRIBUTE **pattr"
.Fa "int nid"
.Fa "int type"
.Fa "const void *data"
.Fa "int len"
.Fc
.Ft X509_ATTRIBUTE *
.Fo X509_ATTRIBUTE_create_by_txt
.Fa "X509_ATTRIBUTE **pattr"
.Fa "const char *name"
.Fa "int type"
.Fa "const unsigned char *data"
.Fa "int len"
.Fc
.Sh DESCRIPTION
.Fn X509_ATTRIBUTE_set1_object
sets the type of
.Fa attr
to
.Fa obj .
If
.Fa obj
is dynamically allocated, a deep copy is created.
If the type of
.Fa attr
was already set, the old type is freed
as far as it was dynamically allocated.
After calling this function,
.Fa attr
may be in an inconsistent state
because its values may not agree with the new attribute type.
.Pp
.Fn X509_ATTRIBUTE_set1_data
sets
.Fa attr
to be multi-valued and initializes its set of values
to contain a single new ASN.1 ANY object representing the
.Fa data .
.Pp
The interpretation of the
.Fa data
depends on the values of the
.Fa type
and
.Fa len
arguments; there are four different cases.
.Pp
If the
.Fa type
argument has the bit
.Dv MBSTRING_FLAG
set,
.Fa data
is expected to point to a multibyte character string that is
.Fa len
bytes long and uses the encoding specified by the
.Fa type
argument, and it is expected that an attribute type was already assigned to
.Fa attr ,
for example by calling
.Fn X509_ATTRIBUTE_set1_object
before calling
.Fn X509_ATTRIBUTE_set1_data .
In this case, an appropriate ASN.1 multibyte string type is chosen and
a new object of that type is allocated and populated to represent the
.Fa data
by calling
.Xr ASN1_STRING_set_by_NID 3 .
The type of that new ASN.1 string object is subsequently used instead of the
.Fa type
argument.
.Pp
If the
.Fa type
argument does not have the bit
.Dv MBSTRING_FLAG
set and the
.Fa len argument
is not \-1, the
.Fa type
argument is expected to be one of the types documented in
.Xr ASN1_STRING_new 3
and
.Fa data
is expected to point to a buffer of
.Fa len
bytes.
In this case, a new object is allocated with
.Xr ASN1_STRING_type_new 3
and populated with
.Xr ASN1_STRING_set 3 .
.Pp
If the
.Fa type
argument does not have the bit
.Dv MBSTRING_FLAG
set and the
.Fa len argument
is \-1,
.Fa data
is expected to point to an object of the given
.Fa type
rather than to a buffer.
In this case, a deep copy of the existing object
into the new ASN.1 ANY object is performed with
.Xr ASN1_TYPE_set1 3 .
.Pp
If the
.Fa type
argument is 0, the
.Fa data
and
.Fa len
arguments are ignored and the set of values is left empty
instead of adding a single ASN.1 ANY object to it.
This violates section 8.2 of the X.501 standard, which requires
every attribute to contain at least one value, but some attribute
types used by the library use empty sets of values anyway.
.Pp
.Fn X509_ATTRIBUTE_create_by_OBJ
sets the type of
.Pf ** Fa attr
to
.Fa obj
using
.Fn X509_ATTRIBUTE_set1_object
and copies the
.Fa data
into it using
.Fn X509_ATTRIBUTE_set1_data .
If
.Fa attr
or
.Pf * Fa attr
is
.Dv NULL ,
a new
.Vt X509_ATTRIBUTE
object is allocated, populated, and returned.
.Pp
.Fn X509_ATTRIBUTE_create_by_NID
is a wrapper around
.Fn X509_ATTRIBUTE_create_by_OBJ
that obtains the required
.Fa obj
argument by calling
.Xr OBJ_nid2obj 3
on the
.Fa nid
argument.
.Pp
.Fn X509_ATTRIBUTE_create_by_txt
is a similar wrapper that obtains
.Fa obj
by calling
.Xr OBJ_txt2obj 3
with the arguments
.Fa name
and 0, which means that long names, short names, and numerical OID
strings are all acceptable.
.Sh RETURN VALUES
.Fn X509_ATTRIBUTE_set1_object
returns 1 if successful or 0 if
.Fa attr
or
.Fa obj
is
.Dv NULL
or if memory allocation fails.
.Pp
.Fn X509_ATTRIBUTE_set1_data
returns 1 if successful or 0 if
.Fa attr
is
.Dv NULL
or if
.Xr ASN1_STRING_set_by_NID 3 ,
.Xr ASN1_STRING_set 3 ,
.Xr ASN1_TYPE_set1 3 ,
or memory allocation fails.
.Pp
.Fn X509_ATTRIBUTE_create_by_OBJ ,
.Fn X509_ATTRIBUTE_create_by_NID ,
and
.Fn X509_ATTRIBUTE_create_by_txt
return a pointer to the changed or new object or
.Dv NULL
if obtaining
.Fa obj ,
allocating memory, or copying fails.
.Sh SEE ALSO
.Xr ASN1_OBJECT_new 3 ,
.Xr ASN1_STRING_new 3 ,
.Xr ASN1_STRING_set 3 ,
.Xr ASN1_STRING_set_by_NID 3 ,
.Xr ASN1_TYPE_new 3 ,
.Xr OBJ_nid2obj 3 ,
.Xr X509_ATTRIBUTE_get0_object 3 ,
.Xr X509_ATTRIBUTE_new 3
.Sh HISTORY
These functions first appeared in OpenSSL 0.9.5
and have been available since
.Ox 2.7 .
.Sh BUGS
If
.Fa attr
already contains one or more values,
.Fn X509_ATTRIBUTE_set1_data ,
.Fn X509_ATTRIBUTE_create_by_OBJ ,
.Fn X509_ATTRIBUTE_create_by_NID ,
and
.Fn X509_ATTRIBUTE_create_by_txt
silently overwrite the pointers to the old values
and leak the memory used for them.