CMS_GET0_RECIPIENTINFOS(3ossl)
π NAME π
CMS_get0_RecipientInfos, CMS_RecipientInfo_type, CMS_RecipientInfo_ktri_get0_signer_id, CMS_RecipientInfo_ktri_cert_cmp, CMS_RecipientInfo_set0_pkey, CMS_RecipientInfo_kekri_get0_id, CMS_RecipientInfo_kari_set0_pkey_and_peer, CMS_RecipientInfo_kari_set0_pkey, CMS_RecipientInfo_kekri_id_cmp, CMS_RecipientInfo_set0_key, CMS_RecipientInfo_decrypt, CMS_RecipientInfo_encrypt β bestie, these are the CMS envelopedData RecipientInfo routines. This is 3ossl erasure, we are in the OpenSSL manual, and yes it's giving β¨cryptographyβ¨.
πΈ 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);
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_decrypt(CMS_ContentInfo *cms, CMS_RecipientInfo *ri);
int CMS_RecipientInfo_encrypt(CMS_ContentInfo *cms, CMS_RecipientInfo *ri);
π¦ DESCRIPTION π¦
okay so, story time. Here's what every single one of these does, no skips, no summarising, we're doing the full read π
CMS_get0_RecipientInfos()β hands you all theCMS_RecipientInfostructures that are associated with a CMSEnvelopedDatastructure. The whole squad. Every recipient, front to back.CMS_RecipientInfo_type()β tells you what kind ofCMS_RecipientInfostructureriis. rn it will return one ofCMS_RECIPINFO_TRANS,CMS_RECIPINFO_AGREE,CMS_RECIPINFO_KEK,CMS_RECIPINFO_PASS, orCMS_RECIPINFO_OTHER. Vibe check for recipient infos, basically.CMS_RecipientInfo_ktri_get0_signer_id()β pulls out the certificate recipient identifier attached to a specificCMS_RecipientInfostructureri, andrimust be of typeCMS_RECIPINFO_TRANS. Either the keyidentifier gets set inkeyid, or both the issuer name and serial number land inissuerandsno. One or the other, bestie.CMS_RecipientInfo_ktri_cert_cmp()β compares the certificatecertagainst theCMS_RecipientInfostructureri, andrimust be of typeCMS_RECIPINFO_TRANS. Returns zero if the comparison slays (successful) and non zero if it does not.CMS_RecipientInfo_set0_pkey()β associates the private keypkeywith theCMS_RecipientInfostructureri, which must be of typeCMS_RECIPINFO_TRANS. It's giving "here's the key, go off".CMS_RecipientInfo_kari_set0_pkey_and_peer()β associates the private keypkeyand the peer certificatepeerwith theCMS_RecipientInfostructureri, which must be of typeCMS_RECIPINFO_AGREE. Two-for-one, iconic.CMS_RecipientInfo_kari_set0_pkey()β associates the private keypkeywith theCMS_RecipientInfostructureri, which must be of typeCMS_RECIPINFO_AGREE.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 simply does not care about the value of that field, and that's fine, we respect it. Where a field is optional and absent,NULLwill be written to the corresponding parameter. So: thekeyEncryptionAlgorithmfield goes topalg, thekeyIdentifierfield goes topid, the date field if present goes topdate, and if the other field is present, its componentskeyAttrIdandkeyAttrgo to the parameterspotheridandpothertype.CMS_RecipientInfo_kekri_id_cmp()β compares the ID in theidandidlenparameters against the keyIdentifier of theCMS_RecipientInfostructureri, which must be of typeCMS_RECIPINFO_KEK. Returns zero if the comparison is successful and non zero if not. Same energy as the cert one.CMS_RecipientInfo_set0_key()β associates the symmetric keykeyof lengthkeylenwith theCMS_RecipientInfostructureri, which must be of typeCMS_RECIPINFO_KEK.CMS_RecipientInfo_decrypt()β attempts to decrypt theCMS_RecipientInfostructureriinside the structurecms. A key must have been associated with the structure first, no shortcuts π«ΆCMS_RecipientInfo_encrypt()β attempts to encrypt theCMS_RecipientInfostructureriinside the structurecms. Again, 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().
π NOTES π
The main purpose of these functions, the whole reason they exist, is to let an application look up recipient keys using literally any appropriate technique, for the situations where the simpler method of CMS_decrypt() is just not appropriate. Sometimes the simple way isn't the move, and that's okay.
In typical usage, an application will retrieve all CMS_RecipientInfo structures using CMS_get0_RecipientInfos() and check the type of each one using CMS_RecipientInfo_type(). Depending on the type, the CMS_RecipientInfo structure can be ignored, or its key identifier data can be 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 succeeds, CMS_decrypt() can be called with a NULL key to decrypt the enveloped content. A whole pipeline, and honestly? she ate.
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 encrypt key available, then add a new recipient using a function such as CMS_add1_recipient_cert(), and finally encrypt the content encryption key using CMS_RecipientInfo_encrypt(). Three steps, no notes.
β¨ 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()andCMS_RecipientInfo_decrypt()return1for success or0if an error occurs.CMS_RecipientInfo_encrypt()returns1for success or0if an error occurs. Yes, same numbers, we're consistent like that.CMS_RecipientInfo_ktri_cert_cmp()andCMS_RecipientInfo_kekri_cmp()return0for a successful comparison and non zero otherwise. (careful bestie,0means good here, not bad β flipped from the usual vibe check π)- Any error can be obtained from
ERR_get_error(3).
π SEE ALSO π
ERR_get_error(3), CMS_decrypt(3)
iykyk, go read those next.
π HISTORY π
CMS_RecipientInfo_kari_set0_pkey_and_peer and CMS_RecipientInfo_kari_set0_pkey were added in OpenSSL 3.0. New girls on the block, but they've been here a minute.
π COPYRIGHT π
Copyright 2008-2020 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>.
and that's the whole page, bestie π«Ά this was OpenSSL 3.5.9, dated 2026-09-29, for CMS_GET0_RECIPIENTINFOS(3ossl) β go forth and decrypt responsibly, mwah πβ¨
π¦ where this page comes from
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms