X509_ATTRIBUTE.pod 12 KB

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