OpenCoverage

cms_smime.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/cms/cms_smime.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/*-
2 * Copyright 2008-2018 The OpenSSL Project Authors. All Rights Reserved.-
3 *-
4 * Licensed under the OpenSSL license (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/x509.h>-
13#include <openssl/x509v3.h>-
14#include <openssl/err.h>-
15#include <openssl/cms.h>-
16#include "cms_lcl.h"-
17#include "internal/asn1_int.h"-
18-
19static BIO *cms_get_text_bio(BIO *out, unsigned int flags)-
20{-
21 BIO *rbio;-
22 if (out == NULL)
out == ((void *)0)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 55 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
1-55
23 rbio = BIO_new(BIO_s_null());
executed 1 time by 1 test: rbio = BIO_new(BIO_s_null());
Executed by:
  • libcrypto.so.1.1
1
24 else if (flags & CMS_TEXT) {
flags & 0x1Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 54 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
1-54
25 rbio = BIO_new(BIO_s_mem());-
26 BIO_set_mem_eof_return(rbio, 0);-
27 } else
executed 1 time by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
1
28 rbio = out;
executed 54 times by 1 test: rbio = out;
Executed by:
  • libcrypto.so.1.1
54
29 return rbio;
executed 56 times by 1 test: return rbio;
Executed by:
  • libcrypto.so.1.1
56
30}-
31-
32static int cms_copy_content(BIO *out, BIO *in, unsigned int flags)-
33{-
34 unsigned char buf[4096];-
35 int r = 0, i;-
36 BIO *tmpout;-
37-
38 tmpout = cms_get_text_bio(out, flags);-
39-
40 if (tmpout == NULL) {
tmpout == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 46 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-46
41 CMSerr(CMS_F_CMS_COPY_CONTENT, ERR_R_MALLOC_FAILURE);-
42 goto err;
never executed: goto err;
0
43 }-
44-
45 /* Read all content through chain to process digest, decrypt etc */-
46 for (;;) {-
47 i = BIO_read(in, buf, sizeof(buf));-
48 if (i <= 0) {
i <= 0Description
TRUEevaluated 46 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 46 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
46
49 if (BIO_method_type(in) == BIO_TYPE_CIPHER) {
BIO_method_typ...== (10|0x0200)Description
TRUEevaluated 24 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 22 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
22-24
50 if (!BIO_get_cipher_status(in))
!BIO_ctrl(in,1... ((void *)0) )Description
TRUEnever evaluated
FALSEevaluated 24 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-24
51 goto err;
never executed: goto err;
0
52 }
executed 24 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
24
53 if (i < 0)
i < 0Description
TRUEnever evaluated
FALSEevaluated 46 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-46
54 goto err;
never executed: goto err;
0
55 break;
executed 46 times by 1 test: break;
Executed by:
  • libcrypto.so.1.1
46
56 }-
57-
58 if (tmpout && (BIO_write(tmpout, buf, i) != i))
tmpoutDescription
TRUEevaluated 46 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
(BIO_write(tmp... buf, i) != i)Description
TRUEnever evaluated
FALSEevaluated 46 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-46
59 goto err;
never executed: goto err;
0
60 }
executed 46 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
46
61-
62 if (flags & CMS_TEXT) {
flags & 0x1Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 45 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
1-45
63 if (!SMIME_text(tmpout, out)) {
!SMIME_text(tmpout, out)Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1
64 CMSerr(CMS_F_CMS_COPY_CONTENT, CMS_R_SMIME_TEXT_ERROR);-
65 goto err;
never executed: goto err;
0
66 }-
67 }
executed 1 time by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
1
68-
69 r = 1;-
70-
71 err:
code before this statement executed 46 times by 1 test: err:
Executed by:
  • libcrypto.so.1.1
46
72 if (tmpout != out)
tmpout != outDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 44 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
2-44
73 BIO_free(tmpout);
executed 2 times by 1 test: BIO_free(tmpout);
Executed by:
  • libcrypto.so.1.1
2
74 return r;
executed 46 times by 1 test: return r;
Executed by:
  • libcrypto.so.1.1
46
75-
76}-
77-
78static int check_content(CMS_ContentInfo *cms)-
79{-
80 ASN1_OCTET_STRING **pos = CMS_get0_content(cms);-
81 if (!pos || !*pos) {
!posDescription
TRUEnever evaluated
FALSEevaluated 45 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
!*posDescription
TRUEnever evaluated
FALSEevaluated 45 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-45
82 CMSerr(CMS_F_CHECK_CONTENT, CMS_R_NO_CONTENT);-
83 return 0;
never executed: return 0;
0
84 }-
85 return 1;
executed 45 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
45
86}-
87-
88static void do_free_upto(BIO *f, BIO *upto)-
89{-
90 if (upto) {
uptoDescription
TRUEevaluated 10 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 38 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
10-38
91 BIO *tbio;-
92 do {-
93 tbio = BIO_pop(f);-
94 BIO_free(f);-
95 f = tbio;-
96 }
executed 10 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
10
97 while (f && f != upto);
fDescription
TRUEevaluated 10 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
f != uptoDescription
TRUEnever evaluated
FALSEevaluated 10 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-10
98 } else
executed 10 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
10
99 BIO_free_all(f);
executed 38 times by 1 test: BIO_free_all(f);
Executed by:
  • libcrypto.so.1.1
38
100}-
101-
102int CMS_data(CMS_ContentInfo *cms, BIO *out, unsigned int flags)-
103{-
104 BIO *cont;-
105 int r;-
106 if (OBJ_obj2nid(CMS_get0_type(cms)) != NID_pkcs7_data) {
OBJ_obj2nid(CM...pe(cms)) != 21Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1
107 CMSerr(CMS_F_CMS_DATA, CMS_R_TYPE_NOT_DATA);-
108 return 0;
never executed: return 0;
0
109 }-
110 cont = CMS_dataInit(cms, NULL);-
111 if (!cont)
!contDescription
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1
112 return 0;
never executed: return 0;
0
113 r = cms_copy_content(out, cont, flags);-
114 BIO_free_all(cont);-
115 return r;
executed 1 time by 1 test: return r;
Executed by:
  • libcrypto.so.1.1
1
116}-
117-
118CMS_ContentInfo *CMS_data_create(BIO *in, unsigned int flags)-
119{-
120 CMS_ContentInfo *cms;-
121 cms = cms_Data_create();-
122 if (!cms)
!cmsDescription
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1
123 return NULL;
never executed: return ((void *)0) ;
0
124-
125 if ((flags & CMS_STREAM) || CMS_final(cms, in, NULL, flags))
(flags & 0x1000)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
CMS_final(cms,... *)0) , flags)Description
TRUEnever evaluated
FALSEnever evaluated
0-1
126 return cms;
executed 1 time by 1 test: return cms;
Executed by:
  • libcrypto.so.1.1
