Coverage Report

Created: 2025-12-31 06:58

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl30/crypto/cms/cms_sd.c
Line
Count
Source
1
/*
2
 * Copyright 2008-2023 The OpenSSL Project Authors. All Rights Reserved.
3
 *
4
 * Licensed under the Apache License 2.0 (the "License").  You may not use
5
 * this file except in compliance with the License.  You can obtain a copy
6
 * in the file LICENSE in the source distribution or at
7
 * https://www.openssl.org/source/license.html
8
 */
9
10
#include "internal/cryptlib.h"
11
#include <openssl/asn1t.h>
12
#include <openssl/pem.h>
13
#include <openssl/x509.h>
14
#include <openssl/x509v3.h>
15
#include <openssl/err.h>
16
#include <openssl/cms.h>
17
#include <openssl/ess.h>
18
#include "internal/sizes.h"
19
#include "crypto/asn1.h"
20
#include "crypto/evp.h"
21
#include "crypto/ess.h"
22
#include "crypto/x509.h" /* for ossl_x509_add_cert_new() */
23
#include "cms_local.h"
24
25
/* CMS SignedData Utilities */
26
27
static CMS_SignedData *cms_get0_signed(CMS_ContentInfo *cms)
28
6.85k
{
29
6.85k
    if (OBJ_obj2nid(cms->contentType) != NID_pkcs7_signed) {
30
5.29k
        ERR_raise(ERR_LIB_CMS, CMS_R_CONTENT_TYPE_NOT_SIGNED_DATA);
31
5.29k
        return NULL;
32
5.29k
    }
33
1.56k
    return cms->d.signedData;
34
6.85k
}
35
36
static CMS_SignedData *cms_signed_data_init(CMS_ContentInfo *cms)
37
0
{
38
0
    if (cms->d.other == NULL) {
39
0
        cms->d.signedData = M_ASN1_new_of(CMS_SignedData);
40
0
        if (!cms->d.signedData) {
41
0
            ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE);
42
0
            return NULL;
43
0
        }
44
0
        cms->d.signedData->version = 1;
45
0
        cms->d.signedData->encapContentInfo->eContentType = OBJ_nid2obj(NID_pkcs7_data);
46
0
        cms->d.signedData->encapContentInfo->partial = 1;
47
0
        ASN1_OBJECT_free(cms->contentType);
48
0
        cms->contentType = OBJ_nid2obj(NID_pkcs7_signed);
49
0
        return cms->d.signedData;
50
0
    }
51
0
    return cms_get0_signed(cms);
52
0
}
53
54
/* Just initialise SignedData e.g. for certs only structure */
55
56
int CMS_SignedData_init(CMS_ContentInfo *cms)
57
0
{
58
0
    if (cms_signed_data_init(cms))
59
0
        return 1;
60
0
    else
61
0
        return 0;
62
0
}
63
64
/* Check structures and fixup version numbers (if necessary) */
65
66
static void cms_sd_set_version(CMS_SignedData *sd)
67
0
{
68
0
    int i;
69
0
    CMS_CertificateChoices *cch;
70
0
    CMS_RevocationInfoChoice *rch;
71
0
    CMS_SignerInfo *si;
72
73
0
    for (i = 0; i < sk_CMS_CertificateChoices_num(sd->certificates); i++) {
74
0
        cch = sk_CMS_CertificateChoices_value(sd->certificates, i);
75
0
        if (cch->type == CMS_CERTCHOICE_OTHER) {
76
0
            if (sd->version < 5)
77
0
                sd->version = 5;
78
0
        } else if (cch->type == CMS_CERTCHOICE_V2ACERT) {
79
0
            if (sd->version < 4)
80
0
                sd->version = 4;
81
0
        } else if (cch->type == CMS_CERTCHOICE_V1ACERT) {
82
0
            if (sd->version < 3)
83
0
                sd->version = 3;
84
0
        }
85
0
    }
86
87
0
    for (i = 0; i < sk_CMS_RevocationInfoChoice_num(sd->crls); i++) {
88
0
        rch = sk_CMS_RevocationInfoChoice_value(sd->crls, i);
89
0
        if (rch->type == CMS_REVCHOICE_OTHER) {
90
0
            if (sd->version < 5)
91
0
                sd->version = 5;
92
0
        }
93
0
    }
94
95
0
    if ((OBJ_obj2nid(sd->encapContentInfo->eContentType) != NID_pkcs7_data)
96
0
        && (sd->version < 3))
97
0
        sd->version = 3;
98
99
0
    for (i = 0; i < sk_CMS_SignerInfo_num(sd->signerInfos); i++) {
100
0
        si = sk_CMS_SignerInfo_value(sd->signerInfos, i);
101
0
        if (si->sid->type == CMS_SIGNERINFO_KEYIDENTIFIER) {
102
0
            if (si->version < 3)
103
0
                si->version = 3;
104
0
            if (sd->version < 3)
105
0
                sd->version = 3;
106
0
        } else if (si->version < 1)
107
0
            si->version = 1;
108
0
    }
109
110
0
    if (sd->version < 1)
111
0
        sd->version = 1;
112
0
}
113
114
/*
115
 * RFC 5652 Section 11.1 Content Type
116
 * The content-type attribute within signed-data MUST
117
 *   1) be present if there are signed attributes
118
 *   2) match the content type in the signed-data,
119
 *   3) be a signed attribute.
120
 *   4) not have more than one copy of the attribute.
121
 *
122
 * Note that since the CMS_SignerInfo_sign() always adds the "signing time"
123
 * attribute, the content type attribute MUST be added also.
124
 * Assumptions: This assumes that the attribute does not already exist.
125
 */
