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