/* * Copyright 2008-2023 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 */#include"internal/cryptlib.h"#include<openssl/asn1t.h>#include<openssl/pem.h>#include<openssl/x509.h>#include<openssl/x509v3.h>#include<openssl/err.h>#include<openssl/cms.h>#include<openssl/ess.h>#include"internal/sizes.h"#include"crypto/asn1.h"#include"crypto/evp.h"#include"crypto/ess.h"#include"crypto/x509.h" /* for ossl_x509_add_cert_new() */#include"cms_local.h"/* CMS SignedData Utilities */staticCMS_SignedData*cms_get0_signed(CMS_ContentInfo*cms){if(OBJ_obj2nid(cms->contentType)!=NID_pkcs7_signed){ERR_raise(ERR_LIB_CMS,CMS_R_CONTENT_TYPE_NOT_SIGNED_DATA);returnNULL;}returncms->d.signedData;}staticCMS_SignedData*cms_signed_data_init(CMS_ContentInfo*cms){if(cms->d.other==NULL){cms->d.signedData=M_ASN1_new_of(CMS_SignedData);if(!cms->d.signedData){ERR_raise(ERR_LIB_CMS,ERR_R_ASN1_LIB);returnNULL;}cms->d.signedData->version=1;cms->d.signedData->encapContentInfo->eContentType=OBJ_nid2obj(NID_pkcs7_data);cms->d.signedData->encapContentInfo->partial=1;ASN1_OBJECT_free(cms->contentType);cms->contentType=OBJ_nid2obj(NID_pkcs7_signed);returncms->d.signedData;}returncms_get0_signed(cms);}/* Just initialise SignedData e.g. for certs only structure */intCMS_SignedData_init(CMS_ContentInfo*cms){if(cms_signed_data_init(cms))return1;elsereturn0;}/* Check structures and fixup version numbers (if necessary) */staticvoidcms_sd_set_version(CMS_SignedData*sd){inti;CMS_CertificateChoices*cch;CMS_RevocationInfoChoice*rch;CMS_SignerInfo*si;for(i=0;i<sk_CMS_CertificateChoices_num(sd->certificates);i++){cch=sk_CMS_CertificateChoices_value(sd->certificates,i);if(cch->type==CMS_CERTCHOICE_OTHER){if(sd->version<5)sd->version=5;}elseif(cch->type==CMS_CERTCHOICE_V2ACERT){if(sd->version<4)sd->version=4;}elseif(cch->type==CMS_CERTCHOICE_V1ACERT){if(sd->version<3)sd->version=3;}}for(i=0;i<sk_CMS_RevocationInfoChoice_num(sd->crls);i++)