1*e0c4386eSCy Schubert=pod 2*e0c4386eSCy Schubert 3*e0c4386eSCy Schubert=head1 NAME 4*e0c4386eSCy Schubert 5*e0c4386eSCy SchubertCMS_signed_get_attr_count, 6*e0c4386eSCy SchubertCMS_signed_get_attr_by_NID, CMS_signed_get_attr_by_OBJ, CMS_signed_get_attr, 7*e0c4386eSCy SchubertCMS_signed_delete_attr, 8*e0c4386eSCy SchubertCMS_signed_add1_attr, CMS_signed_add1_attr_by_OBJ, 9*e0c4386eSCy SchubertCMS_signed_add1_attr_by_NID, CMS_signed_add1_attr_by_txt, 10*e0c4386eSCy SchubertCMS_signed_get0_data_by_OBJ, 11*e0c4386eSCy SchubertCMS_unsigned_get_attr_count, 12*e0c4386eSCy SchubertCMS_unsigned_get_attr_by_NID, CMS_unsigned_get_attr_by_OBJ, 13*e0c4386eSCy SchubertCMS_unsigned_get_attr, CMS_unsigned_delete_attr, 14*e0c4386eSCy SchubertCMS_unsigned_add1_attr, CMS_unsigned_add1_attr_by_OBJ, 15*e0c4386eSCy SchubertCMS_unsigned_add1_attr_by_NID, CMS_unsigned_add1_attr_by_txt, 16*e0c4386eSCy SchubertCMS_unsigned_get0_data_by_OBJ 17*e0c4386eSCy Schubert- CMS signed and unsigned attribute functions 18*e0c4386eSCy Schubert 19*e0c4386eSCy Schubert=head1 SYNOPSIS 20*e0c4386eSCy Schubert 21*e0c4386eSCy Schubert #include <openssl/cms.h> 22*e0c4386eSCy Schubert 23*e0c4386eSCy Schubert int CMS_signed_get_attr_count(const CMS_SignerInfo *si); 24*e0c4386eSCy Schubert int CMS_signed_get_attr_by_NID(const CMS_SignerInfo *si, int nid, 25*e0c4386eSCy Schubert int lastpos); 26*e0c4386eSCy Schubert int CMS_signed_get_attr_by_OBJ(const CMS_SignerInfo *si, const ASN1_OBJECT *obj, 27*e0c4386eSCy Schubert int lastpos); 28*e0c4386eSCy Schubert X509_ATTRIBUTE *CMS_signed_get_attr(const CMS_SignerInfo *si, int loc); 29*e0c4386eSCy Schubert X509_ATTRIBUTE *CMS_signed_delete_attr(CMS_SignerInfo *si, int loc); 30*e0c4386eSCy Schubert int CMS_signed_add1_attr(CMS_SignerInfo *si, X509_ATTRIBUTE *attr); 31*e0c4386eSCy Schubert int CMS_signed_add1_attr_by_OBJ(CMS_SignerInfo *si, 32*e0c4386eSCy Schubert const ASN1_OBJECT *obj, int type, 33*e0c4386eSCy Schubert const void *bytes, int len); 34*e0c4386eSCy Schubert int CMS_signed_add1_attr_by_NID(CMS_SignerInfo *si, 35*e0c4386eSCy Schubert int nid, int type, 36*e0c4386eSCy Schubert const void *bytes, int len); 37*e0c4386eSCy Schubert int CMS_signed_add1_attr_by_txt(CMS_SignerInfo *si, 38*e0c4386eSCy Schubert const char *attrname, int type, 39*e0c4386eSCy Schubert const void *bytes, int len); 40*e0c4386eSCy Schubert void *CMS_signed_get0_data_by_OBJ(const CMS_SignerInfo *si, 41*e0c4386eSCy Schubert const ASN1_OBJECT *oid, 42*e0c4386eSCy Schubert int lastpos, int type); 43*e0c4386eSCy Schubert 44*e0c4386eSCy Schubert int CMS_unsigned_get_attr_count(const CMS_SignerInfo *si); 45*e0c4386eSCy Schubert int CMS_unsigned_get_attr_by_NID(const CMS_SignerInfo *si, int nid, 46*e0c4386eSCy Schubert int lastpos); 47*e0c4386eSCy Schubert int CMS_unsigned_get_attr_by_OBJ(const CMS_SignerInfo *si, 48*e0c4386eSCy Schubert const ASN1_OBJECT *obj, int lastpos); 49*e0c4386eSCy Schubert X509_ATTRIBUTE *CMS_unsigned_get_attr(const CMS_SignerInfo *si, int loc); 50*e0c4386eSCy Schubert X509_ATTRIBUTE *CMS_unsigned_delete_attr(CMS_SignerInfo *si, int loc); 51*e0c4386eSCy Schubert int CMS_unsigned_add1_attr(CMS_SignerInfo *si, X509_ATTRIBUTE *attr); 52*e0c4386eSCy Schubert int CMS_unsigned_add1_attr_by_OBJ(CMS_SignerInfo *si, 53*e0c4386eSCy Schubert const ASN1_OBJECT *obj, int type, 54*e0c4386eSCy Schubert const void *bytes, int len); 55*e0c4386eSCy Schubert int CMS_unsigned_add1_attr_by_NID(CMS_SignerInfo *si, 56*e0c4386eSCy Schubert int nid, int type, 57*e0c4386eSCy Schubert const void *bytes, int len); 58*e0c4386eSCy Schubert int CMS_unsigned_add1_attr_by_txt(CMS_SignerInfo *si, 59*e0c4386eSCy Schubert const char *attrname, int type, 60*e0c4386eSCy Schubert const void *bytes, int len); 61*e0c4386eSCy Schubert void *CMS_unsigned_get0_data_by_OBJ(CMS_SignerInfo *si, ASN1_OBJECT *oid, 62*e0c4386eSCy Schubert int lastpos, int type); 63*e0c4386eSCy Schubert 64*e0c4386eSCy Schubert=head1 DESCRIPTION 65*e0c4386eSCy Schubert 66*e0c4386eSCy SchubertCMS_signerInfo contains separate attribute lists for signed and unsigned 67*e0c4386eSCy Schubertattributes. Each CMS_signed_XXX() function is used for signed attributes, and 68*e0c4386eSCy Schuberteach CMS_unsigned_XXX() function is used for unsigned attributes. 69*e0c4386eSCy SchubertSince the CMS_unsigned_XXX() functions work in the same way as the 70*e0c4386eSCy SchubertCMS_signed_XXX() equivalents, only the CMS_signed_XXX() functions are 71*e0c4386eSCy Schubertdescribed below. 72*e0c4386eSCy Schubert 73*e0c4386eSCy SchubertCMS_signed_get_attr_by_OBJ() finds the location of the first matching object 74*e0c4386eSCy SchubertI<obj> in the SignerInfo's I<si> signed attribute list. The search starts at the 75*e0c4386eSCy Schubertposition after I<lastpos>. If the returned value is positive then it can be used 76*e0c4386eSCy Schuberton the next call to CMS_signed_get_attr_by_OBJ() as the value of I<lastpos> in 77*e0c4386eSCy Schubertorder to iterate through the remaining attributes. I<lastpos> can be set to any 78*e0c4386eSCy Schubertnegative value on the first call, in order to start searching from the start of 79*e0c4386eSCy Schubertthe signed attribute list. 80*e0c4386eSCy Schubert 81*e0c4386eSCy SchubertCMS_signed_get_attr_by_NID() is similar to CMS_signed_get_attr_by_OBJ() except 82*e0c4386eSCy Schubertthat it passes the numerical identifier (NID) I<nid> associated with the object. 83*e0c4386eSCy SchubertSee <openssl/obj_mac.h> for a list of NID_*. 84*e0c4386eSCy Schubert 85*e0c4386eSCy SchubertCMS_signed_get_attr() returns the B<X509_ATTRIBUTE> object at index I<loc> in the 86*e0c4386eSCy SchubertI<si> signed attribute list. I<loc> should be in the range from 0 to 87*e0c4386eSCy SchubertCMS_signed_get_attr_count() - 1. 88*e0c4386eSCy Schubert 89*e0c4386eSCy SchubertCMS_signed_delete_attr() removes the B<X509_ATTRIBUTE> object at index I<loc> in 90*e0c4386eSCy Schubertthe I<si> signed attribute list. An error occurs if the I<si> attribute list 91*e0c4386eSCy Schubertis NULL. 92*e0c4386eSCy Schubert 93*e0c4386eSCy SchubertCMS_signed_add1_attr() pushes a copy of the passed in B<X509_ATTRIBUTE> object 94*e0c4386eSCy Schubertto the I<si> signed attribute list. A new signed attribute list is created if 95*e0c4386eSCy Schubertrequired. An error occurs if I<attr> is NULL. 96*e0c4386eSCy Schubert 97*e0c4386eSCy SchubertCMS_signed_add1_attr_by_OBJ() creates a new signed B<X509_ATTRIBUTE> using 98*e0c4386eSCy SchubertX509_ATTRIBUTE_set1_object() and X509_ATTRIBUTE_set1_data() to assign a new 99*e0c4386eSCy SchubertI<obj> with type I<type> and data I<bytes> of length I<len> and then pushes it 100*e0c4386eSCy Schubertto the I<key> object's attribute list. 101*e0c4386eSCy Schubert 102*e0c4386eSCy SchubertCMS_signed_add1_attr_by_NID() is similar to CMS_signed_add1_attr_by_OBJ() except 103*e0c4386eSCy Schubertthat it passes the numerical identifier (NID) I<nid> associated with the object. 104*e0c4386eSCy SchubertSee <openssl/obj_mac.h> for a list of NID_*. 105*e0c4386eSCy Schubert 106*e0c4386eSCy SchubertCMS_signed_add1_attr_by_txt() is similar to CMS_signed_add1_attr_by_OBJ() 107*e0c4386eSCy Schubertexcept that it passes a name I<attrname> associated with the object. 108*e0c4386eSCy SchubertSee <openssl/obj_mac.h> for a list of SN_* names. 109*e0c4386eSCy Schubert 110*e0c4386eSCy SchubertCMS_signed_get0_data_by_OBJ() finds the first attribute in a I<si> signed 111*e0c4386eSCy Schubertattributes list that matches the I<obj> starting at index I<lastpos> 112*e0c4386eSCy Schubertand returns the data retrieved from the found attributes first B<ASN1_TYPE> 113*e0c4386eSCy Schubertobject. An error will occur if the attribute type I<type> does not match the 114*e0c4386eSCy Schuberttype of the B<ASN1_TYPE> object OR if I<type> is either B<V_ASN1_BOOLEAN> or 115*e0c4386eSCy SchubertB<V_ASN1_NULL> OR the attribute is not found. 116*e0c4386eSCy SchubertIf I<lastpos> is less than -1 then an error will occur if there are multiple 117*e0c4386eSCy Schubertobjects in the signed attribute list that match I<obj>. 118*e0c4386eSCy SchubertIf I<lastpos> is less than -2 then an error will occur if there is more than 119*e0c4386eSCy Schubertone B<ASN1_TYPE> object in the found signed attribute. 120*e0c4386eSCy Schubert 121*e0c4386eSCy SchubertRefer to L<X509_ATTRIBUTE(3)> for information related to attributes. 122*e0c4386eSCy Schubert 123*e0c4386eSCy Schubert=head1 RETURN VALUES 124*e0c4386eSCy Schubert 125*e0c4386eSCy SchubertThe CMS_unsigned_XXX() functions return values are similar to those of the 126*e0c4386eSCy Schubertequivalent CMS_signed_XXX() functions. 127*e0c4386eSCy Schubert 128*e0c4386eSCy SchubertCMS_signed_get_attr_count() returns the number of signed attributes in the 129*e0c4386eSCy SchubertSignerInfo I<si>, or -1 if the signed attribute list is NULL. 130*e0c4386eSCy Schubert 131*e0c4386eSCy SchubertCMS_signed_get_attr_by_OBJ() returns -1 if either the signed attribute list of 132*e0c4386eSCy SchubertI<si> is empty OR if I<obj> is not found, otherwise it returns the location of 133*e0c4386eSCy Schubertthe I<obj> in the SignerInfo's I<si> signed attribute list. 134*e0c4386eSCy Schubert 135*e0c4386eSCy SchubertCMS_signed_get_attr_by_NID() is similar to CMS_signed_get_attr_by_OBJ() except 136*e0c4386eSCy Schubertthat it returns -2 if the I<nid> is not known by OpenSSL. 137*e0c4386eSCy Schubert 138*e0c4386eSCy SchubertCMS_signed_get_attr() returns either a signed B<X509_ATTRIBUTE> or NULL on error. 139*e0c4386eSCy Schubert 140*e0c4386eSCy SchubertCMS_signed_delete_attr() returns either the removed signed B<X509_ATTRIBUTE> or 141*e0c4386eSCy SchubertNULL if there is a error. 142*e0c4386eSCy Schubert 143*e0c4386eSCy SchubertCMS_signed_add1_attr(), CMS_signed_add1_attr_by_OBJ(), 144*e0c4386eSCy SchubertCMS_signed_add1_attr_by_NID(), CMS_signed_add1_attr_by_txt(), 145*e0c4386eSCy Schubertreturn 1 on success or 0 on error. 146*e0c4386eSCy Schubert 147*e0c4386eSCy SchubertCMS_signed_get0_data_by_OBJ() returns the data retrieved from the found 148*e0c4386eSCy Schubertsigned attributes first B<ASN1_TYPE> object, or NULL if an error occurs. 149*e0c4386eSCy Schubert 150*e0c4386eSCy Schubert=head1 NOTES 151*e0c4386eSCy Schubert 152*e0c4386eSCy SchubertSome attributes are added automatically during the signing process. 153*e0c4386eSCy Schubert 154*e0c4386eSCy SchubertCalling CMS_SignerInfo_sign() adds the NID_pkcs9_signingTime signed 155*e0c4386eSCy Schubertattribute. 156*e0c4386eSCy Schubert 157*e0c4386eSCy SchubertCalling CMS_final(), CMS_final_digest() or CMS_dataFinal() adds the 158*e0c4386eSCy SchubertNID_pkcs9_messageDigest signed attribute. 159*e0c4386eSCy Schubert 160*e0c4386eSCy SchubertThe NID_pkcs9_contentType signed attribute is always added if the 161*e0c4386eSCy SchubertNID_pkcs9_signingTime attribute is added. 162*e0c4386eSCy Schubert 163*e0c4386eSCy SchubertCalling CMS_sign_ex(), CMS_sign_receipt() or CMS_add1_signer() may add 164*e0c4386eSCy Schubertattributes depending on the flags parameter. See L<CMS_add1_signer(3)> for 165*e0c4386eSCy Schubertmore information. 166*e0c4386eSCy Schubert 167*e0c4386eSCy SchubertOpenSSL applies special rules for the following attribute NIDs: 168*e0c4386eSCy Schubert 169*e0c4386eSCy Schubert=over 4 170*e0c4386eSCy Schubert 171*e0c4386eSCy Schubert=item CMS Signed Attributes 172*e0c4386eSCy Schubert 173*e0c4386eSCy SchubertNID_pkcs9_contentType 174*e0c4386eSCy SchubertNID_pkcs9_messageDigest 175*e0c4386eSCy SchubertNID_pkcs9_signingTime 176*e0c4386eSCy Schubert 177*e0c4386eSCy Schubert=item ESS Signed Attributes 178*e0c4386eSCy Schubert 179*e0c4386eSCy SchubertNID_id_smime_aa_signingCertificate 180*e0c4386eSCy SchubertNID_id_smime_aa_signingCertificateV2 181*e0c4386eSCy SchubertNID_id_smime_aa_receiptRequest 182*e0c4386eSCy Schubert 183*e0c4386eSCy Schubert=item CMS Unsigned Attributes 184*e0c4386eSCy Schubert 185*e0c4386eSCy SchubertNID_pkcs9_countersignature 186*e0c4386eSCy Schubert 187*e0c4386eSCy Schubert=back 188*e0c4386eSCy Schubert 189*e0c4386eSCy SchubertCMS_signed_add1_attr(), CMS_signed_add1_attr_by_OBJ(), 190*e0c4386eSCy SchubertCMS_signed_add1_attr_by_NID(), CMS_signed_add1_attr_by_txt() 191*e0c4386eSCy Schubertand the equivalent CMS_unsigned_add1_attrXXX() functions allow 192*e0c4386eSCy Schubertduplicate attributes to be added. The attribute rules are not checked 193*e0c4386eSCy Schubertduring these function calls, and are deferred until the sign or verify process 194*e0c4386eSCy Schubert(i.e. during calls to any of CMS_sign_ex(), CMS_sign(), CMS_sign_receipt(), 195*e0c4386eSCy SchubertCMS_add1_signer(), CMS_Final(), CMS_dataFinal(), CMS_final_digest(), 196*e0c4386eSCy SchubertCMS_verify(), CMS_verify_receipt() or CMS_SignedData_verify()). 197*e0c4386eSCy Schubert 198*e0c4386eSCy SchubertFor CMS attribute rules see RFC 5652 Section 11. 199*e0c4386eSCy SchubertFor ESS attribute rules see RFC 2634 Section 1.3.4 and RFC 5035 Section 5.4. 200*e0c4386eSCy Schubert 201*e0c4386eSCy Schubert=head1 SEE ALSO 202*e0c4386eSCy Schubert 203*e0c4386eSCy SchubertL<X509_ATTRIBUTE(3)> 204*e0c4386eSCy Schubert 205*e0c4386eSCy Schubert=head1 COPYRIGHT 206*e0c4386eSCy Schubert 207*e0c4386eSCy SchubertCopyright 2023-2024 The OpenSSL Project Authors. All Rights Reserved. 208*e0c4386eSCy Schubert 209*e0c4386eSCy SchubertLicensed under the Apache License 2.0 (the "License"). You may not use 210*e0c4386eSCy Schubertthis file except in compliance with the License. You can obtain a copy 211*e0c4386eSCy Schubertin the file LICENSE in the source distribution or at 212*e0c4386eSCy SchubertL<https://www.openssl.org/source/license.html>. 213*e0c4386eSCy Schubert 214*e0c4386eSCy Schubert=cut 215