126
static int cms_set_si_contentType_attr(CMS_ContentInfo *cms, CMS_SignerInfo *si)
127
0
{
128
0
    ASN1_OBJECT *ctype = cms->d.signedData->encapContentInfo->eContentType;
129
130
    /* Add the contentType attribute */
131
0
    return CMS_signed_add1_attr_by_NID(si, NID_pkcs9_contentType,
132
0
               V_ASN1_OBJECT, ctype, -1)
133
0
        > 0;
134
0
}
135
136
/* Copy an existing messageDigest value */
137
138
static int cms_copy_messageDigest(CMS_ContentInfo *cms, CMS_SignerInfo *si)
139
0
{
140
0
    STACK_OF(CMS_SignerInfo) *sinfos;
141
0
    CMS_SignerInfo *sitmp;
142
0
    int i;
143
144
0
    sinfos = CMS_get0_SignerInfos(cms);
145
0
    for (i = 0; i < sk_CMS_SignerInfo_num(sinfos); i++) {
146
0
        ASN1_OCTET_STRING *messageDigest;
147
148
0
        sitmp = sk_CMS_SignerInfo_value(sinfos, i);
149
0
        if (sitmp == si)
150
0
            continue;
151
0
        if (CMS_signed_get_attr_count(sitmp) < 0)
152
0
            continue;
153
0
        if (OBJ_cmp(si->digestAlgorithm->algorithm,
154
0
                sitmp->digestAlgorithm->algorithm))
155
0
            continue;
156
0
        messageDigest = CMS_signed_get0_data_by_OBJ(sitmp,
157
0
            OBJ_nid2obj(NID_pkcs9_messageDigest),
158
0
            -3, V_ASN1_OCTET_STRING);
159
0
        if (!messageDigest) {
160
0
            ERR_raise(ERR_LIB_CMS, CMS_R_ERROR_READING_MESSAGEDIGEST_ATTRIBUTE);
161
0
            return 0;
162
0
        }
163
164
0
        if (CMS_signed_add1_attr_by_NID(si, NID_pkcs9_messageDigest,
165
0
                V_ASN1_OCTET_STRING,
166
0
                messageDigest, -1))
167
0
            return 1;
168
0
        else
169
0
            return 0;
170
0
    }
171
0
    ERR_raise(ERR_LIB_CMS, CMS_R_NO_MATCHING_DIGEST);
172
0
    return 0;
173
0
}
174
175
int ossl_cms_set1_SignerIdentifier(CMS_SignerIdentifier *sid, X509 *cert,
176
    int type, const CMS_CTX *ctx)
177
0
{
178
0
    switch (type) {
179
0
    case CMS_SIGNERINFO_ISSUER_SERIAL:
180
0
        if (!ossl_cms_set1_ias(&sid->d.issuerAndSerialNumber, cert))
181
0
            return 0;
182
0
        break;
183
184
0
    case CMS_SIGNERINFO_KEYIDENTIFIER:
185
0
        if (!ossl_cms_set1_keyid(&sid->d.subjectKeyIdentifier, cert))
186
0
            return 0;
187
0
        break;
188
189
0
    default:
190
0
        ERR_raise(ERR_LIB_CMS, CMS_R_UNKNOWN_ID);
191
0
        return 0;
192
0
    }
193
194
0
    sid->type = type;
195
196
0
    return 1;
197
0
}
198
199
int ossl_cms_SignerIdentifier_get0_signer_id(CMS_SignerIdentifier *sid,
200
    ASN1_OCTET_STRING **keyid,
201
    X509_NAME **issuer,
202
    ASN1_INTEGER **sno)
203
0
{
204
0
    if (sid->type == CMS_SIGNERINFO_ISSUER_SERIAL) {
205
0
        if (issuer)
206
0
            *issuer = sid->d.issuerAndSerialNumber->issuer;
207
0
        if (sno)
208
0
            *sno = sid->d.issuerAndSerialNumber->serialNumber;
209
0
    } else if (sid->type == CMS_SIGNERINFO_KEYIDENTIFIER) {
210
0
        if (keyid)
211
0
            *keyid = sid->d.subjectKeyIdentifier;
212
0
    } else
213
0
        return 0;
214
0
    return 1;
215
0
}
216
217
int ossl_cms_SignerIdentifier_cert_cmp(CMS_SignerIdentifier *sid, X509 *cert)
218
0
{
219
0
    if (sid->type == CMS_SIGNERINFO_ISSUER_SERIAL)
220
0
        return ossl_cms_ias_cert_cmp(sid->d.issuerAndSerialNumber, cert);
221
0
    else if (sid->type == CMS_SIGNERINFO_KEYIDENTIFIER)
222
0
        return ossl_cms_keyid_cert_cmp(sid->d.subjectKeyIdentifier, cert);
223
0
    else
224
0
        return -1;
225
0
}
226
227
static int cms_sd_asn1_ctrl(CMS_SignerInfo *si, int cmd)
228
0
{
229
0
    EVP_PKEY *pkey = si->pkey;
230
0
    int i;
231
232
0
    if (EVP_PKEY_is_a(pkey, "DSA") || EVP_PKEY_is_a(pkey, "EC"))
233
0
        return ossl_cms_ecdsa_dsa_sign(si, cmd) > 0;
234
0
    else if (EVP_PKEY_is_a(pkey, "RSA") || EVP_PKEY_is_a(pkey, "RSA-PSS"))
235
0
        return ossl_cms_rsa_sign(si, cmd) > 0;
236
237
    /* Something else? We'll give engines etc a chance to handle this */
238
0
    if (pkey->ameth == NULL || pkey->ameth->pkey_ctrl == NULL)
239
0
        return 1;
240
0
    i = pkey->ameth->pkey_ctrl(pkey, ASN1_PKEY_CTRL_CMS_SIGN, cmd, si);
241
0
    if (i == -2) {
242
0
        ERR_raise(ERR_LIB_CMS, CMS_R_NOT_SUPPORTED_FOR_THIS_KEY_TYPE);
243
0
        return 0;
244
0
    }
245
0
    if (i <= 0) {
246
0
        ERR_raise(ERR_LIB_CMS, CMS_R_CTRL_FAILURE);
247
0
        return 0;
248
0
    }
249
0
    return 1;
250
0
}
251
252
/* Add SigningCertificate signed attribute to the signer info. */
253
static int ossl_cms_add1_signing_cert(CMS_SignerInfo *si,
254
    const ESS_SIGNING_CERT *sc)
255
0
{
256
0
    ASN1_STRING *seq = NULL;
257
0
    unsigned char *p, *pp = NULL;
258
0
    int ret, len = i2d_ESS_SIGNING_CERT(sc, NULL);
259
260
0
    if (len <= 0 || (pp = OPENSSL_malloc(len)) == NULL)
261
0
        return 0;
262
263
0
    p = pp;
264
0
    i2d_ESS_SIGNING_CERT(sc, &p);
265
0
    if (!(seq = ASN1_STRING_new()) || !ASN1_STRING_set(seq, pp, len)) {
266
0
        ASN1_STRING_free(seq);
267
0
        OPENSSL_free(pp);
268
0
        return 0;
269
0
    }
270
0
    OPENSSL_free(pp);
271
0
    ret = CMS_signed_add1_attr_by_NID(si, NID_id_smime_aa_signingCertificate,
272
0
        V_ASN1_SEQUENCE, seq, -1);
273
0
    ASN1_STRING_free(seq);
274
0
    return ret;
275
0
}
276
277
/* Add SigningCertificateV2 signed attribute to the signer info. */
278
static int ossl_cms_add1_signing_cert_v2(CMS_SignerInfo *si,
279
    const ESS_SIGNING_CERT_V2 *sc)