1
127-
128 CMS_ContentInfo_free(cms);-
129-
130 return NULL;
never executed: return ((void *)0) ;
0
131}-
132-
133int CMS_digest_verify(CMS_ContentInfo *cms, BIO *dcont, BIO *out,-
134 unsigned int flags)-
135{-
136 BIO *cont;-
137 int r;-
138 if (OBJ_obj2nid(CMS_get0_type(cms)) != NID_pkcs7_digest) {
OBJ_obj2nid(CM...pe(cms)) != 25Description
TRUEnever evaluated
FALSEnever evaluated
0
139 CMSerr(CMS_F_CMS_DIGEST_VERIFY, CMS_R_TYPE_NOT_DIGESTED_DATA);-
140 return 0;
never executed: return 0;
0
141 }-
142-
143 if (!dcont && !check_content(cms))
!dcontDescription
TRUEnever evaluated
FALSEnever evaluated
!check_content(cms)Description
TRUEnever evaluated
FALSEnever evaluated
0
144 return 0;
never executed: return 0;
0
145-
146 cont = CMS_dataInit(cms, dcont);-
147 if (!cont)
!contDescription
TRUEnever evaluated
FALSEnever evaluated
0
148 return 0;
never executed: return 0;
0
149 r = cms_copy_content(out, cont, flags);-
150 if (r)
rDescription
TRUEnever evaluated
FALSEnever evaluated
0
151 r = cms_DigestedData_do_final(cms, cont, 1);
never executed: r = cms_DigestedData_do_final(cms, cont, 1);
0
152 do_free_upto(cont, dcont);-
153 return r;
never executed: return r;
0
154}-
155-
156CMS_ContentInfo *CMS_digest_create(BIO *in, const EVP_MD *md,-
157 unsigned int flags)-
158{-
159 CMS_ContentInfo *cms;-
160 if (!md)
!mdDescription
TRUEnever evaluated
FALSEnever evaluated
0
161 md = EVP_sha1();
never executed: md = EVP_sha1();
0
162 cms = cms_DigestedData_create(md);-
163 if (!cms)
!cmsDescription
TRUEnever evaluated
FALSEnever evaluated
0
164 return NULL;
never executed: return ((void *)0) ;
0
165-
166 if (!(flags & CMS_DETACHED))
!(flags & 0x40)Description
TRUEnever evaluated
FALSEnever evaluated
0
167 CMS_set_detached(cms, 0);
never executed: CMS_set_detached(cms, 0);
0
168-
169 if ((flags & CMS_STREAM) || CMS_final(cms, in, NULL, flags))
(flags & 0x1000)Description
TRUEnever evaluated
FALSEnever evaluated
CMS_final(cms,... *)0) , flags)Description
TRUEnever evaluated
FALSEnever evaluated
0
170 return cms;
never executed: return cms;
0
171-
172 CMS_ContentInfo_free(cms);-
173 return NULL;
never executed: return ((void *)0) ;
0
174}-
175-
176int CMS_EncryptedData_decrypt(CMS_ContentInfo *cms,-
177 const unsigned char *key, size_t keylen,-
178 BIO *dcont, BIO *out, unsigned int flags)-
179{-
180 BIO *cont;-
181 int r;-
182 if (OBJ_obj2nid(CMS_get0_type(cms)) != NID_pkcs7_encrypted) {
OBJ_obj2nid(CM...pe(cms)) != 26Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4
183 CMSerr(CMS_F_CMS_ENCRYPTEDDATA_DECRYPT,-
184 CMS_R_TYPE_NOT_ENCRYPTED_DATA);-
185 return 0;
never executed: return 0;
0
186 }-
187-
188 if (!dcont && !check_content(cms))
!dcontDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
!check_content(cms)Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4
189 return 0;
never executed: return 0;
0
190-
191 if (CMS_EncryptedData_set1_key(cms, NULL, key, keylen) <= 0)
CMS_EncryptedD..., keylen) <= 0Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4
192 return 0;
never executed: return 0;
0
193 cont = CMS_dataInit(cms, dcont);-
194 if (!cont)
!contDescription
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4
195 return 0;
never executed: return 0;
0
196 r = cms_copy_content(out, cont, flags);-
197 do_free_upto(cont, dcont);-
198 return r;
executed 4 times by 1 test: return r;
Executed by:
  • libcrypto.so.1.1
4
199}-
200-
201CMS_ContentInfo *CMS_EncryptedData_encrypt(BIO *in, const EVP_CIPHER *cipher,-
202 const unsigned char *key,-
203 size_t keylen, unsigned int flags)-
204{-
205 CMS_ContentInfo *cms;-
206 if (!cipher) {
!cipherDescription
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4
207 CMSerr(CMS_F_CMS_ENCRYPTEDDATA_ENCRYPT, CMS_R_NO_CIPHER);-
208 return NULL;
never executed: return ((void *)0) ;
0
209 }-
210 cms = CMS_ContentInfo_new();-
211 if (cms == NULL)
cms == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4
212 return NULL;
never executed: return ((void *)0) ;
0
213 if (!CMS_EncryptedData_set1_key(cms, cipher, key, keylen))
!CMS_Encrypted..., key, keylen)Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4
214 return NULL;
never executed: return ((void *)0) ;
0
215-
216 if (!(flags & CMS_DETACHED))
!(flags & 0x40)Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-4
217 CMS_set_detached(cms, 0);
executed 4 times by 1 test: CMS_set_detached(cms, 0);
Executed by:
  • libcrypto.so.1.1
4
218-
219 if ((flags & (CMS_STREAM | CMS_PARTIAL))
(flags & (0x1000 | 0x4000))Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-4
220 || CMS_final(cms, in, NULL, flags))
CMS_final(cms,... *)0) , flags)Description
TRUEnever evaluated
FALSEnever evaluated
0
221 return cms;
executed 4 times by 1 test: return cms;
Executed by:
  • libcrypto.so.1.1
4
222-
223 CMS_ContentInfo_free(cms);-
224 return NULL;
never executed: return ((void *)0) ;
0
225}-
226-
227static int cms_signerinfo_verify_cert(CMS_SignerInfo *si,-
228 X509_STORE *store,-
229 STACK_OF(X509) *certs,-
230 STACK_OF(X509_CRL) *crls)-
231{-
232 X509_STORE_CTX *ctx = X509_STORE_CTX_new();-
233 X509 *signer;-
234 int i, j, r = 0;-
235-
236 if (ctx == NULL) {
ctx == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 63 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-63
237 CMSerr(CMS_F_CMS_SIGNERINFO_VERIFY_CERT, ERR_R_MALLOC_FAILURE);-
238 goto err;
never executed: goto err;
0
239 }-
240 CMS_SignerInfo_get0_algs(si, NULL, &signer, NULL, NULL);-
241 if (!X509_STORE_CTX_init(ctx, store, signer, certs)) {
!X509_STORE_CT...signer, certs)Description
TRUEnever evaluated
FALSEevaluated 63 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-63
242 CMSerr(CMS_F_CMS_SIGNERINFO_VERIFY_CERT, CMS_R_STORE_INIT_ERROR);-
243 goto err;
never executed: goto err;
0
244 }-
245 X509_STORE_CTX_set_default(ctx, "smime_sign");-
246 if (crls)
crlsDescription
TRUEnever evaluated
FALSEevaluated 63 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-63
247 X509_STORE_CTX_set0_crls(ctx, crls);
never executed: X509_STORE_CTX_set0_crls(ctx, crls);
0
248-
249 i = X509_verify_cert(ctx);-
250 if (i <= 0) {
i <= 0Description
TRUEnever evaluated
FALSEevaluated 63 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-63
251 j = X509_STORE_CTX_get_error(ctx);-
252 CMSerr(CMS_F_CMS_SIGNERINFO_VERIFY_CERT,-
253 CMS_R_CERTIFICATE_VERIFY_ERROR);-
254 ERR_add_error_data(2, "Verify error:",-
255 X509_verify_cert_error_string(j));-
256 goto err;
never executed: goto err;
0
257 }-
258 r = 1;-
259 err:
code before this statement executed 63 times by 1 test: err:
Executed by:
  • libcrypto.so.1.1
63
260 X509_STORE_CTX_free(ctx);-
261 return r;
executed 63 times by 1 test: return r;
Executed by:
  • libcrypto.so.1.1
63
262-
263}-
264-
265int CMS_verify(CMS_ContentInfo *cms, STACK_OF(X509) *certs,-
266 X509_STORE *store, BIO *dcont, BIO *out, unsigned int flags)-
267{-
268 CMS_SignerInfo *si;-
269 STACK_OF(CMS_SignerInfo) *sinfos;-
270 STACK_OF(X509) *cms_certs = NULL;-
271 STACK_OF(X509_CRL) *crls = NULL;-
272 X509 *signer;-
273 int i, scount = 0, ret = 0;-
274 BIO *cmsbio = NULL, *tmpin = NULL, *tmpout = NULL;-
275-
276 if (!dcont && !check_content(cms))
!dcontDescription
TRUEevaluated 21 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 10 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
!check_content(cms)Description
TRUEnever evaluated
FALSEevaluated 21 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-21
277 return 0;
never executed: return 0;
0
278 if (dcont && !(flags & CMS_BINARY)) {
dcontDescription
TRUEevaluated 10 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 21 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
!(flags & 0x80)Description
TRUEevaluated 10 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-21
279 const ASN1_OBJECT *coid = CMS_get0_eContentType(cms);-
280 if (OBJ_obj2nid(coid) == NID_id_ct_asciiTextWithCRLF)
OBJ_obj2nid(coid) == 787Description
TRUEnever evaluated
FALSEevaluated 10 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-10
281 flags |= CMS_ASCIICRLF;
never executed: flags |= 0x80000;
0
282 }
executed 10 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
10
283-
284 /* Attempt to find all signer certificates */-
285-
286 sinfos = CMS_get0_SignerInfos(cms);-
287-
288 if (sk_CMS_SignerInfo_num(sinfos) <= 0) {
sk_CMS_SignerI...m(sinfos) <= 0Description
TRUEnever evaluated
FALSEevaluated 31 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-31
289 CMSerr(CMS_F_CMS_VERIFY, CMS_R_NO_SIGNERS);-
290 goto err;
never executed: goto err;
0
291 }-
292-
293 for (i = 0; i < sk_CMS_SignerInfo_num(sinfos); i++) {
i < sk_CMS_Sig...fo_num(sinfos)Description
TRUEevaluated 63 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 31 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
31-63
294 si = sk_CMS_SignerInfo_value(sinfos, i);-
295 CMS_SignerInfo_get0_algs(si, NULL, &signer, NULL, NULL);-
296 if (signer)
signerDescription
TRUEnever evaluated
FALSEevaluated 63 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-63
297 scount++;
never executed: scount++;
0
298 }
executed 63 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
63
299-
300 if (scount != sk_CMS_SignerInfo_num(sinfos))
scount != sk_C...fo_num(sinfos)Description
TRUEevaluated 31 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-31
301 scount += CMS_set1_signers_certs(cms, certs, flags);
executed 31 times by 1 test: scount += CMS_set1_signers_certs(cms, certs, flags);
Executed by:
  • libcrypto.so.1.1
31
302-
303 if (scount != sk_CMS_SignerInfo_num(sinfos)) {
scount != sk_C...fo_num(sinfos)Description
TRUEnever evaluated
FALSEevaluated 31 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-31
304 CMSerr(CMS_F_CMS_VERIFY, CMS_R_SIGNER_CERTIFICATE_NOT_FOUND);-
305 goto err;
never executed: goto err;
0
306 }-
307-
308 /* Attempt to verify all signers certs */-
309-
310 if (!(flags & CMS_NO_SIGNER_CERT_VERIFY)) {
!(flags & 0x20)Description
TRUEevaluated 31 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-31
311 cms_certs = CMS_get1_certs(cms);-
312 if (!(flags & CMS_NOCRL))
!(flags & 0x2000)Description
TRUEevaluated 31 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-31
313 crls = CMS_get1_crls(cms);
executed 31 times by 1 test: crls = CMS_get1_crls(cms);
Executed by:
  • libcrypto.so.1.1
31
314 for (i = 0; i < sk_CMS_SignerInfo_num(sinfos); i++) {
i < sk_CMS_Sig...fo_num(sinfos)Description
TRUEevaluated 63 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 31 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
31-63
315 si = sk_CMS_SignerInfo_value(sinfos, i);-
316 if (!cms_signerinfo_verify_cert(si, store, cms_certs, crls))
!cms_signerinf...s_certs, crls)Description
TRUEnever evaluated
FALSEevaluated 63 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-63
317 goto err;
never executed: goto err;
0
318 }
executed 63 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
63
319 }
executed 31 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
31
320-
321 /* Attempt to verify all SignerInfo signed attribute signatures */-
322-
323 if (!(flags & CMS_NO_ATTR_VERIFY)) {
!(flags & 0x8)Description
TRUEevaluated 31 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-31
324 for (i = 0; i < sk_CMS_SignerInfo_num(sinfos); i++) {
i < sk_CMS_Sig...fo_num(sinfos)Description
TRUEevaluated 63 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 31 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
31-63
325 si = sk_CMS_SignerInfo_value(sinfos, i);-
326 if (CMS_signed_get_attr_count(si) < 0)
CMS_signed_get..._count(si) < 0Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 54 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
9-54
327 continue;
executed 9 times by 1 test: continue;
Executed by:
  • libcrypto.so.1.1
9
328 if (CMS_SignerInfo_verify(si) <= 0)
CMS_SignerInfo_verify(si) <= 0Description
TRUEnever evaluated
FALSEevaluated 54 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-54
329 goto err;
never executed: goto err;
0
330 }
executed 54 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
54
331 }
executed 31 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
31
332-
333 /*-
334 * Performance optimization: if the content is a memory BIO then store-
335 * its contents in a temporary read only memory BIO. This avoids-
336 * potentially large numbers of slow copies of data which will occur when-
337 * reading from a read write memory BIO when signatures are calculated.-
338 */-
339-
340 if (dcont && (BIO_method_type(dcont) == BIO_TYPE_MEM)) {
dcontDescription
TRUEevaluated 10 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 21 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
(BIO_method_ty...= ( 1|0x0400))Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 6 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
4-21
341 char *ptr;-
342 long len;-
343 len = BIO_get_mem_data(dcont, &ptr);-
344 tmpin = BIO_new_mem_buf(ptr, len);-
345 if (tmpin == NULL) {
tmpin == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4
346 CMSerr(CMS_F_CMS_VERIFY, ERR_R_MALLOC_FAILURE);-
347 goto err2;
never executed: goto err2;
0
348 }-
349 } else
executed 4 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
4
350 tmpin = dcont;
executed 27 times by 1 test: tmpin = dcont;
Executed by:
  • libcrypto.so.1.1
27
351 /*-
352 * If not binary mode and detached generate digests by *writing* through-
353 * the BIO. That makes it possible to canonicalise the input.-
354 */-
355 if (!(flags & SMIME_BINARY) && dcont) {
!(flags & 0x80)Description
TRUEevaluated 31 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
dcontDescription
TRUEevaluated 10 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 21 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-31
356 /*-
357 * Create output BIO so we can either handle text or to ensure-
358 * included content doesn't override detached content.-
359 */-
360 tmpout = cms_get_text_bio(out, flags);-
361 if (!tmpout) {
!tmpoutDescription
TRUEnever evaluated
FALSEevaluated 10 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-10
362 CMSerr(CMS_F_CMS_VERIFY, ERR_R_MALLOC_FAILURE);-
363 goto err;
never executed: goto err;
0
364 }-
365 cmsbio = CMS_dataInit(cms, tmpout);-
366 if (!cmsbio)
!cmsbioDescription
TRUEnever evaluated
FALSEevaluated 10 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-10
367 goto err;
never executed: goto err;
0
368 /*-
369 * Don't use SMIME_TEXT for verify: it adds headers and we want to-
370 * remove them.-
371 */-
372 SMIME_crlf_copy(dcont, cmsbio, flags & ~SMIME_TEXT);-
373-
374 if (flags & CMS_TEXT) {
flags & 0x1Description
TRUEnever evaluated
FALSEevaluated 10 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-10
375 if (!SMIME_text(tmpout, out)) {
!SMIME_text(tmpout, out)Description
TRUEnever evaluated
FALSEnever evaluated
0
376 CMSerr(CMS_F_CMS_VERIFY, CMS_R_SMIME_TEXT_ERROR);-
377 goto err;
never executed: goto err;
0
378 }-
379 }
never executed: end of block
0
380 } else {
executed 10 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
10
381 cmsbio = CMS_dataInit(cms, tmpin);-
382 if (!cmsbio)
!cmsbioDescription
TRUEnever evaluated
FALSEevaluated 21 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-21
383 goto err;
never executed: goto err;
0
384-
385 if (!cms_copy_content(out, cmsbio, flags))
!cms_copy_cont...cmsbio, flags)Description
TRUEnever evaluated
FALSEevaluated 21 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-21
386 goto err;
never executed: goto err;
0
387-
388 }
executed 21 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
21
389 if (!(flags & CMS_NO_CONTENT_VERIFY)) {
!(flags & 0x4)Description
TRUEevaluated 31 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-31
390 for (i = 0; i < sk_CMS_SignerInfo_num(sinfos); i++) {
i < sk_CMS_Sig...fo_num(sinfos)Description
TRUEevaluated 63 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 31 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
31-63
391 si = sk_CMS_SignerInfo_value(sinfos, i);-
392 if (CMS_SignerInfo_verify_content(si, cmsbio) <= 0) {
CMS_SignerInfo..., cmsbio) <= 0Description
TRUEnever evaluated
FALSEevaluated 63 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-63
393 CMSerr(CMS_F_CMS_VERIFY, CMS_R_CONTENT_VERIFY_ERROR);-
394 goto err;
never executed: goto err;
0
395 }-
396 }
executed 63 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
63
397 }
executed 31 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
31
398-
399 ret = 1;-
400-
401 err:
code before this statement executed 31 times by 1 test: err:
Executed by:
  • libcrypto.so.1.1
31
402 if (!(flags & SMIME_BINARY) && dcont) {
!(flags & 0x80)Description
TRUEevaluated 31 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
dcontDescription
TRUEevaluated 10 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 21 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-31
403 do_free_upto(cmsbio, tmpout);-
404 if (tmpin != dcont)
tmpin != dcontDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 6 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
4-6
405 BIO_free(tmpin);
executed 4 times by 1 test: BIO_free(tmpin);
Executed by:
  • libcrypto.so.1.1
4
406 } else {
executed 10 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
10
407 if (dcont && (tmpin == dcont))
dcontDescription
TRUEnever evaluated
FALSEevaluated 21 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
(tmpin == dcont)Description
TRUEnever evaluated
FALSEnever evaluated
0-21
408 do_free_upto(cmsbio, dcont);
never executed: do_free_upto(cmsbio, dcont);
0
409 else-
410 BIO_free_all(cmsbio);
executed 21 times by 1 test: BIO_free_all(cmsbio);
Executed by:
  • libcrypto.so.1.1
21
411 }-
412-
413 if (out != tmpout)
out != tmpoutDescription
TRUEevaluated 20 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 11 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
11-20
414 BIO_free_all(tmpout);
executed 20 times by 1 test: BIO_free_all(tmpout);
Executed by:
  • libcrypto.so.1.1
20
415-
416 err2:
code before this statement executed 31 times by 1 test: err2:
Executed by:
  • libcrypto.so.1.1
31
417 sk_X509_pop_free(cms_certs, X509_free);-
418 sk_X509_CRL_pop_free(crls, X509_CRL_free);-
419-
420 return ret;
executed 31 times by 1 test: return ret;
Executed by:
  • libcrypto.so.1.1
31
421}-
422-
423int CMS_verify_receipt(CMS_ContentInfo *rcms, CMS_ContentInfo *ocms,-
424 STACK_OF(X509) *certs,-
425 X509_STORE *store, unsigned int flags)-
426{-
427 int r;-
428 flags &= ~(CMS_DETACHED | CMS_TEXT);-
429 r = CMS_verify(rcms, certs, store, NULL, NULL, flags);-
430 if (r <= 0)
r <= 0Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1
431 return r;
never executed: return r;
0
432 return cms_Receipt_verify(rcms, ocms);
executed 1 time by 1 test: return cms_Receipt_verify(rcms, ocms);
Executed by:
  • libcrypto.so.1.1
1
433}-
434-
435CMS_ContentInfo *CMS_sign(X509 *signcert, EVP_PKEY *pkey,-
436 STACK_OF(X509) *certs, BIO *data,-
437 unsigned int flags)-
438{-
439 CMS_ContentInfo *cms;-
440 int i;-
441-
442 cms = CMS_ContentInfo_new();-
443 if (cms == NULL || !CMS_SignedData_init(cms))
cms == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 29 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
!CMS_SignedData_init(cms)Description
TRUEnever evaluated
FALSEevaluated 29 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-29
444 goto merr;
never executed: goto merr;
0
445 if (flags & CMS_ASCIICRLF
flags & 0x80000Description
TRUEnever evaluated
FALSEevaluated 29 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-29
446 && !CMS_set1_eContentType(cms,
!CMS_set1_eCon..._nid2obj(787))Description
TRUEnever evaluated
FALSEnever evaluated
0
447 OBJ_nid2obj(NID_id_ct_asciiTextWithCRLF)))
!CMS_set1_eCon..._nid2obj(787))Description
TRUEnever evaluated
FALSEnever evaluated
0
448 goto err;
never executed: goto err;
0
449-
450 if (pkey && !CMS_add1_signer(cms, signcert, pkey, NULL, flags)) {
pkeyDescription
TRUEnever evaluated
FALSEevaluated 29 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
!CMS_add1_sign... *)0) , flags)Description
TRUEnever evaluated
FALSEnever evaluated
0-29
451 CMSerr(CMS_F_CMS_SIGN, CMS_R_ADD_SIGNER_ERROR);-
452 goto err;
never executed: goto err;
0
453 }-
454-
455 for (i = 0; i < sk_X509_num(certs); i++) {
i < sk_X509_num(certs)Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 29 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
4-29
456 X509 *x = sk_X509_value(certs, i);-
457 if (!CMS_add1_cert(cms, x))
!CMS_add1_cert(cms, x)Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4
458 goto merr;
never executed: goto merr;
0
459 }
executed 4 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
4
460-
461 if (!(flags & CMS_DETACHED))
!(flags & 0x40)Description
TRUEevaluated 20 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 9 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
9-20
462 CMS_set_detached(cms, 0);
executed 20 times by 1 test: CMS_set_detached(cms, 0);
Executed by:
  • libcrypto.so.1.1
20
463-
464 if ((flags & (CMS_STREAM | CMS_PARTIAL))
(flags & (0x1000 | 0x4000))Description
TRUEevaluated 29 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-29
465 || CMS_final(cms, data, NULL, flags))
CMS_final(cms,... *)0) , flags)Description
TRUEnever evaluated
FALSEnever evaluated
0
466 return cms;
executed 29 times by 1 test: return cms;
Executed by:
  • libcrypto.so.1.1
29
467 else-
468 goto err;
never executed: goto err;
0
469-
470 merr:-
471 CMSerr(CMS_F_CMS_SIGN, ERR_R_MALLOC_FAILURE);-
472-
473 err:
code before this statement never executed: err:
0
474 CMS_ContentInfo_free(cms);-
475 return NULL;
never executed: return ((void *)0) ;
0
476}-
477-
478CMS_ContentInfo *CMS_sign_receipt(CMS_SignerInfo *si,-
479 X509 *signcert, EVP_PKEY *pkey,-
480 STACK_OF(X509) *certs, unsigned int flags)-
481{-
482 CMS_SignerInfo *rct_si;-
483 CMS_ContentInfo *cms = NULL;-
484 ASN1_OCTET_STRING **pos, *os;-
485 BIO *rct_cont = NULL;-
486 int r = 0;-
487-
488 flags &= ~(CMS_STREAM | CMS_TEXT);-
489 /* Not really detached but avoids content being allocated */-
490 flags |= CMS_PARTIAL | CMS_BINARY | CMS_DETACHED;-
491 if (!pkey || !signcert) {
!pkeyDescription
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
!signcertDescription
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1
492 CMSerr(CMS_F_CMS_SIGN_RECEIPT, CMS_R_NO_KEY_OR_CERT);-
493 return NULL;
never executed: return ((void *)0) ;
0
494 }-
495-
496 /* Initialize signed data */-
497-
498 cms = CMS_sign(NULL, NULL, certs, NULL, flags);-
499 if (!cms)
!cmsDescription
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1
500 goto err;
never executed: goto err;
0
501-
502 /* Set inner content type to signed receipt */-
503 if (!CMS_set1_eContentType(cms, OBJ_nid2obj(NID_id_smime_ct_receipt)))
!CMS_set1_eCon..._nid2obj(204))Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1
504 goto err;
never executed: goto err;
0
505-
506 rct_si = CMS_add1_signer(cms, signcert, pkey, NULL, flags);-
507 if (!rct_si) {
!rct_siDescription
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1
508 CMSerr(CMS_F_CMS_SIGN_RECEIPT, CMS_R_ADD_SIGNER_ERROR);-
509 goto err;
never executed: goto err;
0
510 }-
511-
512 os = cms_encode_Receipt(si);-
513-
514 if (!os)
!osDescription
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1
515 goto err;
never executed: goto err;
0
516-
517 /* Set content to digest */-
518 rct_cont = BIO_new_mem_buf(os->data, os->length);-
519 if (!rct_cont)
!rct_contDescription
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1
520 goto err;
never executed: goto err;
0
521-
522 /* Add msgSigDigest attribute */-
523-
524 if (!cms_msgSigDigest_add1(rct_si, si))
!cms_msgSigDig...d1(rct_si, si)Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1
525 goto err;
never executed: goto err;
0
526-
527 /* Finalize structure */-
528 if (!CMS_final(cms, rct_cont, NULL, flags))
!CMS_final(cms... *)0) , flags)Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1
529 goto err;
never executed: goto err;
0
530-
531 /* Set embedded content */-
532 pos = CMS_get0_content(cms);-
533 *pos = os;-
534-
535 r = 1;-
536-
537 err:
code before this statement executed 1 time by 1 test: err:
Executed by:
  • libcrypto.so.1.1
1
538 BIO_free(rct_cont);-
539 if (r)
rDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-1
540 return cms;
executed 1 time by 1 test: return cms;
Executed by:
  • libcrypto.so.1.1
1
541 CMS_ContentInfo_free(cms);-
542 return NULL;
never executed: return ((void *)0) ;
0
543-
544}-
545-
546CMS_ContentInfo *CMS_encrypt(STACK_OF(X509) *certs, BIO *data,-
547 const EVP_CIPHER *cipher, unsigned int flags)-
548{-
549 CMS_ContentInfo *cms;-
550 int i;-
551 X509 *recip;-
552 cms = CMS_EnvelopedData_create(cipher);-
553 if (!cms)
!cmsDescription
TRUEnever evaluated
FALSEevaluated 20 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-20
554 goto merr;
never executed: goto merr;
0
555 for (i = 0; i < sk_X509_num(certs); i++) {
i < sk_X509_num(certs)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 20 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
1-20
556 recip = sk_X509_value(certs, i);-
557 if (!CMS_add1_recipient_cert(cms, recip, flags)) {
!CMS_add1_reci... recip, flags)Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1
558 CMSerr(CMS_F_CMS_ENCRYPT, CMS_R_RECIPIENT_ERROR);-
559 goto err;
never executed: goto err;
0
560 }-
561 }
executed 1 time by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
1
562-
563 if (!(flags & CMS_DETACHED))
!(flags & 0x40)Description
TRUEevaluated 20 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-20
564 CMS_set_detached(cms, 0);
executed 20 times by 1 test: CMS_set_detached(cms, 0);
Executed by:
  • libcrypto.so.1.1
20
565-
566 if ((flags & (CMS_STREAM | CMS_PARTIAL))
(flags & (0x1000 | 0x4000))Description
TRUEevaluated 19 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
1-19
567 || CMS_final(cms, data, NULL, flags))
CMS_final(cms,... *)0) , flags)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-1
568 return cms;
executed 20 times by 1 test: return cms;
Executed by:
  • libcrypto.so.1.1
20
569 else-
570 goto err;
never executed: goto err;
0
571-
572 merr:-
573 CMSerr(CMS_F_CMS_ENCRYPT, ERR_R_MALLOC_FAILURE);-
574 err:
code before this statement never executed: err:
0
575 CMS_ContentInfo_free(cms);-
576 return NULL;
never executed: return ((void *)0) ;
0
577}-
578-
579static int cms_kari_set1_pkey(CMS_ContentInfo *cms, CMS_RecipientInfo *ri,-
580 EVP_PKEY *pk, X509 *cert)-
581{-
582 int i;-
583 STACK_OF(CMS_RecipientEncryptedKey) *reks;-
584 CMS_RecipientEncryptedKey *rek;-
585 reks = CMS_RecipientInfo_kari_get0_reks(ri);-
586 for (i = 0; i < sk_CMS_RecipientEncryptedKey_num(reks); i++) {
i < sk_CMS_Rec...dKey_num(reks)Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-6
587 int rv;-
588 rek = sk_CMS_RecipientEncryptedKey_value(reks, i);-
589 if (cert != NULL && CMS_RecipientEncryptedKey_cert_cmp(rek, cert))
cert != ((void *)0)Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
CMS_RecipientE...cmp(rek, cert)Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-5
590 continue;
never executed: continue;
0
591 CMS_RecipientInfo_kari_set0_pkey(ri, pk);-
592 rv = CMS_RecipientInfo_kari_decrypt(cms, ri, rek);-
593 CMS_RecipientInfo_kari_set0_pkey(ri, NULL);-
594 if (rv > 0)
rv > 0Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-6
595 return 1;
executed 6 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
6
596 return cert == NULL ? 0 : -1;
never executed: return cert == ((void *)0) ? 0 : -1;
cert == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
597 }-
598 return 0;
never executed: return 0;
0
599}-
600-
601int CMS_decrypt_set1_pkey(CMS_ContentInfo *cms, EVP_PKEY *pk, X509 *cert)-
602{-
603 STACK_OF(CMS_RecipientInfo) *ris;-
604 CMS_RecipientInfo *ri;-
605 int i, r, ri_type;-
606 int debug = 0, match_ri = 0;-
607 ris = CMS_get0_RecipientInfos(cms);-
608 if (ris)
risDescription
TRUEevaluated 18 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-18
609 debug = cms->d.envelopedData->encryptedContentInfo->debug;
executed 18 times by 1 test: debug = cms->d.envelopedData->encryptedContentInfo->debug;
Executed by:
  • libcrypto.so.1.1
18
610 ri_type = cms_pkey_get_ri_type(pk);-
611 if (ri_type == CMS_RECIPINFO_NONE) {
ri_type == -1Description
TRUEnever evaluated
FALSEevaluated 18 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-18
612 CMSerr(CMS_F_CMS_DECRYPT_SET1_PKEY,-
613 CMS_R_NOT_SUPPORTED_FOR_THIS_KEY_TYPE);-
614 return 0;
never executed: return 0;
0
615 }-
616-
617 for (i = 0; i < sk_CMS_RecipientInfo_num(ris); i++) {
i < sk_CMS_Rec...tInfo_num(ris)Description
TRUEevaluated 27 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
2-27
618 ri = sk_CMS_RecipientInfo_value(ris, i);-
619 if (CMS_RecipientInfo_type(ri) != ri_type)
CMS_RecipientI...ri) != ri_typeDescription
TRUEnever evaluated
FALSEevaluated 27 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-27
620 continue;
never executed: continue;
0
621 match_ri = 1;-
622 if (ri_type == CMS_RECIPINFO_AGREE) {
ri_type == 1Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 21 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
6-21
623 r = cms_kari_set1_pkey(cms, ri, pk, cert);-
624 if (r > 0)
r > 0Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-6
625 return 1;
executed 6 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
6
626 if (r < 0)
r < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
627 return 0;
never executed: return 0;
0
628 }
never executed: end of block
0
629 /*-
630 * If we have a cert try matching RecipientInfo otherwise try them-
631 * all.-
632 */-
633 else if (!cert || !CMS_RecipientInfo_ktri_cert_cmp(ri, cert)) {
!certDescription
TRUEevaluated 6 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 15 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
!CMS_Recipient..._cmp(ri, cert)Description
TRUEevaluated 10 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 5 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
5-15
634 EVP_PKEY_up_ref(pk);-
635 CMS_RecipientInfo_set0_pkey(ri, pk);-
636 r = CMS_RecipientInfo_decrypt(cms, ri);-
637 CMS_RecipientInfo_set0_pkey(ri, NULL);-
638 if (cert) {
certDescription
TRUEevaluated 10 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 6 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
6-10
639 /*-
640 * If not debugging clear any error and return success to-
641 * avoid leaking of information useful to MMA-
642 */-
643 if (!debug) {
!debugDescription
TRUEevaluated 10 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-10
644 ERR_clear_error();-
645 return 1;
executed 10 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
10
646 }-
647 if (r > 0)
r > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
648 return 1;
never executed: return 1;
0
649 CMSerr(CMS_F_CMS_DECRYPT_SET1_PKEY, CMS_R_DECRYPT_ERROR);-
650 return 0;
never executed: return 0;
0
651 }-
652 /*-
653 * If no cert and not debugging don't leave loop after first-
654 * successful decrypt. Always attempt to decrypt all recipients-
655 * to avoid leaking timing of a successful decrypt.-
656 */-
657 else if (r > 0 && debug)
r > 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 4 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
debugDescription
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-4
658 return 1;
never executed: return 1;
0
659 }
executed 6 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
6
660 }
executed 11 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
11
661 /* If no cert, key transport and not debugging always return success */-
662 if (cert == NULL && ri_type == CMS_RECIPINFO_TRANS && match_ri && !debug) {
cert == ((void *)0)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
ri_type == 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
match_riDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
!debugDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-2
663 ERR_clear_error();-
664 return 1;
executed 2 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
2
665 }-
666-
667 CMSerr(CMS_F_CMS_DECRYPT_SET1_PKEY, CMS_R_NO_MATCHING_RECIPIENT);-
668 return 0;
never executed: return 0;
0
669-
670}-
671-
672int CMS_decrypt_set1_key(CMS_ContentInfo *cms,-
673 unsigned char *key, size_t keylen,-
674 const unsigned char *id, size_t idlen)-
675{-
676 STACK_OF(CMS_RecipientInfo) *ris;-
677 CMS_RecipientInfo *ri;-
678 int i, r;-
679 ris = CMS_get0_RecipientInfos(cms);-
680 for (i = 0; i < sk_CMS_RecipientInfo_num(ris); i++) {
i < sk_CMS_Rec...tInfo_num(ris)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-2
681 ri = sk_CMS_RecipientInfo_value(ris, i);-
682 if (CMS_RecipientInfo_type(ri) != CMS_RECIPINFO_KEK)
CMS_RecipientI..._type(ri) != 2Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2
683 continue;
never executed: continue;
0
684-
685 /*-
686 * If we have an id try matching RecipientInfo otherwise try them-
687 * all.-
688 */-
689 if (!id || (CMS_RecipientInfo_kekri_id_cmp(ri, id, idlen) == 0)) {
!idDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
(CMS_Recipient..., idlen) == 0)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-1
690 CMS_RecipientInfo_set0_key(ri, key, keylen);-
691 r = CMS_RecipientInfo_decrypt(cms, ri);-
692 CMS_RecipientInfo_set0_key(ri, NULL, 0);-
693 if (r > 0)
r > 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-2
694 return 1;
executed 2 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
2
695 if (id) {
idDescription
TRUEnever evaluated
FALSEnever evaluated
0
696 CMSerr(CMS_F_CMS_DECRYPT_SET1_KEY, CMS_R_DECRYPT_ERROR);-
697 return 0;
never executed: return 0;
0
698 }-
699 ERR_clear_error();-
700 }
never executed: end of block
0
701 }
never executed: end of block
0
702-
703 CMSerr(CMS_F_CMS_DECRYPT_SET1_KEY, CMS_R_NO_MATCHING_RECIPIENT);-
704 return 0;
never executed: return 0;
0
705-
706}-
707-
708int CMS_decrypt_set1_password(CMS_ContentInfo *cms,-
709 unsigned char *pass, ossl_ssize_t passlen)-
710{-
711 STACK_OF(CMS_RecipientInfo) *ris;-
712 CMS_RecipientInfo *ri;-
713 int i, r;-
714 ris = CMS_get0_RecipientInfos(cms);-
715 for (i = 0; i < sk_CMS_RecipientInfo_num(ris); i++) {
i < sk_CMS_Rec...tInfo_num(ris)Description
TRUEnever evaluated
FALSEnever evaluated
0
716 ri = sk_CMS_RecipientInfo_value(ris, i);-
717 if (CMS_RecipientInfo_type(ri) != CMS_RECIPINFO_PASS)
CMS_RecipientI..._type(ri) != 3Description
TRUEnever evaluated
FALSEnever evaluated
0
718 continue;
never executed: continue;
0
719 CMS_RecipientInfo_set0_password(ri, pass, passlen);-
720 r = CMS_RecipientInfo_decrypt(cms, ri);-
721 CMS_RecipientInfo_set0_password(ri, NULL, 0);-
722 if (r > 0)
r > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
723 return 1;
never executed: return 1;
0
724 }
never executed: end of block
0
725-
726 CMSerr(CMS_F_CMS_DECRYPT_SET1_PASSWORD, CMS_R_NO_MATCHING_RECIPIENT);-
727 return 0;
never executed: return 0;
0
728-
729}-
730-
731int CMS_decrypt(CMS_ContentInfo *cms, EVP_PKEY *pk, X509 *cert,-
732 BIO *dcont, BIO *out, unsigned int flags)-
733{-
734 int r;-
735 BIO *cont;-
736 if (OBJ_obj2nid(CMS_get0_type(cms)) != NID_pkcs7_enveloped) {
OBJ_obj2nid(CM...pe(cms)) != 23Description
TRUEnever evaluated
FALSEevaluated 20 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-20
737 CMSerr(CMS_F_CMS_DECRYPT, CMS_R_TYPE_NOT_ENVELOPED_DATA);-
738 return 0;
never executed: return 0;
0
739 }-
740 if (!dcont && !check_content(cms))
!dcontDescription
TRUEevaluated 20 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
!check_content(cms)Description
TRUEnever evaluated
FALSEevaluated 20 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-20
741 return 0;
never executed: return 0;
0
742 if (flags & CMS_DEBUG_DECRYPT)
flags & 0x20000Description
TRUEnever evaluated
FALSEevaluated 20 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-20
743 cms->d.envelopedData->encryptedContentInfo->debug = 1;
never executed: cms->d.envelopedData->encryptedContentInfo->debug = 1;
0
744 else-
745 cms->d.envelopedData->encryptedContentInfo->debug = 0;
executed 20 times by 1 test: cms->d.envelopedData->encryptedContentInfo->debug = 0;
Executed by:
  • libcrypto.so.1.1
20
746 if (!pk && !cert && !dcont && !out)
!pkDescription
TRUEevaluated 19 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
!certDescription
TRUEevaluated 19 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
!dcontDescription
TRUEevaluated 19 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
!outDescription
TRUEnever evaluated
FALSEevaluated 19 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-19
747 return 1;
never executed: return 1;
0
748 if (pk && !CMS_decrypt_set1_pkey(cms, pk, cert))
pkDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 19 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
!CMS_decrypt_s...cms, pk, cert)Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-19
749 return 0;
never executed: return 0;
0
750 cont = CMS_dataInit(cms, dcont);-
751 if (!cont)
!contDescription
TRUEnever evaluated
FALSEevaluated 20 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-20
752 return 0;
never executed: return 0;
0
753 r = cms_copy_content(out, cont, flags);-
754 do_free_upto(cont, dcont);-
755 return r;
executed 20 times by 1 test: return r;
Executed by:
  • libcrypto.so.1.1
20
756}-
757-
758int CMS_final(CMS_ContentInfo *cms, BIO *data, BIO *dcont, unsigned int flags)-
759{-
760 BIO *cmsbio;-
761 int ret = 0;-
762-
763 if ((cmsbio = CMS_dataInit(cms, dcont)) == NULL) {
(cmsbio = CMS_...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 14 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-14
764 CMSerr(CMS_F_CMS_FINAL, CMS_R_CMS_LIB);-
765 return 0;
never executed: return 0;
0
766 }-
767-
768 SMIME_crlf_copy(data, cmsbio, flags);-
769-
770 (void)BIO_flush(cmsbio);-
771-
772 if (!CMS_dataFinal(cms, cmsbio)) {
!CMS_dataFinal(cms, cmsbio)Description
TRUEnever evaluated
FALSEevaluated 14 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-14
773 CMSerr(CMS_F_CMS_FINAL, CMS_R_CMS_DATAFINAL_ERROR);-
774 goto err;
never executed: goto err;
0
775 }-
776-
777 ret = 1;-
778-
779 err:
code before this statement executed 14 times by 1 test: err:
Executed by:
  • libcrypto.so.1.1
14
780 do_free_upto(cmsbio, dcont);-
781-
782 return ret;
executed 14 times by 1 test: return ret;
Executed by:
  • libcrypto.so.1.1
14
783-
784}-
785-
786#ifdef ZLIB-
787-
788int CMS_uncompress(CMS_ContentInfo *cms, BIO *dcont, BIO *out,-
789 unsigned int flags)-
790{-
791 BIO *cont;-
792 int r;-
793 if (OBJ_obj2nid(CMS_get0_type(cms)) != NID_id_smime_ct_compressedData) {-
794 CMSerr(CMS_F_CMS_UNCOMPRESS, CMS_R_TYPE_NOT_COMPRESSED_DATA);-
795 return 0;-
796 }-
797-
798 if (!dcont && !check_content(cms))-
799 return 0;-
800-
801 cont = CMS_dataInit(cms, dcont);-
802 if (!cont)-
803 return 0;-
804 r = cms_copy_content(out, cont, flags);-
805 do_free_upto(cont, dcont);-
806 return r;-
807}-
808-
809CMS_ContentInfo *CMS_compress(BIO *in, int comp_nid, unsigned int flags)-
810{-
811 CMS_ContentInfo *cms;-
812 if (comp_nid <= 0)-
813 comp_nid = NID_zlib_compression;-
814 cms = cms_CompressedData_create(comp_nid);-
815 if (!cms)-
816 return NULL;-
817-
818 if (!(flags & CMS_DETACHED))-
819 CMS_set_detached(cms, 0);-
820-
821 if ((flags & CMS_STREAM) || CMS_final(cms, in, NULL, flags))-
822 return cms;-
823-
824 CMS_ContentInfo_free(cms);-
825 return NULL;-
826}-
827-
828#else-
829-
830int CMS_uncompress(CMS_ContentInfo *cms, BIO *dcont, BIO *out,-
831 unsigned int flags)-
832{-
833 CMSerr(CMS_F_CMS_UNCOMPRESS, CMS_R_UNSUPPORTED_COMPRESSION_ALGORITHM);-
834 return 0;
never executed: return 0;
0
835}-
836-
837CMS_ContentInfo *CMS_compress(BIO *in, int comp_nid, unsigned int flags)-
838{-
839 CMSerr(CMS_F_CMS_COMPRESS, CMS_R_UNSUPPORTED_COMPRESSION_ALGORITHM);-
840 return NULL;
never executed: return ((void *)0) ;
0
841}-
842-
843#endif-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.2