2015-01-22 11:40:55 +08:00
|
|
|
/*
|
2021-01-28 20:54:57 +08:00
|
|
|
* Copyright 2008-2021 The OpenSSL Project Authors. All Rights Reserved.
|
2008-03-13 05:14:28 +08:00
|
|
|
*
|
2018-12-06 20:32:50 +08:00
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-05-18 02:52:22 +08:00
|
|
|
* 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
|
2008-03-13 05:14:28 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <openssl/asn1t.h>
|
2013-07-17 21:36:39 +08:00
|
|
|
#include <openssl/x509v3.h>
|
2008-03-13 05:14:28 +08:00
|
|
|
#include <openssl/err.h>
|
|
|
|
#include <openssl/pem.h>
|
|
|
|
#include <openssl/bio.h>
|
|
|
|
#include <openssl/asn1.h>
|
2014-10-12 02:31:53 +08:00
|
|
|
#include <openssl/cms.h>
|
2020-07-25 16:04:55 +08:00
|
|
|
#include <openssl/cms.h>
|
2021-03-10 19:58:53 +08:00
|
|
|
#include "internal/sizes.h"
|
2020-07-25 16:04:55 +08:00
|
|
|
#include "crypto/x509.h"
|
2019-09-28 06:45:40 +08:00
|
|
|
#include "cms_local.h"
|
2008-03-13 05:14:28 +08:00
|
|
|
|
2020-07-25 16:04:55 +08:00
|
|
|
static STACK_OF(CMS_CertificateChoices)
|
|
|
|
**cms_get0_certificate_choices(CMS_ContentInfo *cms);
|
|
|
|
|
2008-03-13 05:14:28 +08:00
|
|
|
IMPLEMENT_ASN1_PRINT_FUNCTION(CMS_ContentInfo)
|
|
|
|
|
2020-07-25 16:04:55 +08:00
|
|
|
CMS_ContentInfo *d2i_CMS_ContentInfo(CMS_ContentInfo **a,
|
|
|
|
const unsigned char **in, long len)
|
|
|
|
{
|
|
|
|
CMS_ContentInfo *ci;
|
2021-05-26 00:46:11 +08:00
|
|
|
const CMS_CTX *ctx = ossl_cms_get0_cmsctx(a == NULL ? NULL : *a);
|
2020-07-25 16:04:55 +08:00
|
|
|
|
2021-05-26 00:46:11 +08:00
|
|
|
ci = (CMS_ContentInfo *)ASN1_item_d2i_ex((ASN1_VALUE **)a, in, len,
|
|
|
|
(CMS_ContentInfo_it()),
|
|
|
|
ossl_cms_ctx_get0_libctx(ctx),
|
|
|
|
ossl_cms_ctx_get0_propq(ctx));
|
2020-12-11 17:19:37 +08:00
|
|
|
if (ci != NULL)
|
2021-02-18 12:03:25 +08:00
|
|
|
ossl_cms_resolve_libctx(ci);
|
2020-07-25 16:04:55 +08:00
|
|
|
return ci;
|
|
|
|
}
|
|
|
|
|
|
|
|
int i2d_CMS_ContentInfo(const CMS_ContentInfo *a, unsigned char **out)
|
|
|
|
{
|
|
|
|
return ASN1_item_i2d((const ASN1_VALUE *)a, out, (CMS_ContentInfo_it()));
|
|
|
|
}
|
|
|
|
|
2020-10-15 17:55:50 +08:00
|
|
|
CMS_ContentInfo *CMS_ContentInfo_new_ex(OSSL_LIB_CTX *libctx, const char *propq)
|
2020-07-25 16:04:55 +08:00
|
|
|
{
|
|
|
|
CMS_ContentInfo *ci;
|
|
|
|
|
2021-05-26 00:46:11 +08:00
|
|
|
ci = (CMS_ContentInfo *)ASN1_item_new_ex(ASN1_ITEM_rptr(CMS_ContentInfo),
|
|
|
|
libctx, propq);
|
2020-07-25 16:04:55 +08:00
|
|
|
if (ci != NULL) {
|
|
|
|
ci->ctx.libctx = libctx;
|
|
|
|
ci->ctx.propq = NULL;
|
|
|
|
if (propq != NULL) {
|
|
|
|
ci->ctx.propq = OPENSSL_strdup(propq);
|
|
|
|
if (ci->ctx.propq == NULL) {
|
|
|
|
CMS_ContentInfo_free(ci);
|
|
|
|
ci = NULL;
|
|
|
|
ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ci;
|
|
|
|
}
|
|
|
|
|
|
|
|
CMS_ContentInfo *CMS_ContentInfo_new(void)
|
|
|
|
{
|
2020-09-24 17:42:23 +08:00
|
|
|
return CMS_ContentInfo_new_ex(NULL, NULL);
|
2020-07-25 16:04:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CMS_ContentInfo_free(CMS_ContentInfo *cms)
|
|
|
|
{
|
|
|
|
if (cms != NULL) {
|
|
|
|
OPENSSL_free(cms->ctx.propq);
|
|
|
|
ASN1_item_free((ASN1_VALUE *)cms, ASN1_ITEM_rptr(CMS_ContentInfo));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-18 12:03:25 +08:00
|
|
|
const CMS_CTX *ossl_cms_get0_cmsctx(const CMS_ContentInfo *cms)
|
2020-07-25 16:04:55 +08:00
|
|
|
{
|
|
|
|
return cms != NULL ? &cms->ctx : NULL;
|
|
|
|
}
|
|
|
|
|
2021-02-18 12:03:25 +08:00
|
|
|
OSSL_LIB_CTX *ossl_cms_ctx_get0_libctx(const CMS_CTX *ctx)
|
2020-07-25 16:04:55 +08:00
|
|
|
{
|
2020-12-11 17:19:37 +08:00
|
|
|
return ctx != NULL ? ctx->libctx : NULL;
|
2020-07-25 16:04:55 +08:00
|
|
|
}
|
|
|
|
|
2021-02-18 12:03:25 +08:00
|
|
|
const char *ossl_cms_ctx_get0_propq(const CMS_CTX *ctx)
|
2020-07-25 16:04:55 +08:00
|
|
|
{
|
2020-12-11 17:19:37 +08:00
|
|
|
return ctx != NULL ? ctx->propq : NULL;
|
2020-07-25 16:04:55 +08:00
|
|
|
}
|
|
|
|
|
2021-02-18 12:03:25 +08:00
|
|
|
void ossl_cms_resolve_libctx(CMS_ContentInfo *ci)
|
2020-07-25 16:04:55 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
CMS_CertificateChoices *cch;
|
|
|
|
STACK_OF(CMS_CertificateChoices) **pcerts;
|
2021-02-18 12:03:25 +08:00
|
|
|
const CMS_CTX *ctx = ossl_cms_get0_cmsctx(ci);
|
|
|
|
OSSL_LIB_CTX *libctx = ossl_cms_ctx_get0_libctx(ctx);
|
|
|
|
const char *propq = ossl_cms_ctx_get0_propq(ctx);
|
2020-07-25 16:04:55 +08:00
|
|
|
|
2021-02-18 12:03:25 +08:00
|
|
|
ossl_cms_SignerInfos_set_cmsctx(ci);
|
|
|
|
ossl_cms_RecipientInfos_set_cmsctx(ci);
|
2020-07-25 16:04:55 +08:00
|
|
|
|
|
|
|
pcerts = cms_get0_certificate_choices(ci);
|
|
|
|
if (pcerts != NULL) {
|
|
|
|
for (i = 0; i < sk_CMS_CertificateChoices_num(*pcerts); i++) {
|
|
|
|
cch = sk_CMS_CertificateChoices_value(*pcerts, i);
|
|
|
|
if (cch->type == CMS_CERTCHOICE_CERT)
|
2021-03-09 12:18:03 +08:00
|
|
|
ossl_x509_set0_libctx(cch->d.certificate, libctx, propq);
|
2020-07-25 16:04:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-12 17:18:13 +08:00
|
|
|
const ASN1_OBJECT *CMS_get0_type(const CMS_ContentInfo *cms)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
return cms->contentType;
|
|
|
|
}
|
2008-03-13 05:14:28 +08:00
|
|
|
|
2021-02-18 12:03:25 +08:00
|
|
|
CMS_ContentInfo *ossl_cms_Data_create(OSSL_LIB_CTX *libctx, const char *propq)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
2020-09-24 17:42:23 +08:00
|
|
|
CMS_ContentInfo *cms = CMS_ContentInfo_new_ex(libctx, propq);
|
2020-07-25 16:04:55 +08:00
|
|
|
|
2015-10-30 19:12:26 +08:00
|
|
|
if (cms != NULL) {
|
2015-01-22 11:40:55 +08:00
|
|
|
cms->contentType = OBJ_nid2obj(NID_pkcs7_data);
|
|
|
|
/* Never detached */
|
|
|
|
CMS_set_detached(cms, 0);
|
|
|
|
}
|
|
|
|
return cms;
|
|
|
|
}
|
2008-03-13 05:14:28 +08:00
|
|
|
|
2021-02-18 12:03:25 +08:00
|
|
|
BIO *ossl_cms_content_bio(CMS_ContentInfo *cms)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
ASN1_OCTET_STRING **pos = CMS_get0_content(cms);
|
2019-09-17 03:28:57 +08:00
|
|
|
|
|
|
|
if (pos == NULL)
|
2015-01-22 11:40:55 +08:00
|
|
|
return NULL;
|
|
|
|
/* If content detached data goes nowhere: create NULL BIO */
|
2019-09-17 03:28:57 +08:00
|
|
|
if (*pos == NULL)
|
2015-01-22 11:40:55 +08:00
|
|
|
return BIO_new(BIO_s_null());
|
|
|
|
/*
|
|
|
|
* If content not detached and created return memory BIO
|
|
|
|
*/
|
2019-09-17 03:28:57 +08:00
|
|
|
if (*pos == NULL || ((*pos)->flags == ASN1_STRING_FLAG_CONT))
|
2015-01-22 11:40:55 +08:00
|
|
|
return BIO_new(BIO_s_mem());
|
|
|
|
/* Else content was read in: return read only BIO for it */
|
|
|
|
return BIO_new_mem_buf((*pos)->data, (*pos)->length);
|
|
|
|
}
|
2008-03-13 05:14:28 +08:00
|
|
|
|
|
|
|
BIO *CMS_dataInit(CMS_ContentInfo *cms, BIO *icont)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
BIO *cmsbio, *cont;
|
|
|
|
if (icont)
|
|
|
|
cont = icont;
|
|
|
|
else
|
2021-02-18 12:03:25 +08:00
|
|
|
cont = ossl_cms_content_bio(cms);
|
2015-01-22 11:40:55 +08:00
|
|
|
if (!cont) {
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_CMS, CMS_R_NO_CONTENT);
|
2015-01-22 11:40:55 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
switch (OBJ_obj2nid(cms->contentType)) {
|
|
|
|
|
|
|
|
case NID_pkcs7_data:
|
|
|
|
return cont;
|
|
|
|
|
|
|
|
case NID_pkcs7_signed:
|
2021-02-18 12:03:25 +08:00
|
|
|
cmsbio = ossl_cms_SignedData_init_bio(cms);
|
2015-01-22 11:40:55 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NID_pkcs7_digest:
|
2021-02-18 12:03:25 +08:00
|
|
|
cmsbio = ossl_cms_DigestedData_init_bio(cms);
|
2015-01-22 11:40:55 +08:00
|
|
|
break;
|
2008-03-13 05:14:28 +08:00
|
|
|
#ifdef ZLIB
|
2015-01-22 11:40:55 +08:00
|
|
|
case NID_id_smime_ct_compressedData:
|
2021-02-18 12:03:25 +08:00
|
|
|
cmsbio = ossl_cms_CompressedData_init_bio(cms);
|
2015-01-22 11:40:55 +08:00
|
|
|
break;
|
2008-03-13 05:14:28 +08:00
|
|
|
#endif
|
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
case NID_pkcs7_encrypted:
|
2021-02-18 12:03:25 +08:00
|
|
|
cmsbio = ossl_cms_EncryptedData_init_bio(cms);
|
2015-01-22 11:40:55 +08:00
|
|
|
break;
|
2008-03-14 21:21:48 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
case NID_pkcs7_enveloped:
|
2021-02-18 12:03:25 +08:00
|
|
|
cmsbio = ossl_cms_EnvelopedData_init_bio(cms);
|
2015-01-22 11:40:55 +08:00
|
|
|
break;
|
2008-03-16 07:21:33 +08:00
|
|
|
|
2020-09-07 02:11:34 +08:00
|
|
|
case NID_id_smime_ct_authEnvelopedData:
|
2021-02-18 12:03:25 +08:00
|
|
|
cmsbio = ossl_cms_AuthEnvelopedData_init_bio(cms);
|
2020-09-07 02:11:34 +08:00
|
|
|
break;
|
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
default:
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_CMS, CMS_R_UNSUPPORTED_TYPE);
|
2020-08-04 10:34:22 +08:00
|
|
|
goto err;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
2008-03-13 05:14:28 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
if (cmsbio)
|
|
|
|
return BIO_push(cmsbio, cont);
|
2020-08-04 10:34:22 +08:00
|
|
|
err:
|
2015-01-22 11:40:55 +08:00
|
|
|
if (!icont)
|
|
|
|
BIO_free(cont);
|
|
|
|
return NULL;
|
2008-03-13 05:14:28 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
2008-03-14 21:21:48 +08:00
|
|
|
|
2019-01-16 04:51:25 +08:00
|
|
|
/* unfortunately cannot constify SMIME_write_ASN1() due to this function */
|
2008-03-13 05:14:28 +08:00
|
|
|
int CMS_dataFinal(CMS_ContentInfo *cms, BIO *cmsbio)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
ASN1_OCTET_STRING **pos = CMS_get0_content(cms);
|
2019-09-17 03:28:57 +08:00
|
|
|
|
|
|
|
if (pos == NULL)
|
2015-01-22 11:40:55 +08:00
|
|
|
return 0;
|
2016-02-06 04:23:54 +08:00
|
|
|
/* If embedded content find memory BIO and set content */
|
2015-01-22 11:40:55 +08:00
|
|
|
if (*pos && ((*pos)->flags & ASN1_STRING_FLAG_CONT)) {
|
|
|
|
BIO *mbio;
|
|
|
|
unsigned char *cont;
|
|
|
|
long contlen;
|
|
|
|
mbio = BIO_find_type(cmsbio, BIO_TYPE_MEM);
|
|
|
|
if (!mbio) {
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_CMS, CMS_R_CONTENT_NOT_FOUND);
|
2015-01-22 11:40:55 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
contlen = BIO_get_mem_data(mbio, &cont);
|
|
|
|
/* Set bio as read only so its content can't be clobbered */
|
|
|
|
BIO_set_flags(mbio, BIO_FLAGS_MEM_RDONLY);
|
|
|
|
BIO_set_mem_eof_return(mbio, 0);
|
|
|
|
ASN1_STRING_set0(*pos, cont, contlen);
|
|
|
|
(*pos)->flags &= ~ASN1_STRING_FLAG_CONT;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (OBJ_obj2nid(cms->contentType)) {
|
|
|
|
|
|
|
|
case NID_pkcs7_data:
|
|
|
|
case NID_pkcs7_encrypted:
|
|
|
|
case NID_id_smime_ct_compressedData:
|
|
|
|
/* Nothing to do */
|
|
|
|
return 1;
|
|
|
|
|
2020-01-20 23:17:44 +08:00
|
|
|
case NID_pkcs7_enveloped:
|
2021-02-18 12:03:25 +08:00
|
|
|
return ossl_cms_EnvelopedData_final(cms, cmsbio);
|
2020-01-20 23:17:44 +08:00
|
|
|
|
2020-09-07 02:11:34 +08:00
|
|
|
case NID_id_smime_ct_authEnvelopedData:
|
2021-02-18 12:03:25 +08:00
|
|
|
return ossl_cms_AuthEnvelopedData_final(cms, cmsbio);
|
2020-09-07 02:11:34 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
case NID_pkcs7_signed:
|
2021-02-18 12:03:25 +08:00
|
|
|
return ossl_cms_SignedData_final(cms, cmsbio);
|
2015-01-22 11:40:55 +08:00
|
|
|
|
|
|
|
case NID_pkcs7_digest:
|
2021-02-18 12:03:25 +08:00
|
|
|
return ossl_cms_DigestedData_do_final(cms, cmsbio, 0);
|
2015-01-22 11:40:55 +08:00
|
|
|
|
|
|
|
default:
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_CMS, CMS_R_UNSUPPORTED_TYPE);
|
2015-01-22 11:40:55 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return an OCTET STRING pointer to content. This allows it to be accessed
|
|
|
|
* or set later.
|
2008-03-13 05:14:28 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
ASN1_OCTET_STRING **CMS_get0_content(CMS_ContentInfo *cms)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
switch (OBJ_obj2nid(cms->contentType)) {
|
2008-03-13 05:14:28 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
case NID_pkcs7_data:
|
|
|
|
return &cms->d.data;
|
2008-03-13 05:14:28 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
case NID_pkcs7_signed:
|
|
|
|
return &cms->d.signedData->encapContentInfo->eContent;
|
2008-03-13 05:14:28 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
case NID_pkcs7_enveloped:
|
|
|
|
return &cms->d.envelopedData->encryptedContentInfo->encryptedContent;
|
2008-03-13 05:14:28 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
case NID_pkcs7_digest:
|
|
|
|
return &cms->d.digestedData->encapContentInfo->eContent;
|
2008-03-13 05:14:28 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
case NID_pkcs7_encrypted:
|
|
|
|
return &cms->d.encryptedData->encryptedContentInfo->encryptedContent;
|
2008-03-13 05:14:28 +08:00
|
|
|
|
2020-09-07 02:11:34 +08:00
|
|
|
case NID_id_smime_ct_authEnvelopedData:
|
|
|
|
return &cms->d.authEnvelopedData->authEncryptedContentInfo
|
|
|
|
->encryptedContent;
|
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
case NID_id_smime_ct_authData:
|
|
|
|
return &cms->d.authenticatedData->encapContentInfo->eContent;
|
2008-03-13 05:14:28 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
case NID_id_smime_ct_compressedData:
|
|
|
|
return &cms->d.compressedData->encapContentInfo->eContent;
|
2008-03-13 05:14:28 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
default:
|
|
|
|
if (cms->d.other->type == V_ASN1_OCTET_STRING)
|
|
|
|
return &cms->d.other->value.octet_string;
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_CMS, CMS_R_UNSUPPORTED_CONTENT_TYPE);
|
2015-01-22 11:40:55 +08:00
|
|
|
return NULL;
|
2008-03-13 05:14:28 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
|
|
|
}
|
2008-03-13 05:14:28 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
/*
|
|
|
|
* Return an ASN1_OBJECT pointer to content type. This allows it to be
|
|
|
|
* accessed or set later.
|
2008-03-13 05:14:28 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
static ASN1_OBJECT **cms_get0_econtent_type(CMS_ContentInfo *cms)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
switch (OBJ_obj2nid(cms->contentType)) {
|
2008-03-13 05:14:28 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
case NID_pkcs7_signed:
|
|
|
|
return &cms->d.signedData->encapContentInfo->eContentType;
|
2008-03-13 05:14:28 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
case NID_pkcs7_enveloped:
|
|
|
|
return &cms->d.envelopedData->encryptedContentInfo->contentType;
|
2008-03-13 05:14:28 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
case NID_pkcs7_digest:
|
|
|
|
return &cms->d.digestedData->encapContentInfo->eContentType;
|
2008-03-13 05:14:28 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
case NID_pkcs7_encrypted:
|
|
|
|
return &cms->d.encryptedData->encryptedContentInfo->contentType;
|
2008-03-13 05:14:28 +08:00
|
|
|
|
2020-09-07 02:11:34 +08:00
|
|
|
case NID_id_smime_ct_authEnvelopedData:
|
|
|
|
return &cms->d.authEnvelopedData->authEncryptedContentInfo
|
|
|
|
->contentType;
|
2015-01-22 11:40:55 +08:00
|
|
|
case NID_id_smime_ct_authData:
|
|
|
|
return &cms->d.authenticatedData->encapContentInfo->eContentType;
|
2008-03-13 05:14:28 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
case NID_id_smime_ct_compressedData:
|
|
|
|
return &cms->d.compressedData->encapContentInfo->eContentType;
|
2008-03-13 05:14:28 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
default:
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_CMS, CMS_R_UNSUPPORTED_CONTENT_TYPE);
|
2015-01-22 11:40:55 +08:00
|
|
|
return NULL;
|
2008-03-13 05:14:28 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
|
|
|
}
|
2008-03-13 05:14:28 +08:00
|
|
|
|
|
|
|
const ASN1_OBJECT *CMS_get0_eContentType(CMS_ContentInfo *cms)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
ASN1_OBJECT **petype;
|
|
|
|
petype = cms_get0_econtent_type(cms);
|
|
|
|
if (petype)
|
|
|
|
return *petype;
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-03-13 05:14:28 +08:00
|
|
|
|
|
|
|
int CMS_set1_eContentType(CMS_ContentInfo *cms, const ASN1_OBJECT *oid)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
ASN1_OBJECT **petype, *etype;
|
2019-09-17 03:28:57 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
petype = cms_get0_econtent_type(cms);
|
2019-09-17 03:28:57 +08:00
|
|
|
if (petype == NULL)
|
2015-01-22 11:40:55 +08:00
|
|
|
return 0;
|
2019-09-17 03:28:57 +08:00
|
|
|
if (oid == NULL)
|
2015-01-22 11:40:55 +08:00
|
|
|
return 1;
|
|
|
|
etype = OBJ_dup(oid);
|
2019-09-17 03:28:57 +08:00
|
|
|
if (etype == NULL)
|
2015-01-22 11:40:55 +08:00
|
|
|
return 0;
|
|
|
|
ASN1_OBJECT_free(*petype);
|
|
|
|
*petype = etype;
|
|
|
|
return 1;
|
|
|
|
}
|
2008-03-13 05:14:28 +08:00
|
|
|
|
|
|
|
int CMS_is_detached(CMS_ContentInfo *cms)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
ASN1_OCTET_STRING **pos;
|
2019-09-17 03:28:57 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
pos = CMS_get0_content(cms);
|
2019-09-17 03:28:57 +08:00
|
|
|
if (pos == NULL)
|
2015-01-22 11:40:55 +08:00
|
|
|
return -1;
|
2019-09-17 03:28:57 +08:00
|
|
|
if (*pos != NULL)
|
2015-01-22 11:40:55 +08:00
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
2008-03-13 05:14:28 +08:00
|
|
|
|
|
|
|
int CMS_set_detached(CMS_ContentInfo *cms, int detached)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
ASN1_OCTET_STRING **pos;
|
2019-09-17 03:28:57 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
pos = CMS_get0_content(cms);
|
2019-09-17 03:28:57 +08:00
|
|
|
if (pos == NULL)
|
2015-01-22 11:40:55 +08:00
|
|
|
return 0;
|
|
|
|
if (detached) {
|
2015-04-30 23:30:03 +08:00
|
|
|
ASN1_OCTET_STRING_free(*pos);
|
|
|
|
*pos = NULL;
|
2015-01-22 11:40:55 +08:00
|
|
|
return 1;
|
|
|
|
}
|
2015-10-30 19:12:26 +08:00
|
|
|
if (*pos == NULL)
|
2015-01-22 11:40:55 +08:00
|
|
|
*pos = ASN1_OCTET_STRING_new();
|
2015-10-30 19:12:26 +08:00
|
|
|
if (*pos != NULL) {
|
2015-01-22 11:40:55 +08:00
|
|
|
/*
|
|
|
|
* NB: special flag to show content is created and not read in.
|
|
|
|
*/
|
|
|
|
(*pos)->flags |= ASN1_STRING_FLAG_CONT;
|
|
|
|
return 1;
|
|
|
|
}
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE);
|
2015-01-22 11:40:55 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2008-03-13 05:14:28 +08:00
|
|
|
|
|
|
|
/* Create a digest BIO from an X509_ALGOR structure */
|
|
|
|
|
2021-02-18 12:03:25 +08:00
|
|
|
BIO *ossl_cms_DigestAlgorithm_init_bio(X509_ALGOR *digestAlgorithm,
|
|
|
|
const CMS_CTX *ctx)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
BIO *mdbio = NULL;
|
2016-08-17 03:18:04 +08:00
|
|
|
const ASN1_OBJECT *digestoid;
|
2020-08-20 11:28:11 +08:00
|
|
|
const EVP_MD *digest = NULL;
|
|
|
|
EVP_MD *fetched_digest = NULL;
|
2021-03-10 19:58:53 +08:00
|
|
|
char alg[OSSL_MAX_NAME_SIZE];
|
2020-07-25 16:04:55 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
X509_ALGOR_get0(&digestoid, NULL, NULL, digestAlgorithm);
|
2021-03-10 19:58:53 +08:00
|
|
|
OBJ_obj2txt(alg, sizeof(alg), digestoid, 0);
|
2020-08-20 11:28:11 +08:00
|
|
|
|
|
|
|
(void)ERR_set_mark();
|
2021-02-18 12:03:25 +08:00
|
|
|
fetched_digest = EVP_MD_fetch(ossl_cms_ctx_get0_libctx(ctx), alg,
|
|
|
|
ossl_cms_ctx_get0_propq(ctx));
|
2020-08-20 11:28:11 +08:00
|
|
|
|
|
|
|
if (fetched_digest != NULL)
|
|
|
|
digest = fetched_digest;
|
|
|
|
else
|
|
|
|
digest = EVP_get_digestbyobj(digestoid);
|
2020-07-25 16:04:55 +08:00
|
|
|
if (digest == NULL) {
|
2020-08-20 11:28:11 +08:00
|
|
|
(void)ERR_clear_last_mark();
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_CMS, CMS_R_UNKNOWN_DIGEST_ALGORITHM);
|
2015-01-22 11:40:55 +08:00
|
|
|
goto err;
|
|
|
|
}
|
2020-08-20 11:28:11 +08:00
|
|
|
(void)ERR_pop_to_mark();
|
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
mdbio = BIO_new(BIO_f_md());
|
2015-10-30 19:12:26 +08:00
|
|
|
if (mdbio == NULL || !BIO_set_md(mdbio, digest)) {
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_CMS, CMS_R_MD_BIO_INIT_ERROR);
|
2015-01-22 11:40:55 +08:00
|
|
|
goto err;
|
|
|
|
}
|
2020-08-20 11:28:11 +08:00
|
|
|
EVP_MD_free(fetched_digest);
|
2015-01-22 11:40:55 +08:00
|
|
|
return mdbio;
|
|
|
|
err:
|
2020-08-20 11:28:11 +08:00
|
|
|
EVP_MD_free(fetched_digest);
|
2015-03-25 23:31:18 +08:00
|
|
|
BIO_free(mdbio);
|
2015-01-22 11:40:55 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
2008-03-13 05:14:28 +08:00
|
|
|
|
|
|
|
/* Locate a message digest content from a BIO chain based on SignerInfo */
|
|
|
|
|
2021-02-18 12:03:25 +08:00
|
|
|
int ossl_cms_DigestAlgorithm_find_ctx(EVP_MD_CTX *mctx, BIO *chain,
|
|
|
|
X509_ALGOR *mdalg)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
int nid;
|
2016-08-17 03:18:04 +08:00
|
|
|
const ASN1_OBJECT *mdoid;
|
2015-01-22 11:40:55 +08:00
|
|
|
X509_ALGOR_get0(&mdoid, NULL, NULL, mdalg);
|
|
|
|
nid = OBJ_obj2nid(mdoid);
|
|
|
|
/* Look for digest type to match signature */
|
|
|
|
for (;;) {
|
|
|
|
EVP_MD_CTX *mtmp;
|
|
|
|
chain = BIO_find_type(chain, BIO_TYPE_MD);
|
|
|
|
if (chain == NULL) {
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_CMS, CMS_R_NO_MATCHING_DIGEST);
|
2015-01-22 11:40:55 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
BIO_get_md_ctx(chain, &mtmp);
|
Rename all getters to use get/get0 in name
For functions that exist in 1.1.1 provide a simple aliases via #define.
Fixes #15236
Functions with OSSL_DECODER_, OSSL_ENCODER_, OSSL_STORE_LOADER_,
EVP_KEYEXCH_, EVP_KEM_, EVP_ASYM_CIPHER_, EVP_SIGNATURE_,
EVP_KEYMGMT_, EVP_RAND_, EVP_MAC_, EVP_KDF_, EVP_PKEY_,
EVP_MD_, and EVP_CIPHER_ prefixes are renamed.
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15405)
2021-05-21 22:58:08 +08:00
|
|
|
if (EVP_MD_CTX_get_type(mtmp) == nid
|
2015-01-22 11:40:55 +08:00
|
|
|
/*
|
|
|
|
* Workaround for broken implementations that use signature
|
|
|
|
* algorithm OID instead of digest.
|
|
|
|
*/
|
Rename all getters to use get/get0 in name
For functions that exist in 1.1.1 provide a simple aliases via #define.
Fixes #15236
Functions with OSSL_DECODER_, OSSL_ENCODER_, OSSL_STORE_LOADER_,
EVP_KEYEXCH_, EVP_KEM_, EVP_ASYM_CIPHER_, EVP_SIGNATURE_,
EVP_KEYMGMT_, EVP_RAND_, EVP_MAC_, EVP_KDF_, EVP_PKEY_,
EVP_MD_, and EVP_CIPHER_ prefixes are renamed.
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15405)
2021-05-21 22:58:08 +08:00
|
|
|
|| EVP_MD_get_pkey_type(EVP_MD_CTX_get0_md(mtmp)) == nid)
|
2015-01-22 11:40:55 +08:00
|
|
|
return EVP_MD_CTX_copy_ex(mctx, mtmp);
|
|
|
|
chain = BIO_next(chain);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static STACK_OF(CMS_CertificateChoices)
|
|
|
|
**cms_get0_certificate_choices(CMS_ContentInfo *cms)
|
|
|
|
{
|
|
|
|
switch (OBJ_obj2nid(cms->contentType)) {
|
|
|
|
|
|
|
|
case NID_pkcs7_signed:
|
|
|
|
return &cms->d.signedData->certificates;
|
|
|
|
|
|
|
|
case NID_pkcs7_enveloped:
|
2016-06-12 08:04:21 +08:00
|
|
|
if (cms->d.envelopedData->originatorInfo == NULL)
|
|
|
|
return NULL;
|
2015-01-22 11:40:55 +08:00
|
|
|
return &cms->d.envelopedData->originatorInfo->certificates;
|
|
|
|
|
2020-09-07 02:11:34 +08:00
|
|
|
case NID_id_smime_ct_authEnvelopedData:
|
|
|
|
if (cms->d.authEnvelopedData->originatorInfo == NULL)
|
|
|
|
return NULL;
|
|
|
|
return &cms->d.authEnvelopedData->originatorInfo->certificates;
|
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
default:
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_CMS, CMS_R_UNSUPPORTED_CONTENT_TYPE);
|
2015-01-22 11:40:55 +08:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2008-03-13 05:14:28 +08:00
|
|
|
|
|
|
|
CMS_CertificateChoices *CMS_add0_CertificateChoices(CMS_ContentInfo *cms)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
STACK_OF(CMS_CertificateChoices) **pcerts;
|
|
|
|
CMS_CertificateChoices *cch;
|
2019-09-17 03:28:57 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
pcerts = cms_get0_certificate_choices(cms);
|
2019-09-17 03:28:57 +08:00
|
|
|
if (pcerts == NULL)
|
2015-01-22 11:40:55 +08:00
|
|
|
return NULL;
|
2019-09-17 03:28:57 +08:00
|
|
|
if (*pcerts == NULL)
|
2015-01-22 11:40:55 +08:00
|
|
|
*pcerts = sk_CMS_CertificateChoices_new_null();
|
2019-09-17 03:28:57 +08:00
|
|
|
if (*pcerts == NULL)
|
2015-01-22 11:40:55 +08:00
|
|
|
return NULL;
|
|
|
|
cch = M_ASN1_new_of(CMS_CertificateChoices);
|
|
|
|
if (!cch)
|
|
|
|
return NULL;
|
|
|
|
if (!sk_CMS_CertificateChoices_push(*pcerts, cch)) {
|
|
|
|
M_ASN1_free_of(cch, CMS_CertificateChoices);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return cch;
|
|
|
|
}
|
2008-03-13 05:14:28 +08:00
|
|
|
|
|
|
|
int CMS_add0_cert(CMS_ContentInfo *cms, X509 *cert)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
CMS_CertificateChoices *cch;
|
|
|
|
STACK_OF(CMS_CertificateChoices) **pcerts;
|
|
|
|
int i;
|
2019-09-17 03:28:57 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
pcerts = cms_get0_certificate_choices(cms);
|
2019-09-17 03:28:57 +08:00
|
|
|
if (pcerts == NULL)
|
2015-01-22 11:40:55 +08:00
|
|
|
return 0;
|
|
|
|
for (i = 0; i < sk_CMS_CertificateChoices_num(*pcerts); i++) {
|
|
|
|
cch = sk_CMS_CertificateChoices_value(*pcerts, i);
|
|
|
|
if (cch->type == CMS_CERTCHOICE_CERT) {
|
|
|
|
if (!X509_cmp(cch->d.certificate, cert)) {
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_CMS, CMS_R_CERTIFICATE_ALREADY_PRESENT);
|
2015-01-22 11:40:55 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cch = CMS_add0_CertificateChoices(cms);
|
|
|
|
if (!cch)
|
|
|
|
return 0;
|
|
|
|
cch->type = CMS_CERTCHOICE_CERT;
|
|
|
|
cch->d.certificate = cert;
|
|
|
|
return 1;
|
|
|
|
}
|
2008-03-13 05:14:28 +08:00
|
|
|
|
|
|
|
int CMS_add1_cert(CMS_ContentInfo *cms, X509 *cert)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
int r;
|
|
|
|
r = CMS_add0_cert(cms, cert);
|
|
|
|
if (r > 0)
|
2015-09-01 03:29:57 +08:00
|
|
|
X509_up_ref(cert);
|
2015-01-22 11:40:55 +08:00
|
|
|
return r;
|
|
|
|
}
|
2008-03-13 05:14:28 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
static STACK_OF(CMS_RevocationInfoChoice)
|
|
|
|
**cms_get0_revocation_choices(CMS_ContentInfo *cms)
|
|
|
|
{
|
|
|
|
switch (OBJ_obj2nid(cms->contentType)) {
|
2008-03-13 05:14:28 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
case NID_pkcs7_signed:
|
|
|
|
return &cms->d.signedData->crls;
|
2008-03-13 05:14:28 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
case NID_pkcs7_enveloped:
|
2016-06-12 08:04:21 +08:00
|
|
|
if (cms->d.envelopedData->originatorInfo == NULL)
|
|
|
|
return NULL;
|
2015-01-22 11:40:55 +08:00
|
|
|
return &cms->d.envelopedData->originatorInfo->crls;
|
2008-03-13 05:14:28 +08:00
|
|
|
|
2020-09-07 02:11:34 +08:00
|
|
|
case NID_id_smime_ct_authEnvelopedData:
|
|
|
|
if (cms->d.authEnvelopedData->originatorInfo == NULL)
|
|
|
|
return NULL;
|
|
|
|
return &cms->d.authEnvelopedData->originatorInfo->crls;
|
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
default:
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_CMS, CMS_R_UNSUPPORTED_CONTENT_TYPE);
|
2015-01-22 11:40:55 +08:00
|
|
|
return NULL;
|
2008-03-13 05:14:28 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
|
|
|
}
|
2008-03-13 05:14:28 +08:00
|
|
|
|
|
|
|
CMS_RevocationInfoChoice *CMS_add0_RevocationInfoChoice(CMS_ContentInfo *cms)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
STACK_OF(CMS_RevocationInfoChoice) **pcrls;
|
|
|
|
CMS_RevocationInfoChoice *rch;
|
2019-09-17 03:28:57 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
pcrls = cms_get0_revocation_choices(cms);
|
2019-09-17 03:28:57 +08:00
|
|
|
if (pcrls == NULL)
|
2015-01-22 11:40:55 +08:00
|
|
|
return NULL;
|
2019-09-17 03:28:57 +08:00
|
|
|
if (*pcrls == NULL)
|
2015-01-22 11:40:55 +08:00
|
|
|
*pcrls = sk_CMS_RevocationInfoChoice_new_null();
|
2019-09-17 03:28:57 +08:00
|
|
|
if (*pcrls == NULL)
|
2015-01-22 11:40:55 +08:00
|
|
|
return NULL;
|
|
|
|
rch = M_ASN1_new_of(CMS_RevocationInfoChoice);
|
2019-09-17 03:28:57 +08:00
|
|
|
if (rch == NULL)
|
2015-01-22 11:40:55 +08:00
|
|
|
return NULL;
|
|
|
|
if (!sk_CMS_RevocationInfoChoice_push(*pcrls, rch)) {
|
|
|
|
M_ASN1_free_of(rch, CMS_RevocationInfoChoice);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return rch;
|
|
|
|
}
|
2008-03-13 05:14:28 +08:00
|
|
|
|
|
|
|
int CMS_add0_crl(CMS_ContentInfo *cms, X509_CRL *crl)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
CMS_RevocationInfoChoice *rch;
|
|
|
|
rch = CMS_add0_RevocationInfoChoice(cms);
|
|
|
|
if (!rch)
|
|
|
|
return 0;
|
|
|
|
rch->type = CMS_REVCHOICE_CRL;
|
|
|
|
rch->d.crl = crl;
|
|
|
|
return 1;
|
|
|
|
}
|
2008-03-13 05:14:28 +08:00
|
|
|
|
2008-05-03 01:27:01 +08:00
|
|
|
int CMS_add1_crl(CMS_ContentInfo *cms, X509_CRL *crl)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
int r;
|
|
|
|
r = CMS_add0_crl(cms, crl);
|
|
|
|
if (r > 0)
|
2015-09-01 03:30:20 +08:00
|
|
|
X509_CRL_up_ref(crl);
|
2015-01-22 11:40:55 +08:00
|
|
|
return r;
|
|
|
|
}
|
2008-05-03 01:27:01 +08:00
|
|
|
|
2008-03-13 05:14:28 +08:00
|
|
|
STACK_OF(X509) *CMS_get1_certs(CMS_ContentInfo *cms)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
STACK_OF(X509) *certs = NULL;
|
|
|
|
CMS_CertificateChoices *cch;
|
|
|
|
STACK_OF(CMS_CertificateChoices) **pcerts;
|
|
|
|
int i;
|
2019-09-17 03:28:57 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
pcerts = cms_get0_certificate_choices(cms);
|
2019-09-17 03:28:57 +08:00
|
|
|
if (pcerts == NULL)
|
2015-01-22 11:40:55 +08:00
|
|
|
return NULL;
|
|
|
|
for (i = 0; i < sk_CMS_CertificateChoices_num(*pcerts); i++) {
|
|
|
|
cch = sk_CMS_CertificateChoices_value(*pcerts, i);
|
|
|
|
if (cch->type == 0) {
|
2021-02-17 19:29:39 +08:00
|
|
|
if (!ossl_x509_add_cert_new(&certs, cch->d.certificate,
|
|
|
|
X509_ADD_FLAG_UP_REF)) {
|
2015-01-22 11:40:55 +08:00
|
|
|
sk_X509_pop_free(certs, X509_free);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return certs;
|
|
|
|
|
|
|
|
}
|
2008-03-13 05:14:28 +08:00
|
|
|
|
|
|
|
STACK_OF(X509_CRL) *CMS_get1_crls(CMS_ContentInfo *cms)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
STACK_OF(X509_CRL) *crls = NULL;
|
|
|
|
STACK_OF(CMS_RevocationInfoChoice) **pcrls;
|
|
|
|
CMS_RevocationInfoChoice *rch;
|
|
|
|
int i;
|
2019-09-17 03:28:57 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
pcrls = cms_get0_revocation_choices(cms);
|
2019-09-17 03:28:57 +08:00
|
|
|
if (pcrls == NULL)
|
2015-01-22 11:40:55 +08:00
|
|
|
return NULL;
|
|
|
|
for (i = 0; i < sk_CMS_RevocationInfoChoice_num(*pcrls); i++) {
|
|
|
|
rch = sk_CMS_RevocationInfoChoice_value(*pcrls, i);
|
|
|
|
if (rch->type == 0) {
|
|
|
|
if (!crls) {
|
|
|
|
crls = sk_X509_CRL_new_null();
|
|
|
|
if (!crls)
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (!sk_X509_CRL_push(crls, rch->d.crl)) {
|
|
|
|
sk_X509_CRL_pop_free(crls, X509_CRL_free);
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-09-01 03:30:20 +08:00
|
|
|
X509_CRL_up_ref(rch->d.crl);
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return crls;
|
|
|
|
}
|
2013-07-17 21:36:39 +08:00
|
|
|
|
2021-02-18 12:03:25 +08:00
|
|
|
int ossl_cms_ias_cert_cmp(CMS_IssuerAndSerialNumber *ias, X509 *cert)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
ret = X509_NAME_cmp(ias->issuer, X509_get_issuer_name(cert));
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2020-07-13 23:13:48 +08:00
|
|
|
return ASN1_INTEGER_cmp(ias->serialNumber, X509_get0_serialNumber(cert));
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
2013-07-17 21:36:39 +08:00
|
|
|
|
2021-02-18 12:03:25 +08:00
|
|
|
int ossl_cms_keyid_cert_cmp(ASN1_OCTET_STRING *keyid, X509 *cert)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
2015-09-22 22:19:32 +08:00
|
|
|
const ASN1_OCTET_STRING *cert_keyid = X509_get0_subject_key_id(cert);
|
|
|
|
|
|
|
|
if (cert_keyid == NULL)
|
2015-01-22 11:40:55 +08:00
|
|
|
return -1;
|
2015-09-22 22:19:32 +08:00
|
|
|
return ASN1_OCTET_STRING_cmp(keyid, cert_keyid);
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
2013-07-17 21:36:39 +08:00
|
|
|
|
2021-02-18 12:03:25 +08:00
|
|
|
int ossl_cms_set1_ias(CMS_IssuerAndSerialNumber **pias, X509 *cert)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
CMS_IssuerAndSerialNumber *ias;
|
|
|
|
ias = M_ASN1_new_of(CMS_IssuerAndSerialNumber);
|
|
|
|
if (!ias)
|
|
|
|
goto err;
|
|
|
|
if (!X509_NAME_set(&ias->issuer, X509_get_issuer_name(cert)))
|
|
|
|
goto err;
|
2020-07-13 23:13:48 +08:00
|
|
|
if (!ASN1_STRING_copy(ias->serialNumber, X509_get0_serialNumber(cert)))
|
2015-01-22 11:40:55 +08:00
|
|
|
goto err;
|
2015-04-30 23:30:03 +08:00
|
|
|
M_ASN1_free_of(*pias, CMS_IssuerAndSerialNumber);
|
2015-01-22 11:40:55 +08:00
|
|
|
*pias = ias;
|
|
|
|
return 1;
|
|
|
|
err:
|
2015-04-30 23:30:03 +08:00
|
|
|
M_ASN1_free_of(ias, CMS_IssuerAndSerialNumber);
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE);
|
2015-01-22 11:40:55 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2013-07-17 21:36:39 +08:00
|
|
|
|
2021-02-18 12:03:25 +08:00
|
|
|
int ossl_cms_set1_keyid(ASN1_OCTET_STRING **pkeyid, X509 *cert)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
ASN1_OCTET_STRING *keyid = NULL;
|
2015-09-22 22:19:32 +08:00
|
|
|
const ASN1_OCTET_STRING *cert_keyid;
|
|
|
|
cert_keyid = X509_get0_subject_key_id(cert);
|
|
|
|
if (cert_keyid == NULL) {
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_CMS, CMS_R_CERTIFICATE_HAS_NO_KEYID);
|
2015-01-22 11:40:55 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2015-09-22 22:19:32 +08:00
|
|
|
keyid = ASN1_STRING_dup(cert_keyid);
|
2015-01-22 11:40:55 +08:00
|
|
|
if (!keyid) {
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE);
|
2015-01-22 11:40:55 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2015-04-30 23:30:03 +08:00
|
|
|
ASN1_OCTET_STRING_free(*pkeyid);
|
2015-01-22 11:40:55 +08:00
|
|
|
*pkeyid = keyid;
|
|
|
|
return 1;
|
|
|
|
}
|