280
0
{
281
0
    ASN1_STRING *seq = NULL;
282
0
    unsigned char *p, *pp = NULL;
283
0
    int ret, len = i2d_ESS_SIGNING_CERT_V2(sc, NULL);
284
285
0
    if (len <= 0 || (pp = OPENSSL_malloc(len)) == NULL)
286
0
        return 0;
287
288
0
    p = pp;
289
0
    i2d_ESS_SIGNING_CERT_V2(sc, &p);
290
0
    if (!(seq = ASN1_STRING_new()) || !ASN1_STRING_set(seq, pp, len)) {
291
0
        ASN1_STRING_free(seq);
292
0
        OPENSSL_free(pp);
293
0
        return 0;
294
0
    }
295
0
    OPENSSL_free(pp);
296
0
    ret = CMS_signed_add1_attr_by_NID(si, NID_id_smime_aa_signingCertificateV2,
297
0
        V_ASN1_SEQUENCE, seq, -1);
298
0
    ASN1_STRING_free(seq);
299
0
    return ret;
300
0
}
301
302
CMS_SignerInfo *CMS_add1_signer(CMS_ContentInfo *cms,
303
    X509 *signer, EVP_PKEY *pk, const EVP_MD *md,
304
    unsigned int flags)
305
0
{
306
0
    CMS_SignedData *sd;
307
0
    CMS_SignerInfo *si = NULL;
308
0
    X509_ALGOR *alg;
309
0
    int i, type;
310
0
    const CMS_CTX *ctx = ossl_cms_get0_cmsctx(cms);
311
312
0
    if (!X509_check_private_key(signer, pk)) {
313
0
        ERR_raise(ERR_LIB_CMS, CMS_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE);
314
0
        return NULL;
315
0
    }
316
0
    sd = cms_signed_data_init(cms);
317
0
    if (!sd)
318
0
        goto err;
319
0
    si = M_ASN1_new_of(CMS_SignerInfo);
320
0
    if (!si)
321
0
        goto merr;
322
    /* Call for side-effect of computing hash and caching extensions */
323
0
    X509_check_purpose(signer, -1, -1);
324
325
0
    X509_up_ref(signer);
326
0
    EVP_PKEY_up_ref(pk);
327
328
0
    si->cms_ctx = ctx;
329
0
    si->pkey = pk;
330
0
    si->signer = signer;
331
0
    si->mctx = EVP_MD_CTX_new();
332
0
    si->pctx = NULL;
333
334
0
    if (si->mctx == NULL) {
335
0
        ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE);
336
0
        goto err;
337
0
    }
338
339
0
    if (flags & CMS_USE_KEYID) {
340
0
        si->version = 3;
341
0
        if (sd->version < 3)
342
0
            sd->version = 3;
343
0
        type = CMS_SIGNERINFO_KEYIDENTIFIER;
344
0
    } else {
345
0
        type = CMS_SIGNERINFO_ISSUER_SERIAL;
346
0
        si->version = 1;
347
0
    }
348
349
0
    if (!ossl_cms_set1_SignerIdentifier(si->sid, signer, type, ctx))
350
0
        goto err;
351
352
0
    if (md == NULL) {
353
0
        int def_nid;
354
355
0
        if (EVP_PKEY_get_default_digest_nid(pk, &def_nid) <= 0) {
356
0
            ERR_raise_data(ERR_LIB_CMS, CMS_R_NO_DEFAULT_DIGEST,
357
0
                "pkey nid=%d", EVP_PKEY_get_id(pk));
358
0
            goto err;
359
0
        }
360
0
        md = EVP_get_digestbynid(def_nid);
361
0
        if (md == NULL) {
362
0
            ERR_raise_data(ERR_LIB_CMS, CMS_R_NO_DEFAULT_DIGEST,
363
0
                "default md nid=%d", def_nid);
364
0
            goto err;
365
0
        }
366
0
    }
367
368
0
    if (!md) {
369
0
        ERR_raise(ERR_LIB_CMS, CMS_R_NO_DIGEST_SET);
370
0
        goto err;
371
0
    }
372
373
0
    if (md == NULL) {
374
0
        ERR_raise(ERR_LIB_CMS, CMS_R_NO_DIGEST_SET);
375
0
        goto err;
376
0
    }
377
378
0
    X509_ALGOR_set_md(si->digestAlgorithm, md);
379
380
    /* See if digest is present in digestAlgorithms */
381
0
    for (i = 0; i < sk_X509_ALGOR_num(sd->digestAlgorithms); i++) {
382
0
        const ASN1_OBJECT *aoid;
383
0
        char name[OSSL_MAX_NAME_SIZE];
384
385
0
        alg = sk_X509_ALGOR_value(sd->digestAlgorithms, i);
386
0
        X509_ALGOR_get0(&aoid, NULL, NULL, alg);
387
0
        OBJ_obj2txt(name, sizeof(name), aoid, 0);
388
0
        if (EVP_MD_is_a(md, name))
389
0
            break;
390
0
    }
391
392
0
    if (i == sk_X509_ALGOR_num(sd->digestAlgorithms)) {
393
0
        alg = X509_ALGOR_new();
394
0
        if (alg == NULL)
395
0
            goto merr;
396
0
        X509_ALGOR_set_md(alg, md);
397
0
        if (!sk_X509_ALGOR_push(sd->digestAlgorithms, alg)) {
398
0
            X509_ALGOR_free(alg);
399
0
            goto merr;
400
0
        }
401
0
    }
402
403
0
    if (!(flags & CMS_KEY_PARAM) && !cms_sd_asn1_ctrl(si, 0)) {
404
0
        ERR_raise_data(ERR_LIB_CMS, CMS_R_UNSUPPORTED_SIGNATURE_ALGORITHM,
405
0
            "pkey nid=%d", EVP_PKEY_get_id(pk));
406
0
        goto err;
407
0
    }
408
0
    if (!(flags & CMS_NOATTR)) {
409
        /*
410
         * Initialize signed attributes structure so other attributes
411
         * such as signing time etc are added later even if we add none here.
412
         */
413
0
        if (!si->signedAttrs) {
414
0
            si->signedAttrs = sk_X509_ATTRIBUTE_new_null();
415
0
            if (!si->signedAttrs)
416
0
                goto merr;
417
0
        }
418
419
0
        if (!(flags & CMS_NOSMIMECAP)) {
420
0
            STACK_OF(X509_ALGOR) *smcap = NULL;
421
0
            i = CMS_add_standard_smimecap(&smcap);
422
0
            if (i)
423
0
                i = CMS_add_smimecap(si, smcap);
424
0
            sk_X509_ALGOR_pop_free(smcap, X509_ALGOR_free);
425
0
            if (!i)
426
0
                goto merr;
427
0
        }
428
0
        if (flags & CMS_CADES) {
429
0
            ESS_SIGNING_CERT *sc = NULL;
430
0
            ESS_SIGNING_CERT_V2 *sc2 = NULL;
431
0
            int add_sc;
432
433
0
            if (md == NULL || EVP_MD_is_a(md, SN_sha1)) {
434
0
                if ((sc = OSSL_ESS_signing_cert_new_init(signer,
435
0
                         NULL, 1))
436
0
                    == NULL)
437
0
                    goto err;
438
0
                add_sc = ossl_cms_add1_signing_cert(si, sc);
439
0
                ESS_SIGNING_CERT_free(sc);
440
0
            } else {
441
0
                if ((sc2 = OSSL_ESS_signing_cert_v2_new_init(md, signer,
442
0
                         NULL, 1))
443
0
                    == NULL)
444
0
                    goto err;
445
0
                add_sc = ossl_cms_add1_signing_cert_v2(si, sc2);
446
0
                ESS_SIGNING_CERT_V2_free(sc2);
447
0
            }
448
0
            if (!add_sc)
449
0
                goto err;
450
0
        }
451
0
        if (flags & CMS_REUSE_DIGEST) {
452
0
            if (!cms_copy_messageDigest(cms, si))
453
0
                goto err;
454
0
            if (!cms_set_si_contentType_attr(cms, si))
455
0
                goto err;
456
0
            if (!(flags & (CMS_PARTIAL | CMS_KEY_PARAM)) && !CMS_SignerInfo_sign(si))
457
0
                goto err;
458
0
        }
459
0
    }
460
461
0
    if (!(flags & CMS_NOCERTS)) {
462
        /* NB ignore -1 return for duplicate cert */
463
0
        if (!CMS_add1_cert(cms, signer))
464
0
            goto merr;
465
0
    }
466
467
0
    if (flags & CMS_KEY_PARAM) {
468
0
        if (flags & CMS_NOATTR) {
469
0
            si->pctx = EVP_PKEY_CTX_new_from_pkey(ossl_cms_ctx_get0_libctx(ctx),
470
0
                si->pkey,
471
0
                ossl_cms_ctx_get0_propq(ctx));
472
0
            if (si->pctx == NULL)
473
0
                goto err;
474
0
            if (EVP_PKEY_sign_init(si->pctx) <= 0)
475
0
                goto err;
476
0
            if (EVP_PKEY_CTX_set_signature_md(si->pctx, md) <= 0)
477
0
                goto err;
478
0
        } else if (EVP_DigestSignInit_ex(si->mctx, &si->pctx,
479
0
                       EVP_MD_get0_name(md),
480
0
                       ossl_cms_ctx_get0_libctx(ctx),
481
0
                       ossl_cms_ctx_get0_propq(ctx),
482
0
                       pk, NULL)
483
0
            <= 0) {
484
0
            si->pctx = NULL;
485
0
            goto err;
486
0
        } else {
487
0
            EVP_MD_CTX_set_flags(si->mctx, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX);
488
0
        }
489
0
    }
490
491
0
    if (!sd->signerInfos)
492
0
        sd->signerInfos = sk_CMS_SignerInfo_new_null();
493
0
    if (!sd->signerInfos || !sk_CMS_SignerInfo_push(sd->signerInfos, si))
494
0
        goto merr;
495
496
0
    return si;
497
498
0
merr:
499
0
    ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE);
500
0
err:
501
0
    M_ASN1_free_of(si, CMS_SignerInfo);
502
0
    return NULL;
503
0
}
504
505
void ossl_cms_SignerInfos_set_cmsctx(CMS_ContentInfo *cms)
506
6.85k
{
507
6.85k
    int i;
508
6.85k
    CMS_SignerInfo *si;
509
6.85k
    STACK_OF(CMS_SignerInfo) *sinfos;
510
6.85k
    const CMS_CTX *ctx = ossl_cms_get0_cmsctx(cms);
511
512
6.85k
    ERR_set_mark();
513
6.85k
    sinfos = CMS_get0_SignerInfos(cms);
514
6.85k
    ERR_pop_to_mark(); /* removes error in case sinfos == NULL */
515
516
14.9k
    for (i = 0; i < sk_CMS_SignerInfo_num(sinfos); i++) {
517
8.08k
        si = sk_CMS_SignerInfo_value(sinfos, i);
518
8.08k
        if (si != NULL)
519
8.08k
            si->cms_ctx = ctx;
520
8.08k
    }
521
6.85k
}
522
523
static int cms_add1_signingTime(CMS_SignerInfo *si, ASN1_TIME *t)
524
0
{
525
0
    ASN1_TIME *tt;
526
0
    int r = 0;
527
528
0
    if (t != NULL)
529
0
        tt = t;
530
0
    else
531
0
        tt = X509_gmtime_adj(NULL, 0);
532
533
0
    if (tt == NULL)
534
0
        goto merr;
535
536
0
    if (CMS_signed_add1_attr_by_NID(si, NID_pkcs9_signingTime,
537
0
            tt->type, tt, -1)
538
0
        <= 0)
539
0
        goto merr;
540
541
0
    r = 1;
542
0
merr:
543
0
    if (t == NULL)
544
0
        ASN1_TIME_free(tt);
545
546
0
    if (!r)
547
0
        ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE);
548
549
0
    return r;
550
0
}
551
552
EVP_PKEY_CTX *CMS_SignerInfo_get0_pkey_ctx(CMS_SignerInfo *si)
553
0
{
554
0
    return si->pctx;
555
0
}
556
557
EVP_MD_CTX *CMS_SignerInfo_get0_md_ctx(CMS_SignerInfo *si)
558
0
{
559
0
    return si->mctx;
560
0
}
561
562
STACK_OF(CMS_SignerInfo) *CMS_get0_SignerInfos(CMS_ContentInfo *cms)
563
6.85k
{
564
6.85k
    CMS_SignedData *sd = cms_get0_signed(cms);
565
566
6.85k
    return sd != NULL ? sd->signerInfos : NULL;
567
6.85k
}
568
569
STACK_OF(X509) *CMS_get0_signers(CMS_ContentInfo *cms)
570
0
{
571
0
    STACK_OF(X509) *signers = NULL;
572
0
    STACK_OF(CMS_SignerInfo) *sinfos;
573
0
    CMS_SignerInfo *si;
574
0
    int i;
575
576
0
    sinfos = CMS_get0_SignerInfos(cms);
577
0
    for (i = 0; i < sk_CMS_SignerInfo_num(sinfos); i++) {
578
0
        si = sk_CMS_SignerInfo_value(sinfos, i);
579
0
        if (si->signer != NULL) {
580
0
            if (!ossl_x509_add_cert_new(&signers, si->signer,
581
0
                    X509_ADD_FLAG_DEFAULT)) {
582
0
                sk_X509_free(signers);
583
0
                return NULL;
584
0
            }
585
0
        }
586
0
    }
587
0
    return signers;
588
0
}
589
590
void CMS_SignerInfo_set1_signer_cert(CMS_SignerInfo *si, X509 *signer)
591
0
{
592
0
    if (signer != NULL) {
593
0
        X509_up_ref(signer);
594
0
        EVP_PKEY_free(si->pkey);
595
0
        si->pkey = X509_get_pubkey(signer);
596
0
    }
597
0
    X509_free(si->signer);
598
0
    si->signer = signer;
599
0
}
600
601
int CMS_SignerInfo_get0_signer_id(CMS_SignerInfo *si,
602
    ASN1_OCTET_STRING **keyid,
603
    X509_NAME **issuer, ASN1_INTEGER **sno)
604
0
{
605
0
    return ossl_cms_SignerIdentifier_get0_signer_id(si->sid, keyid, issuer, sno);
606
0
}
607
608
int CMS_SignerInfo_cert_cmp(CMS_SignerInfo *si, X509 *cert)
609
0
{
610
0
    return ossl_cms_SignerIdentifier_cert_cmp(si->sid, cert);
611
0
}
612
613
int CMS_set1_signers_certs(CMS_ContentInfo *cms, STACK_OF(X509) *scerts,
614
    unsigned int flags)
615
0
{
616
0
    CMS_SignedData *sd;
617
0
    CMS_SignerInfo *si;
618
0
    CMS_CertificateChoices *cch;
619
0
    STACK_OF(CMS_CertificateChoices) *certs;
620
0
    X509 *x;
621
0
    int i, j;
622
0
    int ret = 0;
623
624
0
    sd = cms_get0_signed(cms);
625
0
    if (sd == NULL)
626
0
        return -1;
627
0
    certs = sd->certificates;
628
0
    for (i = 0; i < sk_CMS_SignerInfo_num(sd->signerInfos); i++) {
629
0
        si = sk_CMS_SignerInfo_value(sd->signerInfos, i);
630
0
        if (si->signer != NULL)
631
0
            continue;
632
633
0
        for (j = 0; j < sk_X509_num(scerts); j++) {
634
0
            x = sk_X509_value(scerts, j);
635
0
            if (CMS_SignerInfo_cert_cmp(si, x) == 0) {
636
0
                CMS_SignerInfo_set1_signer_cert(si, x);
637
0
                ret++;
638
0
                break;
639
0
            }
640
0
        }
641
642
0
        if (si->signer != NULL || (flags & CMS_NOINTERN))
643
0
            continue;
644
645
0
        for (j = 0; j < sk_CMS_CertificateChoices_num(certs); j++) {
646
0
            cch = sk_CMS_CertificateChoices_value(certs, j);
647
0
            if (cch->type != 0)
648
0
                continue;
649
0
            x = cch->d.certificate;
650
0
            if (CMS_SignerInfo_cert_cmp(si, x) == 0) {
651
0
                CMS_SignerInfo_set1_signer_cert(si, x);
652
0
                ret++;
653
0
                break;
654
0
            }
655
0
        }
656
0
    }
657
0
    return ret;
658
0
}
659
660
void CMS_SignerInfo_get0_algs(CMS_SignerInfo *si, EVP_PKEY **pk,
661
    X509 **signer, X509_ALGOR **pdig,
662
    X509_ALGOR **psig)
663
0
{
664
0
    if (pk != NULL)
665
0
        *pk = si->pkey;
666
0
    if (signer != NULL)
667
0
        *signer = si->signer;
668
0
    if (pdig != NULL)
669
0
        *pdig = si->digestAlgorithm;
670
0
    if (psig != NULL)
671
0
        *psig = si->signatureAlgorithm;
672
0
}
673
674
ASN1_OCTET_STRING *CMS_SignerInfo_get0_signature(CMS_SignerInfo *si)
675
0
{
676
0
    return si->signature;
677
0
}
678
679
static int cms_SignerInfo_content_sign(CMS_ContentInfo *cms,
680
    CMS_SignerInfo *si, BIO *chain)
681
0
{
682
0
    EVP_MD_CTX *mctx = EVP_MD_CTX_new();
683
0
    int r = 0;
684
0
    EVP_PKEY_CTX *pctx = NULL;
685
0
    const CMS_CTX *ctx = ossl_cms_get0_cmsctx(cms);
686
687
0
    if (mctx == NULL) {
688
0
        ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE);
689
0
        return 0;
690
0
    }
691
692
0
    if (si->pkey == NULL) {
693
0
        ERR_raise(ERR_LIB_CMS, CMS_R_NO_PRIVATE_KEY);
694
0
        goto err;
695
0
    }
696
697
0
    if (!ossl_cms_DigestAlgorithm_find_ctx(mctx, chain, si->digestAlgorithm))
698
0
        goto err;
699
    /* Set SignerInfo algorithm details if we used custom parameter */
700
0
    if (si->pctx && !cms_sd_asn1_ctrl(si, 0))
701
0
        goto err;
702
703
    /*
704
     * If any signed attributes calculate and add messageDigest attribute
705
     */
706
707
0
    if (CMS_signed_get_attr_count(si) >= 0) {
708
0
        unsigned char md[EVP_MAX_MD_SIZE];
709
0
        unsigned int mdlen;
710
711
0
        if (!EVP_DigestFinal_ex(mctx, md, &mdlen))
712
0
            goto err;
713
0
        if (!CMS_signed_add1_attr_by_NID(si, NID_pkcs9_messageDigest,
714
0
                V_ASN1_OCTET_STRING, md, mdlen))
715
0
            goto err;
716
        /* Copy content type across */
717
0
        if (!cms_set_si_contentType_attr(cms, si))
718
0
            goto err;
719
720
0
        if (!CMS_SignerInfo_sign(si))
721
0
            goto err;
722
0
    } else if (si->pctx) {
723
0
        unsigned char *sig;
724
0
        size_t siglen;
725
0
        unsigned char md[EVP_MAX_MD_SIZE];
726
0
        unsigned int mdlen;
727
728
0
        pctx = si->pctx;
729
0
        si->pctx = NULL;
730
0
        if (!EVP_DigestFinal_ex(mctx, md, &mdlen))
731
0
            goto err;
732
0
        siglen = EVP_PKEY_get_size(si->pkey);
733
0
        sig = OPENSSL_malloc(siglen);
734
0
        if (sig == NULL) {
735
0
            ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE);
736
0
            goto err;
737
0
        }
738
0
        if (EVP_PKEY_sign(pctx, sig, &siglen, md, mdlen) <= 0) {
739
0
            OPENSSL_free(sig);
740
0
            goto err;
741
0
        }
742
0
        ASN1_STRING_set0(si->signature, sig, siglen);
743
0
    } else {
744
0
        unsigned char *sig;
745
0
        unsigned int siglen;
746
747
0
        sig = OPENSSL_malloc(EVP_PKEY_get_size(si->pkey));
748
0
        if (sig == NULL) {
749
0
            ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE);
750
0
            goto err;
751
0
        }
752
0
        if (!EVP_SignFinal_ex(mctx, sig, &siglen, si->pkey,
753
0
                ossl_cms_ctx_get0_libctx(ctx),
754
0
                ossl_cms_ctx_get0_propq(ctx))) {
755
0
            ERR_raise(ERR_LIB_CMS, CMS_R_SIGNFINAL_ERROR);
756
0
            OPENSSL_free(sig);
757
0
            goto err;
758
0
        }
759
0
        ASN1_STRING_set0(si->signature, sig, siglen);
760
0
    }
761
762
0
    r = 1;
763
764
0
err:
765
0
    EVP_MD_CTX_free(mctx);
766
0
    EVP_PKEY_CTX_free(pctx);
767
0
    return r;
768
0
}
769
770
int ossl_cms_SignedData_final(CMS_ContentInfo *cms, BIO *chain)
771
0
{
772
0
    STACK_OF(CMS_SignerInfo) *sinfos;
773
0
    CMS_SignerInfo *si;
774
0
    int i;
775
776
0
    sinfos = CMS_get0_SignerInfos(cms);
777
0
    for (i = 0; i < sk_CMS_SignerInfo_num(sinfos); i++) {
778
0
        si = sk_CMS_SignerInfo_value(sinfos, i);
779
0
        if (!cms_SignerInfo_content_sign(cms, si, chain))
780
0
            return 0;
781
0
    }
782
0
    cms->d.signedData->encapContentInfo->partial = 0;
783
0
    return 1;
784
0
}
785
786
int CMS_SignerInfo_sign(CMS_SignerInfo *si)
787
0
{
788
0
    EVP_MD_CTX *mctx = si->mctx;
789
0
    EVP_PKEY_CTX *pctx = NULL;
790
0
    unsigned char *abuf = NULL;
791
0
    int alen;
792
0
    size_t siglen;
793
0
    const CMS_CTX *ctx = si->cms_ctx;
794
0
    char md_name[OSSL_MAX_NAME_SIZE];
795
796
0
    if (OBJ_obj2txt(md_name, sizeof(md_name),
797
0
            si->digestAlgorithm->algorithm, 0)
798
0
        <= 0)
799
0
        return 0;
800
801
0
    if (CMS_signed_get_attr_by_NID(si, NID_pkcs9_signingTime, -1) < 0) {
802
0
        if (!cms_add1_signingTime(si, NULL))
803
0
            goto err;
804
0
    }
805
806
0
    if (!ossl_cms_si_check_attributes(si))
807
0
        goto err;
808
809
0
    if (si->pctx)
810
0
        pctx = si->pctx;
811
0
    else {
812
0
        EVP_MD_CTX_reset(mctx);
813
0
        if (EVP_DigestSignInit_ex(mctx, &pctx, md_name,
814
0
                ossl_cms_ctx_get0_libctx(ctx),
815
0
                ossl_cms_ctx_get0_propq(ctx), si->pkey,
816
0
                NULL)
817
0
            <= 0)
818
0
            goto err;
819
0
        EVP_MD_CTX_set_flags(mctx, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX);
820
0
        si->pctx = pctx;
821
0
    }
822
823
0
    alen = ASN1_item_i2d((ASN1_VALUE *)si->signedAttrs, &abuf,
824
0
        ASN1_ITEM_rptr(CMS_Attributes_Sign));
825
0
    if (!abuf)
826
0
        goto err;
827
0
    if (EVP_DigestSignUpdate(mctx, abuf, alen) <= 0)
828
0
        goto err;
829
0
    if (EVP_DigestSignFinal(mctx, NULL, &siglen) <= 0)
830
0
        goto err;
831
0
    OPENSSL_free(abuf);
832
0
    abuf = OPENSSL_malloc(siglen);
833
0
    if (abuf == NULL)
834
0
        goto err;
835
0
    if (EVP_DigestSignFinal(mctx, abuf, &siglen) <= 0)
836
0
        goto err;
837
838
0
    EVP_MD_CTX_reset(mctx);
839
840
0
    ASN1_STRING_set0(si->signature, abuf, siglen);
841
842
0
    return 1;
843
844
0
err:
845
0
    OPENSSL_free(abuf);
846
0
    EVP_MD_CTX_reset(mctx);
847
0
    return 0;
848
0
}
849
850
int CMS_SignerInfo_verify(CMS_SignerInfo *si)
851
0
{
852
0
    EVP_MD_CTX *mctx = NULL;
853
0
    unsigned char *abuf = NULL;
854
0
    int alen, r = -1;
855
0
    char name[OSSL_MAX_NAME_SIZE];
856
0
    const EVP_MD *md;
857
0
    EVP_MD *fetched_md = NULL;
858
0
    const CMS_CTX *ctx = si->cms_ctx;
859
0
    OSSL_LIB_CTX *libctx = ossl_cms_ctx_get0_libctx(ctx);
860
0
    const char *propq = ossl_cms_ctx_get0_propq(ctx);
861
862
0
    if (si->pkey == NULL) {
863
0
        ERR_raise(ERR_LIB_CMS, CMS_R_NO_PUBLIC_KEY);
864
0
        return -1;
865
0
    }
866
867
0
    if (!ossl_cms_si_check_attributes(si))
868
0
        return -1;
869
870
0
    OBJ_obj2txt(name, sizeof(name), si->digestAlgorithm->algorithm, 0);
871
872
0
    (void)ERR_set_mark();
873
0
    fetched_md = EVP_MD_fetch(libctx, name, propq);
874
875
0
    if (fetched_md != NULL)
876
0
        md = fetched_md;
877
0
    else
878
0
        md = EVP_get_digestbyobj(si->digestAlgorithm->algorithm);
879
0
    if (md == NULL) {
880
0
        (void)ERR_clear_last_mark();
881
0
        ERR_raise(ERR_LIB_CMS, CMS_R_UNKNOWN_DIGEST_ALGORITHM);
882
0
        return -1;
883
0
    }
884
0
    (void)ERR_pop_to_mark();
885
886
0
    if (si->mctx == NULL && (si->mctx = EVP_MD_CTX_new()) == NULL) {
887
0
        ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE);
888
0
        goto err;
889
0
    }
