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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
|
.\" $OpenBSD: CMS_signed_add1_attr.3,v 1.1 2024/01/22 13:44:59 job Exp $
.\"
.\" Copyright (c) 2024 Job Snijders <job@openbsd.org>
.\" Copyright (c) 2024 Theo Buehler <tb@openbsd.org>
.\" 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: January 22 2024 $
.Dt CMS_SIGNED_ADD1_ATTR 3
.Os
.Sh NAME
.Nm CMS_signed_add1_attr ,
.Nm CMS_signed_add1_attr_by_NID ,
.Nm CMS_signed_add1_attr_by_OBJ ,
.Nm CMS_signed_add1_attr_by_txt ,
.Nm CMS_signed_delete_attr ,
.Nm CMS_signed_get0_data_by_OBJ ,
.Nm CMS_signed_get_attr ,
.Nm CMS_signed_get_attr_by_NID ,
.Nm CMS_signed_get_attr_by_OBJ ,
.Nm CMS_signed_get_attr_count ,
.Nm CMS_unsigned_add1_attr ,
.Nm CMS_unsigned_add1_attr_by_NID ,
.Nm CMS_unsigned_add1_attr_by_OBJ ,
.Nm CMS_unsigned_add1_attr_by_txt ,
.Nm CMS_unsigned_delete_attr ,
.Nm CMS_unsigned_get0_data_by_OBJ ,
.Nm CMS_unsigned_get_attr ,
.Nm CMS_unsigned_get_attr_by_NID ,
.Nm CMS_unsigned_get_attr_by_OBJ ,
.Nm CMS_unsigned_get_attr_count
.Nd change signed and unsigned attributes of a CMS SignerInfo object
.Sh SYNOPSIS
.In openssl/cms.h
.Ft int
.Fo CMS_signed_add1_attr
.Fa "CMS_SignerInfo *si"
.Fa "X509_ATTRIBUTE *attr"
.Fc
.Ft int
.Fo CMS_signed_add1_attr_by_NID
.Fa "CMS_SignerInfo *si"
.Fa "int nid"
.Fa "int type"
.Fa "const void *bytes"
.Fa "int len"
.Fc
.Ft int
.Fo CMS_signed_add1_attr_by_OBJ
.Fa "CMS_SignerInfo *si"
.Fa "const ASN1_OBJECT *obj"
.Fa "int type"
.Fa "const void *bytes"
.Fa "int len"
.Fc
.Ft int
.Fo CMS_signed_add1_attr_by_txt
.Fa "CMS_SignerInfo *si"
.Fa "const char *attrname"
.Fa "int type"
.Fa "const void *bytes"
.Fa "int len"
.Fc
.Ft "X509_ATTRIBUTE *"
.Fo CMS_signed_delete_attr
.Fa "CMS_SignerInfo *si"
.Fa "int loc"
.Fc
.Ft "void *"
.Fo CMS_signed_get0_data_by_OBJ
.Fa "CMS_SignerInfo *si"
.Fa "const ASN1_OBJECT *oid"
.Fa "int lastpos"
.Fa "int type"
.Fc
.Ft "X509_ATTRIBUTE *"
.Fo CMS_signed_get_attr
.Fa "const CMS_SignerInfo *si"
.Fa "int loc"
.Fc
.Ft int
.Fo CMS_signed_get_attr_by_NID
.Fa "const CMS_SignerInfo *si"
.Fa "int nid"
.Fa "int lastpos"
.Fc
.Ft int
.Fo CMS_signed_get_attr_by_OBJ
.Fa "const CMS_SignerInfo *si"
.Fa "const ASN1_OBJECT *obj"
.Fa "int lastpos"
.Fc
.Ft int
.Fo CMS_signed_get_attr_count
.Fa "const CMS_SignerInfo *si"
.Fc
.Ft int
.Fo CMS_unsigned_add1_attr
.Fa "CMS_SignerInfo *si"
.Fa "X509_ATTRIBUTE *attr"
.Fc
.Ft int
.Fo CMS_unsigned_add1_attr_by_NID
.Fa "CMS_SignerInfo *si"
.Fa "int nid"
.Fa "int type"
.Fa "const void *bytes"
.Fa "int len"
.Fc
.Ft int
.Fo CMS_unsigned_add1_attr_by_OBJ
.Fa "CMS_SignerInfo *si"
.Fa "const ASN1_OBJECT *obj"
.Fa "int type"
.Fa "const void *bytes"
.Fa "int len"
.Fc
.Ft int
.Fo CMS_unsigned_add1_attr_by_txt
.Fa "CMS_SignerInfo *si"
.Fa "const char *attrname"
.Fa "int type"
.Fa "const void *bytes"
.Fa "int len"
.Fc
.Ft "X509_ATTRIBUTE *"
.Fo CMS_unsigned_delete_attr
.Fa "CMS_SignerInfo *si"
.Fa "int loc"
.Fc
.Ft "void *"
.Fo CMS_unsigned_get0_data_by_OBJ
.Fa "CMS_SignerInfo *si"
.Fa "ASN1_OBJECT *oid"
.Fa "int lastpos"
.Fa "int type"
.Fc
.Ft "X509_ATTRIBUTE *"
.Fo CMS_unsigned_get_attr
.Fa "const CMS_SignerInfo *si"
.Fa "int loc"
.Fc
.Ft int
.Fo CMS_unsigned_get_attr_by_NID
.Fa "const CMS_SignerInfo *si"
.Fa "int nid"
.Fa "int lastpos"
.Fc
.Ft int
.Fo CMS_unsigned_get_attr_by_OBJ
.Fa "const CMS_SignerInfo *si"
.Fa "const ASN1_OBJECT *obj"
.Fa "int lastpos"
.Fc
.Ft int
.Fo CMS_unsigned_get_attr_count
.Fa "const CMS_SignerInfo *si"
.Fc
.Sh DESCRIPTION
A
.Em CMS_SignerInfo
object has two optional sets of X.501 attributes:
a set of signed attributes in the
.Fa signedAttrs
array and a set of unsigned attributes in the
.Fa unsignedAttrs
array.
The functions in this manual are wrappers of the
.Fn X509at_*
functions.
All arguments except
.Fa si
are passed to
.Fn X509at_* .
The
.Fn CMS_signed_*
and
.Fn CMS_unsigned_*
functions are similar, except
.Fn CMS_signed_*
calls
.Fn X509at_*
with the
.Em CMS_SignerInfo
object's set of signed attributes and
.Fn CMS_unsigned_*
calls
.Fn X509at_*
with the
.Em CMS_SignerInfo
object's set of unsigned attributes.
For brevity only the
.Fn CMS_signed_*
functions are described below.
.Pp
.Fn CMS_signed_add1_attr
appends a deep copy of
.Fa attr
to the
.Fa signedAttrs
array of
.Fa si ,
allocating a new array if necessary.
.Pp
.Fn CMS_signed_add1_attr_by_NID ,
.Fn CMS_signed_add1_attr_by_OBJ ,
and
.Fn CMS_signed_add1_attr_by_txt
create a new X.501 Attribute object using
.Xr X509at_add1_attr_by_NID 3 ,
.Xr X509at_add1_attr_by_OBJ 3 ,
and
.Xr X509at_add1_attr_by_txt 3 ,
and append it to the
.Fa signedAttrs
array of
.Fa si .
.Pp
.Fn CMS_signed_delete_attr
deletes the element with the zero-based
.Fa loc
in
.Fa signedAttrs
of
.Fa si .
.Pp
.Fn CMS_signed_get0_data_by_OBJ ,
.Fn CMS_signed_get_attr_by_NID ,
and
.Fn CMS_signed_get_attr_by_OBJ
search the array starting after the index
.Fa lastpos .
They fail if no matching object is found.
.Fn CMS_signed_get0_data_by_OBJ
also fails if the data is not of the requested
.Fa type .
.Pp
Additionally, the
.Fa lastpos
argument of
.Fn CMS_signed_get0_data_by_OBJ
is interpreted in a special way.
If
.Fa lastpos
is \-2 or smaller, the function also fails if the
.Fa signedAttrs
array of
.Fa si ,
contains more than one matching object.
If
.Fa lastpos
is \-3 or smaller, it also fails unless the matching object contains exactly
one value.
.Pp
.Fn CMS_signed_get_attr
returns the array element at the zero-based
.Fa loc .
It fails if the
.Fa loc
argument is negative or greater than or equal to the number of objects in the
array.
.Pp
.Fn CMS_signed_get_attr_count
returns the number of objects currently stored in the
.Fa signedAttrs
array of
.Fa si .
.Sh RETURN VALUES
.Fn CMS_signed_add1_attr ,
.Fn CMS_signed_add1_attr_by_NID ,
.Fn CMS_signed_add1_attr_by_OBJ ,
.Fn CMS_signed_add1_attr_by_txt ,
.Fn CMS_unsigned_add1_attr ,
.Fn CMS_unsigned_add1_attr_by_NID ,
.Fn CMS_unsigned_add1_attr_by_OBJ ,
and
.Fn CMS_unsigned_add1_attr_by_txt
return 1 for success or 0 if an error occurs.
.Pp
.Fn CMS_signed_delete_attr
returns the deleted element or
.Dv NULL
if the
.Fa signedAttrs
array is
.Dv NULL ,
or if the requested
.Fa loc
argument is negative, or greater than or equal to the number of objects in it.
.Pp
.Fn CMS_unsigned_delete_attr
returns the deleted element or
.Dv NULL
if the
.Fa unsignedAttrs
array is
.Dv NULL ,
or if the requested
.Fa loc
argument is negative, or greater than or equal to the number of objects in it.
.Pp
.Fn CMS_signed_get0_data_by_OBJ
and
.Fn CMS_unsigned_get0_data_by_OBJ
return an internal pointer to the data contained in the value of the first
object that has an index greater than
.Fa lastpos
and a type matching
.Fa type ,
or NULL on failure.
.Pp
.Fn CMS_signed_get_attr
and
.Fn CMS_unsigned_get_attr
return an internal pointer or NULL on failure.
.Pp
.Fn CMS_signed_get_attr_by_NID ,
.Fn CMS_signed_get_attr_by_OBJ ,
.Fn CMS_unsigned_get_attr_by_NID ,
and
.Fn CMS_unsigned_get_attr_by_OBJ
return the index of the first object in the array that has an index greater than
.Fa lastpos
and a type matching
.Fa nid
or
.Fa oid ,
respectively, or \-1 on failure.
In addition,
.Fn CMS_signed_get_attr_by_OBJ
and
.Fn CMS_unsigned_get_attr_by_OBJ
return \-2 if
.Xr OBJ_nid2obj 3
fails on the requested
.Fa nid .
.Pp
.Fn CMS_signed_get_attr_count
and
.Fn CMS_unsigned_get_attr_count
return the number of array elements or \-1 on failure.
.Sh SEE ALSO
.Xr CMS_add1_signer 3 ,
.Xr CMS_get0_SignerInfos 3 ,
.Xr OBJ_nid2obj 3 ,
.Xr X509_ATTRIBUTE_create_by_OBJ 3 ,
.Xr X509_ATTRIBUTE_new 3 ,
.Xr X509at_add1_attr 3
.Sh STANDARDS
RFC 5652: Cryptographic Message Syntax (CMS)
.Bl -dash -compact -offset indent
.It
section 5.3: SignerInfo Type
.It
section 11: Useful Attributes
.El
.Sh HISTORY
.Fn CMS_signed_add1_attr ,
.Fn CMS_signed_add1_attr_by_NID ,
.Fn CMS_signed_add1_attr_by_OBJ ,
.Fn CMS_signed_add1_attr_by_txt ,
.Fn CMS_signed_delete_attr ,
.Fn CMS_signed_get0_data_by_OBJ ,
.Fn CMS_signed_get_attr ,
.Fn CMS_signed_get_attr_by_NID ,
.Fn CMS_signed_get_attr_by_OBJ ,
.Fn CMS_signed_get_attr_count ,
.Fn CMS_unsigned_add1_attr ,
.Fn CMS_unsigned_add1_attr_by_NID ,
.Fn CMS_unsigned_add1_attr_by_OBJ ,
.Fn CMS_unsigned_add1_attr_by_txt ,
.Fn CMS_unsigned_delete_attr ,
.Fn CMS_unsigned_get0_data_by_OBJ ,
.Fn CMS_unsigned_get_attr ,
.Fn CMS_unsigned_get_attr_by_NID ,
.Fn CMS_unsigned_get_attr_by_OBJ
and
.Fn CMS_unsigned_get_attr_count
first appeared in OpenSSL 0.9.9 and have been available since
.Ox 6.6 .
|