xref: /freebsd/crypto/openssl/doc/man3/X509_ATTRIBUTE.pod (revision e0c4386e7e71d93b0edc0c8fa156263fc4a8b0b6)
1*e0c4386eSCy Schubert=pod
2*e0c4386eSCy Schubert
3*e0c4386eSCy Schubert=head1 NAME
4*e0c4386eSCy Schubert
5*e0c4386eSCy SchubertX509_ATTRIBUTE, X509at_get_attr,
6*e0c4386eSCy SchubertX509at_get_attr_count, X509at_get_attr_by_NID, X509at_get_attr_by_OBJ,
7*e0c4386eSCy SchubertX509at_delete_attr,
8*e0c4386eSCy SchubertX509at_add1_attr,
9*e0c4386eSCy SchubertX509at_add1_attr_by_OBJ, X509at_add1_attr_by_NID, X509at_add1_attr_by_txt,
10*e0c4386eSCy SchubertX509at_get0_data_by_OBJ,
11*e0c4386eSCy SchubertX509_ATTRIBUTE_create, X509_ATTRIBUTE_create_by_NID,
12*e0c4386eSCy SchubertX509_ATTRIBUTE_create_by_OBJ, X509_ATTRIBUTE_create_by_txt,
13*e0c4386eSCy SchubertX509_ATTRIBUTE_set1_object, X509_ATTRIBUTE_set1_data,
14*e0c4386eSCy SchubertX509_ATTRIBUTE_count,
15*e0c4386eSCy SchubertX509_ATTRIBUTE_get0_data, X509_ATTRIBUTE_get0_object, X509_ATTRIBUTE_get0_type
16*e0c4386eSCy Schubert- X509 attribute functions
17*e0c4386eSCy Schubert
18*e0c4386eSCy Schubert=head1 SYNOPSIS
19*e0c4386eSCy Schubert
20*e0c4386eSCy Schubert #include <openssl/x509.h>
21*e0c4386eSCy Schubert
22*e0c4386eSCy Schubert typedef struct x509_attributes_st X509_ATTRIBUTE;
23*e0c4386eSCy Schubert
24*e0c4386eSCy Schubert int X509at_get_attr_count(const STACK_OF(X509_ATTRIBUTE) *x);
25*e0c4386eSCy Schubert int X509at_get_attr_by_NID(const STACK_OF(X509_ATTRIBUTE) *x, int nid,
26*e0c4386eSCy Schubert                            int lastpos);
27*e0c4386eSCy Schubert int X509at_get_attr_by_OBJ(const STACK_OF(X509_ATTRIBUTE) *sk,
28*e0c4386eSCy Schubert                            const ASN1_OBJECT *obj, int lastpos);
29*e0c4386eSCy Schubert X509_ATTRIBUTE *X509at_get_attr(const STACK_OF(X509_ATTRIBUTE) *x, int loc);
30*e0c4386eSCy Schubert X509_ATTRIBUTE *X509at_delete_attr(STACK_OF(X509_ATTRIBUTE) *x, int loc);
31*e0c4386eSCy Schubert STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr(STACK_OF(X509_ATTRIBUTE) **x,
32*e0c4386eSCy Schubert                                            X509_ATTRIBUTE *attr);
33*e0c4386eSCy Schubert STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_OBJ(STACK_OF(X509_ATTRIBUTE)
34*e0c4386eSCy Schubert                                                   **x, const ASN1_OBJECT *obj,
35*e0c4386eSCy Schubert                                                   int type,
36*e0c4386eSCy Schubert                                                   const unsigned char *bytes,
37*e0c4386eSCy Schubert                                                   int len);
38*e0c4386eSCy Schubert STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_NID(STACK_OF(X509_ATTRIBUTE)
39*e0c4386eSCy Schubert                                                   **x, int nid, int type,
40*e0c4386eSCy Schubert                                                   const unsigned char *bytes,
41*e0c4386eSCy Schubert                                                   int len);
42*e0c4386eSCy Schubert STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_txt(STACK_OF(X509_ATTRIBUTE)
43*e0c4386eSCy Schubert                                                   **x, const char *attrname,
44*e0c4386eSCy Schubert                                                   int type,
45*e0c4386eSCy Schubert                                                   const unsigned char *bytes,
46*e0c4386eSCy Schubert                                                   int len);
47*e0c4386eSCy Schubert void *X509at_get0_data_by_OBJ(const STACK_OF(X509_ATTRIBUTE) *x,
48*e0c4386eSCy Schubert                               const ASN1_OBJECT *obj, int lastpos, int type);
49*e0c4386eSCy Schubert X509_ATTRIBUTE *X509_ATTRIBUTE_create(int nid, int atrtype, void *value);
50*e0c4386eSCy Schubert X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_NID(X509_ATTRIBUTE **attr, int nid,
51*e0c4386eSCy Schubert                                              int atrtype, const void *data,
52*e0c4386eSCy Schubert                                              int len);
53*e0c4386eSCy Schubert X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_OBJ(X509_ATTRIBUTE **attr,
54*e0c4386eSCy Schubert                                              const ASN1_OBJECT *obj,
55*e0c4386eSCy Schubert                                              int atrtype, const void *data,
56*e0c4386eSCy Schubert                                              int len);
57*e0c4386eSCy Schubert X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_txt(X509_ATTRIBUTE **attr,
58*e0c4386eSCy Schubert                                              const char *atrname, int type,
59*e0c4386eSCy Schubert                                              const unsigned char *bytes,
60*e0c4386eSCy Schubert                                              int len);
61*e0c4386eSCy Schubert int X509_ATTRIBUTE_set1_object(X509_ATTRIBUTE *attr, const ASN1_OBJECT *obj);
62*e0c4386eSCy Schubert int X509_ATTRIBUTE_set1_data(X509_ATTRIBUTE *attr, int attrtype,
63*e0c4386eSCy Schubert                              const void *data, int len);
64*e0c4386eSCy Schubert void *X509_ATTRIBUTE_get0_data(X509_ATTRIBUTE *attr, int idx, int atrtype,
65*e0c4386eSCy Schubert                                void *data);
66*e0c4386eSCy Schubert int X509_ATTRIBUTE_count(const X509_ATTRIBUTE *attr);
67*e0c4386eSCy Schubert ASN1_OBJECT *X509_ATTRIBUTE_get0_object(X509_ATTRIBUTE *attr);
68*e0c4386eSCy Schubert ASN1_TYPE *X509_ATTRIBUTE_get0_type(X509_ATTRIBUTE *attr, int idx);
69*e0c4386eSCy Schubert
70*e0c4386eSCy Schubert=head1 DESCRIPTION
71*e0c4386eSCy Schubert
72*e0c4386eSCy SchubertB<X509_ATTRIBUTE> objects are used by many standards including X509, X509_REQ,
73*e0c4386eSCy SchubertPKCS12, PKCS8, PKCS7 and CMS.
74*e0c4386eSCy Schubert
75*e0c4386eSCy SchubertThe B<X509_ATTRIBUTE> object is used to represent the ASN.1 Attribute as defined
76*e0c4386eSCy Schubertin RFC 5280, i.e.
77*e0c4386eSCy Schubert
78*e0c4386eSCy Schubert Attribute ::= SEQUENCE {
79*e0c4386eSCy Schubert   type             AttributeType,
80*e0c4386eSCy Schubert   values    SET OF AttributeValue }
81*e0c4386eSCy Schubert
82*e0c4386eSCy Schubert AttributeType ::= OBJECT IDENTIFIER
83*e0c4386eSCy Schubert AttributeValue ::= ANY -- DEFINED BY AttributeType
84*e0c4386eSCy Schubert
85*e0c4386eSCy SchubertFor example CMS defines the signing-time attribute as:
86*e0c4386eSCy Schubert
87*e0c4386eSCy Schubert  id-signingTime OBJECT IDENTIFIER ::= { iso(1) member-body(2)
88*e0c4386eSCy Schubert      us(840) rsadsi(113549) pkcs(1) pkcs9(9) 5 }
89*e0c4386eSCy Schubert
90*e0c4386eSCy Schubert  SigningTime ::= Time
91*e0c4386eSCy Schubert
92*e0c4386eSCy Schubert  Time ::= CHOICE {
93*e0c4386eSCy Schubert    utcTime UTCTime,
94*e0c4386eSCy Schubert    generalizedTime GeneralizedTime }
95*e0c4386eSCy Schubert
96*e0c4386eSCy SchubertIn OpenSSL B<AttributeType> maps to an B<ASN1_OBJECT> object
97*e0c4386eSCy Schubertand B<AttributeValue> maps to a list of B<ASN1_TYPE> objects.
98*e0c4386eSCy Schubert
99*e0c4386eSCy SchubertThe following functions are used for B<X509_ATTRIBUTE> objects.
100*e0c4386eSCy Schubert
101*e0c4386eSCy SchubertX509at_get_attr_by_OBJ() finds the location of the first matching object I<obj>
102*e0c4386eSCy Schubertin a list of attributes I<sk>. The search starts at the position after I<lastpos>.
103*e0c4386eSCy SchubertIf the returned value is positive then it can be used on the next call to
104*e0c4386eSCy SchubertX509at_get_attr_by_OBJ() as the value of I<lastpos> in order to iterate through
105*e0c4386eSCy Schubertthe remaining attributes. I<lastpos> can be set to any negative value on the
106*e0c4386eSCy Schubertfirst call, in order to start searching from the start of the list.
107*e0c4386eSCy Schubert
108*e0c4386eSCy SchubertX509at_get_attr_by_NID() is similar to X509at_get_attr_by_OBJ() except that it
109*e0c4386eSCy Schubertpasses the numerical identifier (NID) I<nid> associated with the object.
110*e0c4386eSCy SchubertSee <openssl/obj_mac.h> for a list of NID_*.
111*e0c4386eSCy Schubert
112*e0c4386eSCy SchubertX509at_get_attr() returns the B<X509_ATTRIBUTE> object at index I<loc> in the
113*e0c4386eSCy Schubertlist of attributes I<x>. I<loc> should be in the range from 0 to
114*e0c4386eSCy SchubertX509at_get_attr_count() - 1.
115*e0c4386eSCy Schubert
116*e0c4386eSCy SchubertX509at_delete_attr() removes the B<X509_ATTRIBUTE> object at index I<loc> in
117*e0c4386eSCy Schubertthe list of attributes I<x>.
118*e0c4386eSCy Schubert
119*e0c4386eSCy SchubertX509at_add1_attr() pushes a copy of the passed in B<X509_ATTRIBUTE> object
120*e0c4386eSCy Schubertto the list I<x>.
121*e0c4386eSCy SchubertBoth I<x> and I<attr> must be non NULL or an error will occur.
122*e0c4386eSCy SchubertIf I<*x> is NULL then a new list is created, otherwise it uses the
123*e0c4386eSCy Schubertpassed in list. An error will occur if an existing attribute (with the same
124*e0c4386eSCy Schubertattribute type) already exists in the attribute list.
125*e0c4386eSCy Schubert
126*e0c4386eSCy SchubertX509at_add1_attr_by_OBJ() creates a new B<X509_ATTRIBUTE> using
127*e0c4386eSCy SchubertX509_ATTRIBUTE_set1_object() and X509_ATTRIBUTE_set1_data() to assign a new
128*e0c4386eSCy SchubertI<obj> with type I<type> and data I<bytes> of length I<len> and then pushes it
129*e0c4386eSCy Schubertto the attribute list I<x>. Both I<x> and I<attr> must be non NULL or an error
130*e0c4386eSCy Schubertwill occur. If I<*x> is NULL then a new attribute list is created. If I<obj>
131*e0c4386eSCy Schubertalready exists in the attribute list then an error occurs.
132*e0c4386eSCy Schubert
133*e0c4386eSCy SchubertX509at_add1_attr_by_NID() is similar to X509at_add1_attr_by_OBJ() except that it
134*e0c4386eSCy Schubertpasses the numerical identifier (NID) I<nid> associated with the object.
135*e0c4386eSCy SchubertSee <openssl/obj_mac.h> for a list of NID_*.
136*e0c4386eSCy Schubert
137*e0c4386eSCy SchubertX509at_add1_attr_by_txt() is similar to X509at_add1_attr_by_OBJ() except that it
138*e0c4386eSCy Schubertpasses a name I<attrname> associated with the object.
139*e0c4386eSCy SchubertSee <openssl/obj_mac.h> for a list of SN_* names.
140*e0c4386eSCy Schubert
141*e0c4386eSCy SchubertX509_ATTRIBUTE_set1_object() assigns a B<ASN1_OBJECT> I<obj>
142*e0c4386eSCy Schubertto the attribute I<attr>. If I<attr> contained an existing B<ASN1_OBJECT> then
143*e0c4386eSCy Schubertit is freed. An error occurs if either I<attr> or I<obj> are NULL, or if
144*e0c4386eSCy Schubertthe passed in I<obj> cannot be duplicated.
145*e0c4386eSCy Schubert
146*e0c4386eSCy SchubertX509_ATTRIBUTE_set1_data() pushes a new B<ASN1_TYPE> object onto the I<attr>
147*e0c4386eSCy Schubertattributes list. The new object is assigned a copy of the data in I<data> of
148*e0c4386eSCy Schubertsize I<len>.
149*e0c4386eSCy SchubertIf I<attrtype> has flag I<MBSTRING_FLAG> set then a table lookup using the
150*e0c4386eSCy SchubertI<attr> attributes NID is used to set an B<ASN1_STRING> using
151*e0c4386eSCy SchubertASN1_STRING_set_by_NID(), and the passed in I<data> must be in the format
152*e0c4386eSCy Schubertrequired for that object type or an error will occur.
153*e0c4386eSCy SchubertIf I<len> is not -1 then internally ASN1_STRING_type_new() is
154*e0c4386eSCy Schubertused with the passed in I<attrtype>.
155*e0c4386eSCy SchubertIf I<attrtype> is 0 the call does nothing except return 1.
156*e0c4386eSCy Schubert
157*e0c4386eSCy SchubertX509_ATTRIBUTE_create() creates a new B<X509_ATTRIBUTE> using the I<nid>
158*e0c4386eSCy Schubertto set the B<ASN1_OBJECT> OID and the I<atrtype> and I<value> to set the
159*e0c4386eSCy SchubertB<ASN1_TYPE>.
160*e0c4386eSCy Schubert
161*e0c4386eSCy SchubertX509_ATTRIBUTE_create_by_OBJ() uses X509_ATTRIBUTE_set1_object() and
162*e0c4386eSCy SchubertX509_ATTRIBUTE_set1_data() to assign a new I<obj> with type I<atrtype> and
163*e0c4386eSCy Schubertdata I<data> of length I<len>. If the passed in attribute I<attr> OR I<*attr> is
164*e0c4386eSCy SchubertNULL then a new B<X509_ATTRIBUTE> will be returned, otherwise the passed in
165*e0c4386eSCy SchubertB<X509_ATTRIBUTE> is used. Note that the ASN1_OBJECT I<obj> is pushed onto the
166*e0c4386eSCy Schubertattributes existing list of objects, which could be an issue if the attributes
167*e0c4386eSCy Schubert<ASN1_OBJECT> was different.
168*e0c4386eSCy Schubert
169*e0c4386eSCy SchubertX509_ATTRIBUTE_create_by_NID() is similar to X509_ATTRIBUTE_create_by_OBJ()
170*e0c4386eSCy Schubertexcept that it passes the numerical identifier (NID) I<nid> associated with the
171*e0c4386eSCy Schubertobject. See <openssl/obj_mac.h> for a list of NID_*.
172*e0c4386eSCy Schubert
173*e0c4386eSCy SchubertX509_ATTRIBUTE_create_by_txt() is similar to X509_ATTRIBUTE_create_by_OBJ()
174*e0c4386eSCy Schubertexcept that it passes a name I<atrname> associated with the
175*e0c4386eSCy Schubertobject. See <openssl/obj_mac.h> for a list of SN_* names.
176*e0c4386eSCy Schubert
177*e0c4386eSCy SchubertX509_ATTRIBUTE_count() returns the number of B<ASN1_TYPE> objects in an
178*e0c4386eSCy Schubertattribute I<attr>.
179*e0c4386eSCy Schubert
180*e0c4386eSCy SchubertX509_ATTRIBUTE_get0_type() returns the B<ASN1_TYPE> object at index I<idx> in
181*e0c4386eSCy Schubertthe attribute list I<attr>. I<idx> should be in the
182*e0c4386eSCy Schubertrange of 0 to X509_ATTRIBUTE_count() - 1 or an error will occur.
183*e0c4386eSCy Schubert
184*e0c4386eSCy SchubertX509_ATTRIBUTE_get0_data() returns the data of an B<ASN1_TYPE> object at
185*e0c4386eSCy Schubertindex I<idx> in the attribute I<attr>. I<data> is unused and can be set to NULL.
186*e0c4386eSCy SchubertAn error will occur if the attribute type I<atrtype> does not match the type of
187*e0c4386eSCy Schubertthe B<ASN1_TYPE> object at index I<idx> OR if I<atrtype> is either
188*e0c4386eSCy SchubertB<V_ASN1_BOOLEAN> or B<V_ASN1_NULL> OR if the I<idx> is not in the
189*e0c4386eSCy Schubertrange 0 to X509_ATTRIBUTE_count() - 1.
190*e0c4386eSCy Schubert
191*e0c4386eSCy SchubertX509at_get0_data_by_OBJ() finds the first attribute in an attribute list I<x>
192*e0c4386eSCy Schubertthat matches the I<obj> starting at index I<lastpos> and returns the data
193*e0c4386eSCy Schubertretrieved from the found attributes first B<ASN1_TYPE> object. An error will
194*e0c4386eSCy Schubertoccur if the attribute type I<type> does not match the type of the B<ASN1_TYPE>
195*e0c4386eSCy Schubertobject OR if I<type> is either B<V_ASN1_BOOLEAN> or B<V_ASN1_NULL> OR the
196*e0c4386eSCy Schubertattribute is not found.
197*e0c4386eSCy SchubertIf I<lastpos> is less than -1 then an error will occur if there are multiple
198*e0c4386eSCy Schubertobjects in the list I<x> that match I<obj>.
199*e0c4386eSCy SchubertIf I<lastpos> is less than -2 then an error will occur if there is more than
200*e0c4386eSCy Schubertone B<ASN1_TYPE> object in the found attribute.
201*e0c4386eSCy Schubert
202*e0c4386eSCy Schubert=head1 RETURN VALUES
203*e0c4386eSCy Schubert
204*e0c4386eSCy SchubertX509at_get_attr_count() returns the number of attributes in the list I<x> or -1
205*e0c4386eSCy Schubertif I<x> is NULL.
206*e0c4386eSCy Schubert
207*e0c4386eSCy SchubertX509at_get_attr_by_OBJ() returns -1 if either the list is empty OR the object
208*e0c4386eSCy Schubertis not found, otherwise it returns the location of the object in the list.
209*e0c4386eSCy Schubert
210*e0c4386eSCy SchubertX509at_get_attr_by_NID() is similar to X509at_get_attr_by_OBJ(), except that
211*e0c4386eSCy Schubertit returns -2 if the I<nid> is not known by OpenSSL.
212*e0c4386eSCy Schubert
213*e0c4386eSCy SchubertX509at_get_attr() returns either an B<X509_ATTRIBUTE> or NULL if there is a error.
214*e0c4386eSCy Schubert
215*e0c4386eSCy SchubertX509at_delete_attr() returns either the removed B<X509_ATTRIBUTE> or NULL if
216*e0c4386eSCy Schubertthere is a error.
217*e0c4386eSCy Schubert
218*e0c4386eSCy SchubertX509_ATTRIBUTE_count() returns -1 on error, otherwise it returns the number
219*e0c4386eSCy Schubertof B<ASN1_TYPE> elements.
220*e0c4386eSCy Schubert
221*e0c4386eSCy SchubertX509_ATTRIBUTE_get0_type() returns NULL on error, otherwise it returns a
222*e0c4386eSCy SchubertB<ASN1_TYPE> object.
223*e0c4386eSCy Schubert
224*e0c4386eSCy SchubertX509_ATTRIBUTE_get0_data() returns NULL if an error occurs,
225*e0c4386eSCy Schubertotherwise it returns the data associated with an B<ASN1_TYPE> object.
226*e0c4386eSCy Schubert
227*e0c4386eSCy SchubertX509_ATTRIBUTE_set1_object() and X509_ATTRIBUTE_set1_data() returns 1 on
228*e0c4386eSCy Schubertsuccess, or 0 otherwise.
229*e0c4386eSCy Schubert
230*e0c4386eSCy SchubertX509_ATTRIBUTE_create(), X509_ATTRIBUTE_create_by_OBJ(),
231*e0c4386eSCy SchubertX509_ATTRIBUTE_create_by_NID() and X509_ATTRIBUTE_create_by_txt() return either
232*e0c4386eSCy Schuberta B<X509_ATTRIBUTE> on success, or NULL if there is a error.
233*e0c4386eSCy Schubert
234*e0c4386eSCy SchubertX509at_add1_attr(), X509at_add1_attr_by_OBJ(), X509at_add1_attr_by_NID() and
235*e0c4386eSCy SchubertX509at_add1_attr_by_txt() return NULL on error, otherwise they return a list
236*e0c4386eSCy Schubertof B<X509_ATTRIBUTE>.
237*e0c4386eSCy Schubert
238*e0c4386eSCy SchubertX509at_get0_data_by_OBJ() returns the data retrieved from the found attributes
239*e0c4386eSCy Schubertfirst B<ASN1_TYPE> object, or NULL if an error occurs.
240*e0c4386eSCy Schubert
241*e0c4386eSCy Schubert=head1 SEE ALSO
242*e0c4386eSCy Schubert
243*e0c4386eSCy SchubertL<ASN1_TYPE_get(3)>,
244*e0c4386eSCy SchubertL<ASN1_INTEGER_get(3)>,
245*e0c4386eSCy SchubertL<ASN1_ENUMERATED_get(3)>,
246*e0c4386eSCy SchubertL<ASN1_STRING_get0_data(3)>,
247*e0c4386eSCy SchubertL<ASN1_STRING_length(3)>,
248*e0c4386eSCy SchubertL<ASN1_STRING_type(3)>,
249*e0c4386eSCy SchubertL<X509_REQ_get_attr(3)>,
250*e0c4386eSCy SchubertL<EVP_PKEY_get_attr(3)>,
251*e0c4386eSCy SchubertL<CMS_signed_get_attr(3)>,
252*e0c4386eSCy SchubertL<PKCS8_pkey_get0_attrs(3)>,
253*e0c4386eSCy Schubert
254*e0c4386eSCy Schubert=head1 COPYRIGHT
255*e0c4386eSCy Schubert
256*e0c4386eSCy SchubertCopyright 2023-2024 The OpenSSL Project Authors. All Rights Reserved.
257*e0c4386eSCy Schubert
258*e0c4386eSCy SchubertLicensed under the Apache License 2.0 (the "License").  You may not use
259*e0c4386eSCy Schubertthis file except in compliance with the License.  You can obtain a copy
260*e0c4386eSCy Schubertin the file LICENSE in the source distribution or at
261*e0c4386eSCy SchubertL<https://www.openssl.org/source/license.html>.
262*e0c4386eSCy Schubert
263*e0c4386eSCy Schubert=cut
264