890
0
    mctx = si->mctx;
891
0
    if (si->pctx != NULL) {
892
0
        EVP_PKEY_CTX_free(si->pctx);
893
0
        si->pctx = NULL;
894
0
    }
895
0
    if (EVP_DigestVerifyInit_ex(mctx, &si->pctx, EVP_MD_get0_name(md), libctx,
896
0
            propq, si->pkey, NULL)
897
0
        <= 0) {
898
0
        si->pctx = NULL;
899
0
        goto err;
900
0
    }
901
0
    EVP_MD_CTX_set_flags(mctx, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX);
902
903
0
    if (!cms_sd_asn1_ctrl(si, 1))
904
0
        goto err;
905
906
0
    alen = ASN1_item_i2d((ASN1_VALUE *)si->signedAttrs, &abuf,
907
0
        ASN1_ITEM_rptr(CMS_Attributes_Verify));
908
0
    if (abuf == NULL || alen < 0)
909
0
        goto err;
910
0
    r = EVP_DigestVerifyUpdate(mctx, abuf, alen);
911
0
    OPENSSL_free(abuf);
912
0
    if (r <= 0) {
913
0
        r = -1;
914
0
        goto err;
915
0
    }
916
0
    r = EVP_DigestVerifyFinal(mctx,
917
0
        si->signature->data, si->signature->length);
918
0
    if (r <= 0)
919
0
        ERR_raise(ERR_LIB_CMS, CMS_R_VERIFICATION_FAILURE);
920
0
err:
921
0
    EVP_MD_free(fetched_md);
922
0
    EVP_MD_CTX_reset(mctx);
923
0
    return r;
924
0
}
925
926
/* Create a chain of digest BIOs from a CMS ContentInfo */
927
928
BIO *ossl_cms_SignedData_init_bio(CMS_ContentInfo *cms)
929
0
{
930
0
    int i;
931
0
    CMS_SignedData *sd;
932
0
    BIO *chain = NULL;
933
934
0
    sd = cms_get0_signed(cms);
935
0
    if (sd == NULL)
936
0
        return NULL;
937
0
    if (cms->d.signedData->encapContentInfo->partial)
938
0
        cms_sd_set_version(sd);
939
0
    for (i = 0; i < sk_X509_ALGOR_num(sd->digestAlgorithms); i++) {
940
0
        X509_ALGOR *digestAlgorithm;
941
0
        BIO *mdbio;
942
943
0
        digestAlgorithm = sk_X509_ALGOR_value(sd->digestAlgorithms, i);
944
0
        mdbio = ossl_cms_DigestAlgorithm_init_bio(digestAlgorithm,
945
0
            ossl_cms_get0_cmsctx(cms));
946
0
        if (mdbio == NULL)
947
0
            goto err;
948
0
        if (chain != NULL)
949
0
            BIO_push(chain, mdbio);
950
0
        else
951
0
            chain = mdbio;
952
0
    }
953
0
    return chain;
954
0
err:
955
0
    BIO_free_all(chain);
956
0
    return NULL;
957
0
}
958
959
int CMS_SignerInfo_verify_content(CMS_SignerInfo *si, BIO *chain)
960
0
{
961
0
    ASN1_OCTET_STRING *os = NULL;
962
0
    EVP_MD_CTX *mctx = EVP_MD_CTX_new();
963
0
    EVP_PKEY_CTX *pkctx = NULL;
964
0
    int r = -1;
965
0
    unsigned char mval[EVP_MAX_MD_SIZE];
966
0
    unsigned int mlen;
967
968
0
    if (mctx == NULL) {
969
0
        ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE);
970
0
        goto err;
971
0
    }
972
    /* If we have any signed attributes look for messageDigest value */
973
0
    if (CMS_signed_get_attr_count(si) >= 0) {
974
0
        os = CMS_signed_get0_data_by_OBJ(si,
975
0
            OBJ_nid2obj(NID_pkcs9_messageDigest),
976
0
            -3, V_ASN1_OCTET_STRING);
977
0
        if (os == NULL) {
978
0
            ERR_raise(ERR_LIB_CMS, CMS_R_ERROR_READING_MESSAGEDIGEST_ATTRIBUTE);
979
0
            goto err;
980
0
        }
981
0
    }
982
983
0
    if (!ossl_cms_DigestAlgorithm_find_ctx(mctx, chain, si->digestAlgorithm))
984
0
        goto err;
985
986
0
    if (EVP_DigestFinal_ex(mctx, mval, &mlen) <= 0) {
987
0
        ERR_raise(ERR_LIB_CMS, CMS_R_UNABLE_TO_FINALIZE_CONTEXT);
988
0
        goto err;
989
0
    }
