1e71b7053SJung-uk Kim=pod 2e71b7053SJung-uk Kim 3e71b7053SJung-uk Kim=head1 NAME 4e71b7053SJung-uk Kim 5e71b7053SJung-uk KimCMS_get0_RecipientInfos, CMS_RecipientInfo_type, 6e71b7053SJung-uk KimCMS_RecipientInfo_ktri_get0_signer_id, CMS_RecipientInfo_ktri_cert_cmp, 7e71b7053SJung-uk KimCMS_RecipientInfo_set0_pkey, CMS_RecipientInfo_kekri_get0_id, 8*b077aed3SPierre ProncheryCMS_RecipientInfo_kari_set0_pkey_and_peer, 9*b077aed3SPierre ProncheryCMS_RecipientInfo_kari_set0_pkey, 10e71b7053SJung-uk KimCMS_RecipientInfo_kekri_id_cmp, CMS_RecipientInfo_set0_key, 11e71b7053SJung-uk KimCMS_RecipientInfo_decrypt, CMS_RecipientInfo_encrypt 12e71b7053SJung-uk Kim- CMS envelopedData RecipientInfo routines 13e71b7053SJung-uk Kim 14e71b7053SJung-uk Kim=head1 SYNOPSIS 15e71b7053SJung-uk Kim 16e71b7053SJung-uk Kim #include <openssl/cms.h> 17e71b7053SJung-uk Kim 18e71b7053SJung-uk Kim STACK_OF(CMS_RecipientInfo) *CMS_get0_RecipientInfos(CMS_ContentInfo *cms); 19e71b7053SJung-uk Kim int CMS_RecipientInfo_type(CMS_RecipientInfo *ri); 20e71b7053SJung-uk Kim 21e71b7053SJung-uk Kim int CMS_RecipientInfo_ktri_get0_signer_id(CMS_RecipientInfo *ri, 22e71b7053SJung-uk Kim ASN1_OCTET_STRING **keyid, 23e71b7053SJung-uk Kim X509_NAME **issuer, 24e71b7053SJung-uk Kim ASN1_INTEGER **sno); 25e71b7053SJung-uk Kim int CMS_RecipientInfo_ktri_cert_cmp(CMS_RecipientInfo *ri, X509 *cert); 26e71b7053SJung-uk Kim int CMS_RecipientInfo_set0_pkey(CMS_RecipientInfo *ri, EVP_PKEY *pkey); 27*b077aed3SPierre Pronchery int CMS_RecipientInfo_kari_set0_pkey_and_peer(CMS_RecipientInfo *ri, 28*b077aed3SPierre Pronchery EVP_PKEY *pk, X509 *peer); 29*b077aed3SPierre Pronchery int CMS_RecipientInfo_kari_set0_pkey(CMS_RecipientInfo *ri, EVP_PKEY *pk); 30e71b7053SJung-uk Kim int CMS_RecipientInfo_kekri_get0_id(CMS_RecipientInfo *ri, X509_ALGOR **palg, 31e71b7053SJung-uk Kim ASN1_OCTET_STRING **pid, 32e71b7053SJung-uk Kim ASN1_GENERALIZEDTIME **pdate, 33e71b7053SJung-uk Kim ASN1_OBJECT **potherid, 34e71b7053SJung-uk Kim ASN1_TYPE **pothertype); 35e71b7053SJung-uk Kim int CMS_RecipientInfo_kekri_id_cmp(CMS_RecipientInfo *ri, 36e71b7053SJung-uk Kim const unsigned char *id, size_t idlen); 37e71b7053SJung-uk Kim int CMS_RecipientInfo_set0_key(CMS_RecipientInfo *ri, 38e71b7053SJung-uk Kim unsigned char *key, size_t keylen); 39e71b7053SJung-uk Kim 40e71b7053SJung-uk Kim int CMS_RecipientInfo_decrypt(CMS_ContentInfo *cms, CMS_RecipientInfo *ri); 41e71b7053SJung-uk Kim int CMS_RecipientInfo_encrypt(CMS_ContentInfo *cms, CMS_RecipientInfo *ri); 42e71b7053SJung-uk Kim 43e71b7053SJung-uk Kim=head1 DESCRIPTION 44e71b7053SJung-uk Kim 45e71b7053SJung-uk KimThe function CMS_get0_RecipientInfos() returns all the CMS_RecipientInfo 46e71b7053SJung-uk Kimstructures associated with a CMS EnvelopedData structure. 47e71b7053SJung-uk Kim 48e71b7053SJung-uk KimCMS_RecipientInfo_type() returns the type of CMS_RecipientInfo structure B<ri>. 49e71b7053SJung-uk KimIt will currently return CMS_RECIPINFO_TRANS, CMS_RECIPINFO_AGREE, 50e71b7053SJung-uk KimCMS_RECIPINFO_KEK, CMS_RECIPINFO_PASS, or CMS_RECIPINFO_OTHER. 51e71b7053SJung-uk Kim 52e71b7053SJung-uk KimCMS_RecipientInfo_ktri_get0_signer_id() retrieves the certificate recipient 53e71b7053SJung-uk Kimidentifier associated with a specific CMS_RecipientInfo structure B<ri>, which 54e71b7053SJung-uk Kimmust be of type CMS_RECIPINFO_TRANS. Either the keyidentifier will be set in 55e71b7053SJung-uk KimB<keyid> or B<both> issuer name and serial number in B<issuer> and B<sno>. 56e71b7053SJung-uk Kim 57e71b7053SJung-uk KimCMS_RecipientInfo_ktri_cert_cmp() compares the certificate B<cert> against the 58e71b7053SJung-uk KimCMS_RecipientInfo structure B<ri>, which must be of type CMS_RECIPINFO_TRANS. 59e71b7053SJung-uk KimIt returns zero if the comparison is successful and non zero if not. 60e71b7053SJung-uk Kim 61e71b7053SJung-uk KimCMS_RecipientInfo_set0_pkey() associates the private key B<pkey> with 62e71b7053SJung-uk Kimthe CMS_RecipientInfo structure B<ri>, which must be of type 63e71b7053SJung-uk KimCMS_RECIPINFO_TRANS. 64e71b7053SJung-uk Kim 65*b077aed3SPierre ProncheryCMS_RecipientInfo_kari_set0_pkey_and_peer() associates the private key B<pkey> 66*b077aed3SPierre Proncheryand peer certificate B<peer> with the CMS_RecipientInfo structure B<ri>, which 67*b077aed3SPierre Proncherymust be of type CMS_RECIPINFO_AGREE. 68*b077aed3SPierre Pronchery 69*b077aed3SPierre ProncheryCMS_RecipientInfo_kari_set0_pkey() associates the private key B<pkey> with the 70*b077aed3SPierre ProncheryCMS_RecipientInfo structure B<ri>, which must be of type CMS_RECIPINFO_AGREE. 71*b077aed3SPierre Pronchery 72e71b7053SJung-uk KimCMS_RecipientInfo_kekri_get0_id() retrieves the key information from the 73e71b7053SJung-uk KimCMS_RecipientInfo structure B<ri> which must be of type CMS_RECIPINFO_KEK. Any 74e71b7053SJung-uk Kimof the remaining parameters can be NULL if the application is not interested in 75e71b7053SJung-uk Kimthe value of a field. Where a field is optional and absent NULL will be written 76e71b7053SJung-uk Kimto the corresponding parameter. The keyEncryptionAlgorithm field is written to 77e71b7053SJung-uk KimB<palg>, the B<keyIdentifier> field is written to B<pid>, the B<date> field if 78e71b7053SJung-uk Kimpresent is written to B<pdate>, if the B<other> field is present the components 79e71b7053SJung-uk KimB<keyAttrId> and B<keyAttr> are written to parameters B<potherid> and 80e71b7053SJung-uk KimB<pothertype>. 81e71b7053SJung-uk Kim 82e71b7053SJung-uk KimCMS_RecipientInfo_kekri_id_cmp() compares the ID in the B<id> and B<idlen> 83e71b7053SJung-uk Kimparameters against the B<keyIdentifier> CMS_RecipientInfo structure B<ri>, 84e71b7053SJung-uk Kimwhich must be of type CMS_RECIPINFO_KEK. It returns zero if the comparison is 85e71b7053SJung-uk Kimsuccessful and non zero if not. 86e71b7053SJung-uk Kim 87e71b7053SJung-uk KimCMS_RecipientInfo_set0_key() associates the symmetric key B<key> of length 88e71b7053SJung-uk KimB<keylen> with the CMS_RecipientInfo structure B<ri>, which must be of type 89e71b7053SJung-uk KimCMS_RECIPINFO_KEK. 90e71b7053SJung-uk Kim 91e71b7053SJung-uk KimCMS_RecipientInfo_decrypt() attempts to decrypt CMS_RecipientInfo structure 92e71b7053SJung-uk KimB<ri> in structure B<cms>. A key must have been associated with the structure 93e71b7053SJung-uk Kimfirst. 94e71b7053SJung-uk Kim 95e71b7053SJung-uk KimCMS_RecipientInfo_encrypt() attempts to encrypt CMS_RecipientInfo structure 96e71b7053SJung-uk KimB<ri> in structure B<cms>. A key must have been associated with the structure 97e71b7053SJung-uk Kimfirst and the content encryption key must be available: for example by a 98e71b7053SJung-uk Kimprevious call to CMS_RecipientInfo_decrypt(). 99e71b7053SJung-uk Kim 100e71b7053SJung-uk Kim=head1 NOTES 101e71b7053SJung-uk Kim 102e71b7053SJung-uk KimThe main purpose of these functions is to enable an application to lookup 103e71b7053SJung-uk Kimrecipient keys using any appropriate technique when the simpler method 104e71b7053SJung-uk Kimof CMS_decrypt() is not appropriate. 105e71b7053SJung-uk Kim 106e71b7053SJung-uk KimIn typical usage and application will retrieve all CMS_RecipientInfo structures 107e71b7053SJung-uk Kimusing CMS_get0_RecipientInfos() and check the type of each using 108e71b7053SJung-uk KimCMS_RecipientInfo_type(). Depending on the type the CMS_RecipientInfo structure 109e71b7053SJung-uk Kimcan be ignored or its key identifier data retrieved using an appropriate 110e71b7053SJung-uk Kimfunction. Then if the corresponding secret or private key can be obtained by 111e71b7053SJung-uk Kimany appropriate means it can then associated with the structure and 112e71b7053SJung-uk KimCMS_RecipientInfo_decrypt() called. If successful CMS_decrypt() can be called 113e71b7053SJung-uk Kimwith a NULL key to decrypt the enveloped content. 114e71b7053SJung-uk Kim 115e71b7053SJung-uk KimThe CMS_RecipientInfo_encrypt() can be used to add a new recipient to an 116e71b7053SJung-uk Kimexisting enveloped data structure. Typically an application will first decrypt 117e71b7053SJung-uk Kiman appropriate CMS_RecipientInfo structure to make the content encrypt key 118e71b7053SJung-uk Kimavailable, it will then add a new recipient using a function such as 119e71b7053SJung-uk KimCMS_add1_recipient_cert() and finally encrypt the content encryption key 120e71b7053SJung-uk Kimusing CMS_RecipientInfo_encrypt(). 121e71b7053SJung-uk Kim 122e71b7053SJung-uk Kim=head1 RETURN VALUES 123e71b7053SJung-uk Kim 124e71b7053SJung-uk KimCMS_get0_RecipientInfos() returns all CMS_RecipientInfo structures, or NULL if 125e71b7053SJung-uk Kiman error occurs. 126e71b7053SJung-uk Kim 127e71b7053SJung-uk KimCMS_RecipientInfo_ktri_get0_signer_id(), CMS_RecipientInfo_set0_pkey(), 128e71b7053SJung-uk KimCMS_RecipientInfo_kekri_get0_id(), CMS_RecipientInfo_set0_key() and 129e71b7053SJung-uk KimCMS_RecipientInfo_decrypt() return 1 for success or 0 if an error occurs. 130e71b7053SJung-uk KimCMS_RecipientInfo_encrypt() return 1 for success or 0 if an error occurs. 131e71b7053SJung-uk Kim 132e71b7053SJung-uk KimCMS_RecipientInfo_ktri_cert_cmp() and CMS_RecipientInfo_kekri_cmp() return 0 133e71b7053SJung-uk Kimfor a successful comparison and non zero otherwise. 134e71b7053SJung-uk Kim 135e71b7053SJung-uk KimAny error can be obtained from L<ERR_get_error(3)>. 136e71b7053SJung-uk Kim 137e71b7053SJung-uk Kim=head1 SEE ALSO 138e71b7053SJung-uk Kim 139e71b7053SJung-uk KimL<ERR_get_error(3)>, L<CMS_decrypt(3)> 140e71b7053SJung-uk Kim 141*b077aed3SPierre Pronchery=head1 HISTORY 142*b077aed3SPierre Pronchery 143*b077aed3SPierre ProncheryB<CMS_RecipientInfo_kari_set0_pkey_and_peer> and B<CMS_RecipientInfo_kari_set0_pkey> 144*b077aed3SPierre Proncherywere added in OpenSSL 3.0. 145*b077aed3SPierre Pronchery 146e71b7053SJung-uk Kim=head1 COPYRIGHT 147e71b7053SJung-uk Kim 148*b077aed3SPierre ProncheryCopyright 2008-2021 The OpenSSL Project Authors. All Rights Reserved. 149e71b7053SJung-uk Kim 150*b077aed3SPierre ProncheryLicensed under the Apache License 2.0 (the "License"). You may not use 151e71b7053SJung-uk Kimthis file except in compliance with the License. You can obtain a copy 152e71b7053SJung-uk Kimin the file LICENSE in the source distribution or at 153e71b7053SJung-uk KimL<https://www.openssl.org/source/license.html>. 154e71b7053SJung-uk Kim 155e71b7053SJung-uk Kim=cut 156