CMS_GET0_RECIPIENTINFOS(3SSL)
π NAME π
okay bestie, welcome to the CMS_GET0_RECIPIENTINFOS(3SSL) page, aka the OpenSSL girlies' guide to CMS envelopedData RecipientInfo routines π
This is the whole squad, no one left behind:
CMS_get0_RecipientInfosCMS_RecipientInfo_typeCMS_RecipientInfo_ktri_get0_signer_idCMS_RecipientInfo_ktri_cert_cmpCMS_RecipientInfo_set0_pkeyCMS_RecipientInfo_kekri_get0_idCMS_RecipientInfo_kari_set0_pkey_and_peerCMS_RecipientInfo_kari_set0_pkeyCMS_RecipientInfo_kari_get0_ctxCMS_RecipientInfo_kekri_id_cmpCMS_RecipientInfo_set0_keyCMS_RecipientInfo_kemri_cert_cmpCMS_RecipientInfo_kemri_set0_pkeyCMS_RecipientInfo_kemri_get0_ctxCMS_RecipientInfo_kemri_get0_kdf_algCMS_RecipientInfo_kemri_set_ukmCMS_RecipientInfo_decryptCMS_RecipientInfo_encrypt
β¨ SYNOPSIS β¨
#include <openssl/cms.h>
STACK_OF(CMS_RecipientInfo) *CMS_get0_RecipientInfos(CMS_ContentInfo *cms);
int CMS_RecipientInfo_type(CMS_RecipientInfo *ri);
int CMS_RecipientInfo_ktri_get0_signer_id(CMS_RecipientInfo *ri,
ASN1_OCTET_STRING **keyid,
X509_NAME **issuer,
ASN1_INTEGER **sno);
int CMS_RecipientInfo_ktri_cert_cmp(CMS_RecipientInfo *ri, X509 *cert);
int CMS_RecipientInfo_set0_pkey(CMS_RecipientInfo *ri, EVP_PKEY *pkey);
int CMS_RecipientInfo_kari_set0_pkey_and_peer(CMS_RecipientInfo *ri,
EVP_PKEY *pk, X509 *peer);
int CMS_RecipientInfo_kari_set0_pkey(CMS_RecipientInfo *ri, EVP_PKEY *pk);
EVP_CIPHER_CTX *CMS_RecipientInfo_kari_get0_ctx(CMS_RecipientInfo *ri);
int CMS_RecipientInfo_kekri_get0_id(CMS_RecipientInfo *ri, X509_ALGOR **palg,
ASN1_OCTET_STRING **pid,
ASN1_GENERALIZEDTIME **pdate,
ASN1_OBJECT **potherid,
ASN1_TYPE **pothertype);
int CMS_RecipientInfo_kekri_id_cmp(CMS_RecipientInfo *ri,
const unsigned char *id, size_t idlen);
int CMS_RecipientInfo_set0_key(CMS_RecipientInfo *ri,
unsigned char *key, size_t keylen);
int CMS_RecipientInfo_kemri_cert_cmp(CMS_RecipientInfo *ri, X509 *cert);
int CMS_RecipientInfo_kemri_set0_pkey(CMS_RecipientInfo *ri, EVP_PKEY *pk);
EVP_CIPHER_CTX *CMS_RecipientInfo_kemri_get0_ctx(CMS_RecipientInfo *ri);
X509_ALGOR *CMS_RecipientInfo_kemri_get0_kdf_alg(CMS_RecipientInfo *ri);
int CMS_RecipientInfo_kemri_set_ukm(CMS_RecipientInfo *ri,
const unsigned char *ukm,
int ukmLength);
int CMS_RecipientInfo_decrypt(CMS_ContentInfo *cms, CMS_RecipientInfo *ri);
int CMS_RecipientInfo_encrypt(CMS_ContentInfo *cms, CMS_RecipientInfo *ri);
π DESCRIPTION π
so basically every single one of these is about poking at one recipient inside an EnvelopedData situation, and here's the tea on each π΅
CMS_get0_RecipientInfos()β hands you back all theCMS_RecipientInfostructures that are chillin' inside aCMS EnvelopedDatastructure. the whole group chat, fr fr.CMS_RecipientInfo_type()β tells you what kind ofCMS_RecipientInfostructureriis. and right now it can returnCMS_RECIPINFO_TRANS,CMS_RECIPINFO_AGREE,CMS_RECIPINFO_KEK,CMS_RECIPINFO_PASS,CMS_RECIPINFO_KEM, orCMS_RECIPINFO_OTHER. pick your fighter πCMS_RecipientInfo_ktri_get0_signer_id()β grabs the certificate recipient identifier that belongs to a specificCMS_RecipientInfostructureri, andrihas got to be of typeCMS_RECIPINFO_TRANS. either the key identifier gets set inkeyid, or both the issuer name and serial number get set inissuerandsno. choose your own adventure.CMS_RecipientInfo_ktri_cert_cmp()β compares the certificatecertagainst theCMS_RecipientInfostructureri, which must be of typeCMS_RECIPINFO_TRANS. it returns zero if the comparison slayed (success π) and non zero if not.CMS_RecipientInfo_set0_pkey()β associates the private keypkeywith theCMS_RecipientInfostructureri, andrimust be of typeCMS_RECIPINFO_TRANS. it's giving matchmaker energy π«ΆCMS_RecipientInfo_kari_set0_pkey_and_peer()β associates the private keypkeyand the peer certificatepeerwith theCMS_RecipientInfostructureri, which must be of typeCMS_RECIPINFO_AGREE. plus one, literally.CMS_RecipientInfo_kari_set0_pkey()β associates the private keypkeywith theCMS_RecipientInfostructureri, which must be of typeCMS_RECIPINFO_AGREE.CMS_RecipientInfo_kari_get0_ctx()β returns theEVP_CIPHER_CTXfor the key encryption key, which lets the caller specify the key wrap cipher. theCMS_RecipientInfostructurerimust be of typeCMS_RECIPINFO_AGREE. yes bestie you get to pick the fit π₯CMS_RecipientInfo_kekri_get0_id()β retrieves the key information from theCMS_RecipientInfostructureri, which must be of typeCMS_RECIPINFO_KEK. any of the remaining parameters can beNULLif the application isn't interested in the value of a field. where a field is optional and absent,NULLwill be written to the corresponding parameter. thekeyEncryptionAlgorithmfield gets written topalg, thekeyIdentifierfield gets written topid, thedatefield (if present) gets written topdate, and if theotherfield is present the componentskeyAttrIdandkeyAttrget written to the parameterspotheridandpothertype. whew, that's a lot of slots but we're filling them all correctly πCMS_RecipientInfo_kekri_id_cmp()β compares the ID in theidandidlenparameters against thekeyIdentifierCMS_RecipientInfostructureri, which must be of typeCMS_RECIPINFO_KEK. it returns zero if the comparison succeeded and non zero if not.CMS_RecipientInfo_set0_key()β associates the symmetric keykeyof lengthkeylenwith theCMS_RecipientInfostructureri, which must be of typeCMS_RECIPINFO_KEK.CMS_RecipientInfo_kemri_cert_cmp()β compares the certificatecertagainst theCMS_RecipientInfostructureri, which must be of typeCMS_RECIPINFO_KEM. returns zero if the comparison worked out and non zero if not. we love a successful compare πCMS_RecipientInfo_kemri_set0_pkey()β associates the private keypkeywith theCMS_RecipientInfostructureri, which must be of typeCMS_RECIPINFO_KEM.CMS_RecipientInfo_kemri_get0_ctx()β returns theEVP_CIPHER_CTXfor the key encryption key, so the caller can specify the key wrap cipher. theCMS_RecipientInfostructurerimust be of typeCMS_RECIPINFO_KEM.CMS_RecipientInfo_kemri_get0_kdf_alg()β returns theX509_ALGORfor the RecipientInfo's KDF, letting the caller specify the KDF algorithm. theCMS_RecipientInfostructurerimust be of typeCMS_RECIPINFO_KEM. and bestie, if the caller doesn't specify a KDF algorithm,HKDF-SHA256will be used. it's the default for a reason β¨CMS_RecipientInfo_kemri_set_ukm()β sets the RecipientInfo's optional user keying material (UKM). the UKM gets encoded, along with other information, into theOSSL_KDF_PARAM_INFOparameter of the RecipientInfo's KDF. theCMS_RecipientInfostructurerimust be of typeCMS_RECIPINFO_KEM.CMS_RecipientInfo_decrypt()β attempts to decrypt theCMS_RecipientInfostructureriin the structurecms. a key must have been associated with the structure first. no key, no decrypt, periodt.CMS_RecipientInfo_encrypt()β attempts to encrypt theCMS_RecipientInfostructureriin the structurecms. a key must have been associated with the structure first, and the content encryption key must be available: for example by a previous call toCMS_RecipientInfo_decrypt(). both ingredients or it's not happening π§
πΈ NOTES πΈ
the main purpose of all these functions is to let an application look up recipient keys using any appropriate technique, for those times when the simpler method of CMS_decrypt() just isn't appropriate. sometimes the simple route isn't the vibe, yk?
in typical usage an application will retrieve all the CMS_RecipientInfo structures using CMS_get0_RecipientInfos() and then check the type of each one using CMS_RecipientInfo_type(). depending on the type, the CMS_RecipientInfo structure can either be ignored or have its key identifier data retrieved using an appropriate function. then, if the corresponding secret or private key can be obtained by any appropriate means, it can be associated with the structure and CMS_RecipientInfo_decrypt() called. if that popped off, CMS_decrypt() can be called with a NULL key to decrypt the enveloped content. iconic workflow honestly π
CMS_RecipientInfo_encrypt() can be used to add a new recipient to an existing enveloped data structure. typically an application will first decrypt an appropriate CMS_RecipientInfo structure to make the content encryption key available, then it'll add a new recipient using a function such as CMS_add1_recipient_cert(), and finally encrypt the content encryption key using CMS_RecipientInfo_encrypt(). add a friend to the gc, but make it cryptographic π
β RETURN VALUES β
CMS_get0_RecipientInfos()β returns allCMS_RecipientInfostructures, orNULLif an error occurs. πCMS_RecipientInfo_ktri_get0_signer_id(),CMS_RecipientInfo_set0_pkey(),CMS_RecipientInfo_kekri_get0_id(),CMS_RecipientInfo_set0_key(),CMS_RecipientInfo_kemri_set0_pkey(),CMS_RecipientInfo_kemri_set_ukm(),CMS_RecipientInfo_decrypt()andCMS_RecipientInfo_encrypt()β return1for success or0if an error occurs.CMS_RecipientInfo_ktri_cert_cmp(),CMS_RecipientInfo_kemri_cert_cmp()andCMS_RecipientInfo_kekri_cmp()β return0for a successful comparison and non zero otherwise. (heads up, zero is the good number here, yes it's confusing, we deal π)CMS_RecipientInfo_kemri_get0_ctx()andCMS_RecipientInfo_kari_get0_ctxβ return the RecipientInfo'sEVP_CIPHER_CTXorNULLif an error occurred.CMS_RecipientInfo_kemri_get0_kdf_alg()β returns the RecipientInfo's KDF'sX509_ALGORorNULLif an error occurred.
any error can be obtained from ERR_get_error(3). go check the receipts π
π SEE ALSO π
ERR_get_error(3), CMS_decrypt(3)
π¦ HISTORY π¦
CMS_RecipientInfo_kari_set0_pkey_and_peerandCMS_RecipientInfo_kari_set0_pkeywere added in OpenSSL 3.0.CMS_RecipientInfo_kemri_cert_cmp,CMS_RecipientInfo_kemri_set0_pkey,CMS_RecipientInfo_kemri_get0_ctx,CMS_RecipientInfo_kemri_get0_kdf_algandCMS_RecipientInfo_kemri_set_ukmwere added in OpenSSL 3.6.
glow-ups only β¨
π COPYRIGHT π
Copyright 2008-2025 The OpenSSL Project Authors. All Rights Reserved.
Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.
okay that's the whole page bestie, tysm for reading!! this was OpenSSL 4.0.3, dated 2026-09-29, and you can find it filed under CMS_GET0_RECIPIENTINFOS(3SSL) π mwah, go encrypt something cute ππ«Ά
π¦ where this page comes from
- ubuntu stonking: libssl-doc 4.0.3-1ubuntu1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms