CMS_signed_get_attr.pod 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. =pod
  2. =head1 NAME
  3. CMS_signed_get_attr_count,
  4. CMS_signed_get_attr_by_NID, CMS_signed_get_attr_by_OBJ, CMS_signed_get_attr,
  5. CMS_signed_delete_attr,
  6. CMS_signed_add1_attr, CMS_signed_add1_attr_by_OBJ,
  7. CMS_signed_add1_attr_by_NID, CMS_signed_add1_attr_by_txt,
  8. CMS_signed_get0_data_by_OBJ,
  9. CMS_unsigned_get_attr_count,
  10. CMS_unsigned_get_attr_by_NID, CMS_unsigned_get_attr_by_OBJ,
  11. CMS_unsigned_get_attr, CMS_unsigned_delete_attr,
  12. CMS_unsigned_add1_attr, CMS_unsigned_add1_attr_by_OBJ,
  13. CMS_unsigned_add1_attr_by_NID, CMS_unsigned_add1_attr_by_txt,
  14. CMS_unsigned_get0_data_by_OBJ
  15. - CMS signed and unsigned attribute functions
  16. =head1 SYNOPSIS
  17. #include <openssl/cms.h>
  18. int CMS_signed_get_attr_count(const CMS_SignerInfo *si);
  19. int CMS_signed_get_attr_by_NID(const CMS_SignerInfo *si, int nid,
  20. int lastpos);
  21. int CMS_signed_get_attr_by_OBJ(const CMS_SignerInfo *si, const ASN1_OBJECT *obj,
  22. int lastpos);
  23. X509_ATTRIBUTE *CMS_signed_get_attr(const CMS_SignerInfo *si, int loc);
  24. X509_ATTRIBUTE *CMS_signed_delete_attr(CMS_SignerInfo *si, int loc);
  25. int CMS_signed_add1_attr(CMS_SignerInfo *si, X509_ATTRIBUTE *attr);
  26. int CMS_signed_add1_attr_by_OBJ(CMS_SignerInfo *si,
  27. const ASN1_OBJECT *obj, int type,
  28. const void *bytes, int len);
  29. int CMS_signed_add1_attr_by_NID(CMS_SignerInfo *si,
  30. int nid, int type,
  31. const void *bytes, int len);
  32. int CMS_signed_add1_attr_by_txt(CMS_SignerInfo *si,
  33. const char *attrname, int type,
  34. const void *bytes, int len);
  35. void *CMS_signed_get0_data_by_OBJ(const CMS_SignerInfo *si,
  36. const ASN1_OBJECT *oid,
  37. int lastpos, int type);
  38. int CMS_unsigned_get_attr_count(const CMS_SignerInfo *si);
  39. int CMS_unsigned_get_attr_by_NID(const CMS_SignerInfo *si, int nid,
  40. int lastpos);
  41. int CMS_unsigned_get_attr_by_OBJ(const CMS_SignerInfo *si,
  42. const ASN1_OBJECT *obj, int lastpos);
  43. X509_ATTRIBUTE *CMS_unsigned_get_attr(const CMS_SignerInfo *si, int loc);
  44. X509_ATTRIBUTE *CMS_unsigned_delete_attr(CMS_SignerInfo *si, int loc);
  45. int CMS_unsigned_add1_attr(CMS_SignerInfo *si, X509_ATTRIBUTE *attr);
  46. int CMS_unsigned_add1_attr_by_OBJ(CMS_SignerInfo *si,
  47. const ASN1_OBJECT *obj, int type,
  48. const void *bytes, int len);
  49. int CMS_unsigned_add1_attr_by_NID(CMS_SignerInfo *si,
  50. int nid, int type,
  51. const void *bytes, int len);
  52. int CMS_unsigned_add1_attr_by_txt(CMS_SignerInfo *si,
  53. const char *attrname, int type,
  54. const void *bytes, int len);
  55. void *CMS_unsigned_get0_data_by_OBJ(CMS_SignerInfo *si, ASN1_OBJECT *oid,
  56. int lastpos, int type);
  57. =head1 DESCRIPTION
  58. CMS_signerInfo contains separate attribute lists for signed and unsigned
  59. attributes. Each CMS_signed_XXX() function is used for signed attributes, and
  60. each CMS_unsigned_XXX() function is used for unsigned attributes.
  61. Since the CMS_unsigned_XXX() functions work in the same way as the
  62. CMS_signed_XXX() equivalents, only the CMS_signed_XXX() functions are
  63. described below.
  64. CMS_signed_get_attr_by_OBJ() finds the location of the first matching object
  65. I<obj> in the SignerInfo's I<si> signed attribute list. The search starts at the
  66. position after I<lastpos>. If the returned value is positive then it can be used
  67. on the next call to CMS_signed_get_attr_by_OBJ() as the value of I<lastpos> in
  68. order to iterate through the remaining attributes. I<lastpos> can be set to any
  69. negative value on the first call, in order to start searching from the start of
  70. the signed attribute list.
  71. CMS_signed_get_attr_by_NID() is similar to CMS_signed_get_attr_by_OBJ() except
  72. that it passes the numerical identifier (NID) I<nid> associated with the object.
  73. See <openssl/obj_mac.h> for a list of NID_*.
  74. CMS_signed_get_attr() returns the B<X509_ATTRIBUTE> object at index I<loc> in the
  75. I<si> signed attribute list. I<loc> should be in the range from 0 to
  76. CMS_signed_get_attr_count() - 1.
  77. CMS_signed_delete_attr() removes the B<X509_ATTRIBUTE> object at index I<loc> in
  78. the I<si> signed attribute list. An error occurs if the I<si> attribute list
  79. is NULL.
  80. CMS_signed_add1_attr() pushes a copy of the passed in B<X509_ATTRIBUTE> object
  81. to the I<si> signed attribute list. A new signed attribute list is created if
  82. required. An error occurs if I<attr> is NULL.
  83. CMS_signed_add1_attr_by_OBJ() creates a new signed B<X509_ATTRIBUTE> using
  84. X509_ATTRIBUTE_set1_object() and X509_ATTRIBUTE_set1_data() to assign a new
  85. I<obj> with type I<type> and data I<bytes> of length I<len> and then pushes it
  86. to the I<key> object's attribute list.
  87. CMS_signed_add1_attr_by_NID() is similar to CMS_signed_add1_attr_by_OBJ() except
  88. that it passes the numerical identifier (NID) I<nid> associated with the object.
  89. See <openssl/obj_mac.h> for a list of NID_*.
  90. CMS_signed_add1_attr_by_txt() is similar to CMS_signed_add1_attr_by_OBJ()
  91. except that it passes a name I<attrname> associated with the object.
  92. See <openssl/obj_mac.h> for a list of SN_* names.
  93. CMS_signed_get0_data_by_OBJ() finds the first attribute in a I<si> signed
  94. attributes list that matches the I<obj> starting at index I<lastpos>
  95. and returns the data retrieved from the found attributes first B<ASN1_TYPE>
  96. object. An error will occur if the attribute type I<type> does not match the
  97. type of the B<ASN1_TYPE> object OR if I<type> is either B<V_ASN1_BOOLEAN> or
  98. B<V_ASN1_NULL> OR the attribute is not found.
  99. If I<lastpos> is less than -1 then an error will occur if there are multiple
  100. objects in the signed attribute list that match I<obj>.
  101. If I<lastpos> is less than -2 then an error will occur if there is more than
  102. one B<ASN1_TYPE> object in the found signed attribute.
  103. Refer to L<X509_ATTRIBUTE(3)> for information related to attributes.
  104. =head1 RETURN VALUES
  105. The CMS_unsigned_XXX() functions return values are similar to those of the
  106. equivalent CMS_signed_XXX() functions.
  107. CMS_signed_get_attr_count() returns the number of signed attributes in the
  108. SignerInfo I<si>, or -1 if the signed attribute list is NULL.
  109. CMS_signed_get_attr_by_OBJ() returns -1 if either the signed attribute list of
  110. I<si> is empty OR if I<obj> is not found, otherwise it returns the location of
  111. the I<obj> in the SignerInfo's I<si> signed attribute list.
  112. CMS_signed_get_attr_by_NID() is similar to CMS_signed_get_attr_by_OBJ() except
  113. that it returns -2 if the I<nid> is not known by OpenSSL.
  114. CMS_signed_get_attr() returns either a signed B<X509_ATTRIBUTE> or NULL on error.
  115. CMS_signed_delete_attr() returns either the removed signed B<X509_ATTRIBUTE> or
  116. NULL if there is a error.
  117. CMS_signed_add1_attr(), CMS_signed_add1_attr_by_OBJ(),
  118. CMS_signed_add1_attr_by_NID(), CMS_signed_add1_attr_by_txt(),
  119. return 1 on success or 0 on error.
  120. CMS_signed_get0_data_by_OBJ() returns the data retrieved from the found
  121. signed attributes first B<ASN1_TYPE> object, or NULL if an error occurs.
  122. =head1 NOTES
  123. Some attributes are added automatically during the signing process.
  124. Calling CMS_SignerInfo_sign() adds the NID_pkcs9_signingTime signed
  125. attribute.
  126. Calling CMS_final(), CMS_final_digest() or CMS_dataFinal() adds the
  127. NID_pkcs9_messageDigest signed attribute.
  128. The NID_pkcs9_contentType signed attribute is always added if the
  129. NID_pkcs9_signingTime attribute is added.
  130. Calling CMS_sign_ex(), CMS_sign_receipt() or CMS_add1_signer() may add
  131. attributes depending on the flags parameter. See L<CMS_add1_signer(3)> for
  132. more information.
  133. OpenSSL applies special rules for the following attribute NIDs:
  134. =over 4
  135. =item CMS Signed Attributes
  136. NID_pkcs9_contentType
  137. NID_pkcs9_messageDigest
  138. NID_pkcs9_signingTime
  139. =item ESS Signed Attributes
  140. NID_id_smime_aa_signingCertificate
  141. NID_id_smime_aa_signingCertificateV2
  142. NID_id_smime_aa_receiptRequest
  143. =item CMS Unsigned Attributes
  144. NID_pkcs9_countersignature
  145. =back
  146. CMS_signed_add1_attr(), CMS_signed_add1_attr_by_OBJ(),
  147. CMS_signed_add1_attr_by_NID(), CMS_signed_add1_attr_by_txt()
  148. and the equivalent CMS_unsigned_add1_attrXXX() functions allow
  149. duplicate attributes to be added. The attribute rules are not checked
  150. during these function calls, and are deferred until the sign or verify process
  151. (i.e. during calls to any of CMS_sign_ex(), CMS_sign(), CMS_sign_receipt(),
  152. CMS_add1_signer(), CMS_Final(), CMS_dataFinal(), CMS_final_digest(),
  153. CMS_verify(), CMS_verify_receipt() or CMS_SignedData_verify()).
  154. For CMS attribute rules see RFC 5652 Section 11.
  155. For ESS attribute rules see RFC 2634 Section 1.3.4 and RFC 5035 Section 5.4.
  156. =head1 SEE ALSO
  157. L<X509_ATTRIBUTE(3)>
  158. =head1 COPYRIGHT
  159. Copyright 2023-2024 The OpenSSL Project Authors. All Rights Reserved.
  160. Licensed under the Apache License 2.0 (the "License"). You may not use
  161. this file except in compliance with the License. You can obtain a copy
  162. in the file LICENSE in the source distribution or at
  163. L<https://www.openssl.org/source/license.html>.
  164. =cut