990
991
    /* If messageDigest found compare it */
992
993
0
    if (os != NULL) {
994
0
        if (mlen != (unsigned int)os->length) {
995
0
            ERR_raise(ERR_LIB_CMS, CMS_R_MESSAGEDIGEST_ATTRIBUTE_WRONG_LENGTH);
996
0
            goto err;
997
0
        }
998
999
0
        if (memcmp(mval, os->data, mlen)) {
1000
0
            ERR_raise(ERR_LIB_CMS, CMS_R_VERIFICATION_FAILURE);
1001
0
            r = 0;
1002
0
        } else
1003
0
            r = 1;
1004
0
    } else {
1005
0
        const EVP_MD *md = EVP_MD_CTX_get0_md(mctx);
1006
0
        const CMS_CTX *ctx = si->cms_ctx;
1007
1008
0
        pkctx = EVP_PKEY_CTX_new_from_pkey(ossl_cms_ctx_get0_libctx(ctx),
1009
0
            si->pkey,
1010
0
            ossl_cms_ctx_get0_propq(ctx));
1011
0
        if (pkctx == NULL)
1012
0
            goto err;
1013
0
        if (EVP_PKEY_verify_init(pkctx) <= 0)
1014
0
            goto err;
1015
0
        if (EVP_PKEY_CTX_set_signature_md(pkctx, md) <= 0)
1016
0
            goto err;
1017
0
        si->pctx = pkctx;
1018
0
        if (!cms_sd_asn1_ctrl(si, 1)) {
1019
0
            si->pctx = NULL;
1020
0
            goto err;
1021
0
        }
1022
0
        si->pctx = NULL;
1023
0
        r = EVP_PKEY_verify(pkctx, si->signature->data,
1024
0
            si->signature->length, mval, mlen);
1025
0
        if (r <= 0) {
1026
0
            ERR_raise(ERR_LIB_CMS, CMS_R_VERIFICATION_FAILURE);
1027
0
            r = 0;
1028
0
        }
1029
0
    }
1030
1031
0
err:
1032
0
    EVP_PKEY_CTX_free(pkctx);
1033
0
    EVP_MD_CTX_free(mctx);
1034
0
    return r;
1035
0
}
1036
1037
int CMS_add_smimecap(CMS_SignerInfo *si, STACK_OF(X509_ALGOR) *algs)
1038
0
{
1039
0
    unsigned char *smder = NULL;
1040
0
    int smderlen, r;
1041
1042
0
    smderlen = i2d_X509_ALGORS(algs, &smder);
1043
0
    if (smderlen <= 0)
1044
0
        return 0;
1045
0
    r = CMS_signed_add1_attr_by_NID(si, NID_SMIMECapabilities,
1046
0
        V_ASN1_SEQUENCE, smder, smderlen);
1047
0
    OPENSSL_free(smder);
1048
0
    return r;
1049
0
}
1050
1051
int CMS_add_simple_smimecap(STACK_OF(X509_ALGOR) **algs,
1052
    int algnid, int keysize)
1053
0
{
1054
0
    X509_ALGOR *alg = NULL;
1055
0
    ASN1_INTEGER *key = NULL;
1056
1057
0
    if (keysize > 0) {
1058
0
        key = ASN1_INTEGER_new();
1059
0
        if (key == NULL || !ASN1_INTEGER_set(key, keysize))
1060
0
            goto err;
1061
0
    }
1062
0
    alg = X509_ALGOR_new();
1063
0
    if (alg == NULL)
1064
0
        goto err;
1065
1066
0
    if (!X509_ALGOR_set0(alg, OBJ_nid2obj(algnid),
1067
0
            key ? V_ASN1_INTEGER : V_ASN1_UNDEF, key))
1068
0
        goto err;
1069
0
    key = NULL;
1070
0
    if (*algs == NULL)
1071
0
        *algs = sk_X509_ALGOR_new_null();
1072
0
    if (*algs == NULL || !sk_X509_ALGOR_push(*algs, alg))
1073
0
        goto err;
1074
0
    return 1;
1075
1076
0
err:
1077
0
    ASN1_INTEGER_free(key);
1078
0
    X509_ALGOR_free(alg);
1079
0
    return 0;
1080
0
}
1081
1082
/* Check to see if a cipher exists and if so add S/MIME capabilities */
1083
1084
static int cms_add_cipher_smcap(STACK_OF(X509_ALGOR) **sk, int nid, int arg)
1085
0
{
1086
0
    if (EVP_get_cipherbynid(nid))
1087
0
        return CMS_add_simple_smimecap(sk, nid, arg);
1088
0
    return 1;
1089
0
}
1090
1091
static int cms_add_digest_smcap(STACK_OF(X509_ALGOR) **sk, int nid, int arg)
1092
0
{
1093
0
    if (EVP_get_digestbynid(nid))
1094
0
        return CMS_add_simple_smimecap(sk, nid, arg);
1095
0
    return 1;
1096
0
}
1097
1098
int CMS_add_standard_smimecap(STACK_OF(X509_ALGOR) **smcap)
1099
0
{
1100
0
    if (!cms_add_cipher_smcap(smcap, NID_aes_256_cbc, -1)
1101
0
        || !cms_add_digest_smcap(smcap, NID_id_GostR3411_2012_256, -1)
1102
0
        || !cms_add_digest_smcap(smcap, NID_id_GostR3411_2012_512, -1)
1103
0
        || !cms_add_digest_smcap(smcap, NID_id_GostR3411_94, -1)
1104
0
        || !cms_add_cipher_smcap(smcap, NID_id_Gost28147_89, -1)
1105
0
        || !cms_add_cipher_smcap(smcap, NID_aes_192_cbc, -1)
1106
0
        || !cms_add_cipher_smcap(smcap, NID_aes_128_cbc, -1)
1107
0
        || !cms_add_cipher_smcap(smcap, NID_des_ede3_cbc, -1)
1108
0
        || !cms_add_cipher_smcap(smcap, NID_rc2_cbc, 128)
1109
0
        || !cms_add_cipher_smcap(smcap, NID_rc2_cbc, 64)
1110
0
        || !cms_add_cipher_smcap(smcap, NID_des_cbc, -1)
1111
0
        || !cms_add_cipher_smcap(smcap, NID_rc2_cbc, 40))
1112
0
        return 0;
1113
0
    return 1;
1114
0
}