Coverage Report

Created: 2024-07-27 06:39

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