Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/pkcs7/pk7_smime.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||||||||
2 | - | |||||||||||||||||||
3 | - | |||||||||||||||||||
4 | - | |||||||||||||||||||
5 | static int pkcs7_copy_existing_digest(PKCS7 *p7, PKCS7_SIGNER_INFO *si); | - | ||||||||||||||||||
6 | - | |||||||||||||||||||
7 | PKCS7 *PKCS7_sign(X509 *signcert, EVP_PKEY *pkey, struct stack_st_X509 *certs, | - | ||||||||||||||||||
8 | BIO *data, int flags) | - | ||||||||||||||||||
9 | { | - | ||||||||||||||||||
10 | PKCS7 *p7; | - | ||||||||||||||||||
11 | int i; | - | ||||||||||||||||||
12 | - | |||||||||||||||||||
13 | if ((
| 0-11 | ||||||||||||||||||
14 | ((void *)0)
| 0-11 | ||||||||||||||||||
15 | ) { | - | ||||||||||||||||||
16 | ERR_put_error(33,(116),((1|64)),__FILE__,29); | - | ||||||||||||||||||
17 | return never executed: return ((void *)0) ; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
18 | ((void *)0) never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
19 | ; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
20 | } | - | ||||||||||||||||||
21 | - | |||||||||||||||||||
22 | if (!PKCS7_set_type(p7, 22)
| 0-11 | ||||||||||||||||||
23 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
24 | - | |||||||||||||||||||
25 | if (!PKCS7_content_new(p7, 21)
| 0-11 | ||||||||||||||||||
26 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
27 | - | |||||||||||||||||||
28 | if (pkey
| 0-11 | ||||||||||||||||||
29 | ((void *)0)
| 0 | ||||||||||||||||||
30 | , flags)
| 0 | ||||||||||||||||||
31 | ERR_put_error(33,(116),(153),__FILE__,40); | - | ||||||||||||||||||
32 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
33 | } | - | ||||||||||||||||||
34 | - | |||||||||||||||||||
35 | if (!(flags & 0x2)
| 0-11 | ||||||||||||||||||
36 | for (i = 0; i < sk_X509_num(certs)
| 2-11 | ||||||||||||||||||
37 | if (!PKCS7_add_certificate(p7, sk_X509_value(certs, i))
| 0-2 | ||||||||||||||||||
38 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
39 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
40 | } executed 11 times by 1 test: end of block Executed by:
| 11 | ||||||||||||||||||
41 | - | |||||||||||||||||||
42 | if (flags & 0x40
| 4-7 | ||||||||||||||||||
43 | PKCS7_ctrl(p7,1,1, executed 4 times by 1 test: PKCS7_ctrl(p7,1,1, ((void *)0) ); Executed by:
| 4 | ||||||||||||||||||
44 | ((void *)0) executed 4 times by 1 test: PKCS7_ctrl(p7,1,1, ((void *)0) ); Executed by:
| 4 | ||||||||||||||||||
45 | ); executed 4 times by 1 test: PKCS7_ctrl(p7,1,1, ((void *)0) ); Executed by:
| 4 | ||||||||||||||||||
46 | - | |||||||||||||||||||
47 | if (flags & (0x1000 | 0x4000)
| 0-11 | ||||||||||||||||||
48 | return executed 11 times by 1 test: p7;return p7; Executed by:
executed 11 times by 1 test: return p7; Executed by:
| 11 | ||||||||||||||||||
49 | - | |||||||||||||||||||
50 | if (PKCS7_final(p7, data, flags)
| 0 | ||||||||||||||||||
51 | return never executed: p7;return p7; never executed: return p7; | 0 | ||||||||||||||||||
52 | - | |||||||||||||||||||
53 | err: code before this statement never executed: err: | 0 | ||||||||||||||||||
54 | PKCS7_free(p7); | - | ||||||||||||||||||
55 | return never executed: return ((void *)0) ; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
56 | ((void *)0) never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
57 | ; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
58 | } | - | ||||||||||||||||||
59 | - | |||||||||||||||||||
60 | int PKCS7_final(PKCS7 *p7, BIO *data, int flags) | - | ||||||||||||||||||
61 | { | - | ||||||||||||||||||
62 | BIO *p7bio; | - | ||||||||||||||||||
63 | int ret = 0; | - | ||||||||||||||||||
64 | - | |||||||||||||||||||
65 | if ((
| 0-4 | ||||||||||||||||||
66 | ((void *)0)
| 0-4 | ||||||||||||||||||
67 | )) ==
| 0-4 | ||||||||||||||||||
68 | ((void *)0)
| 0-4 | ||||||||||||||||||
69 | ) { | - | ||||||||||||||||||
70 | ERR_put_error(33,(134),((1|64)),__FILE__,71); | - | ||||||||||||||||||
71 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
72 | } | - | ||||||||||||||||||
73 | - | |||||||||||||||||||
74 | SMIME_crlf_copy(data, p7bio, flags); | - | ||||||||||||||||||
75 | - | |||||||||||||||||||
76 | (void)(int)BIO_ctrl(p7bio,11,0, | - | ||||||||||||||||||
77 | ((void *)0) | - | ||||||||||||||||||
78 | ); | - | ||||||||||||||||||
79 | - | |||||||||||||||||||
80 | if (!PKCS7_dataFinal(p7, p7bio)
| 0-4 | ||||||||||||||||||
81 | ERR_put_error(33,(134),(145),__FILE__,80); | - | ||||||||||||||||||
82 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
83 | } | - | ||||||||||||||||||
84 | - | |||||||||||||||||||
85 | ret = 1; | - | ||||||||||||||||||
86 | - | |||||||||||||||||||
87 | err: code before this statement executed 4 times by 1 test: err: Executed by:
| 4 | ||||||||||||||||||
88 | BIO_free_all(p7bio); | - | ||||||||||||||||||
89 | - | |||||||||||||||||||
90 | return executed 4 times by 1 test: ret;return ret; Executed by:
executed 4 times by 1 test: return ret; Executed by:
| 4 | ||||||||||||||||||
91 | - | |||||||||||||||||||
92 | } | - | ||||||||||||||||||
93 | - | |||||||||||||||||||
94 | - | |||||||||||||||||||
95 | - | |||||||||||||||||||
96 | static int add_cipher_smcap(struct stack_st_X509_ALGOR *sk, int nid, int arg) | - | ||||||||||||||||||
97 | { | - | ||||||||||||||||||
98 | if (EVP_get_cipherbyname(OBJ_nid2sn(nid))
| 20-160 | ||||||||||||||||||
99 | return executed 160 times by 1 test: PKCS7_simple_smimecap(sk, nid, arg);return PKCS7_simple_smimecap(sk, nid, arg); Executed by:
executed 160 times by 1 test: return PKCS7_simple_smimecap(sk, nid, arg); Executed by:
| 160 | ||||||||||||||||||
100 | return executed 20 times by 1 test: 1;return 1; Executed by:
executed 20 times by 1 test: return 1; Executed by:
| 20 | ||||||||||||||||||
101 | } | - | ||||||||||||||||||
102 | - | |||||||||||||||||||
103 | static int add_digest_smcap(struct stack_st_X509_ALGOR *sk, int nid, int arg) | - | ||||||||||||||||||
104 | { | - | ||||||||||||||||||
105 | if (EVP_get_digestbyname(OBJ_nid2sn(nid))
| 0-60 | ||||||||||||||||||
106 | return never executed: PKCS7_simple_smimecap(sk, nid, arg);return PKCS7_simple_smimecap(sk, nid, arg); never executed: return PKCS7_simple_smimecap(sk, nid, arg); | 0 | ||||||||||||||||||
107 | return executed 60 times by 1 test: 1;return 1; Executed by:
executed 60 times by 1 test: return 1; Executed by:
| 60 | ||||||||||||||||||
108 | } | - | ||||||||||||||||||
109 | - | |||||||||||||||||||
110 | PKCS7_SIGNER_INFO *PKCS7_sign_add_signer(PKCS7 *p7, X509 *signcert, | - | ||||||||||||||||||
111 | EVP_PKEY *pkey, const EVP_MD *md, | - | ||||||||||||||||||
112 | int flags) | - | ||||||||||||||||||
113 | { | - | ||||||||||||||||||
114 | PKCS7_SIGNER_INFO *si = | - | ||||||||||||||||||
115 | ((void *)0) | - | ||||||||||||||||||
116 | ; | - | ||||||||||||||||||
117 | struct stack_st_X509_ALGOR *smcap = | - | ||||||||||||||||||
118 | ((void *)0) | - | ||||||||||||||||||
119 | ; | - | ||||||||||||||||||
120 | if (!X509_check_private_key(signcert, pkey)
| 0-24 | ||||||||||||||||||
121 | ERR_put_error(33,(137),(127),__FILE__,117) | - | ||||||||||||||||||
122 | ; | - | ||||||||||||||||||
123 | return never executed: return ((void *)0) ; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
124 | ((void *)0) never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
125 | ; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
126 | } | - | ||||||||||||||||||
127 | - | |||||||||||||||||||
128 | if ((
| 0-24 | ||||||||||||||||||
129 | ((void *)0)
| 0-24 | ||||||||||||||||||
130 | ) { | - | ||||||||||||||||||
131 | ERR_put_error(33,(137),(124),__FILE__,123) | - | ||||||||||||||||||
132 | ; | - | ||||||||||||||||||
133 | return never executed: return ((void *)0) ; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
134 | ((void *)0) never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
135 | ; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
136 | } | - | ||||||||||||||||||
137 | - | |||||||||||||||||||
138 | if (!(flags & 0x2)
| 0-24 | ||||||||||||||||||
139 | if (!PKCS7_add_certificate(p7, signcert)
| 0-24 | ||||||||||||||||||
140 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
141 | } executed 24 times by 1 test: end of block Executed by:
| 24 | ||||||||||||||||||
142 | - | |||||||||||||||||||
143 | if (!(flags & 0x100)
| 4-20 | ||||||||||||||||||
144 | if (!PKCS7_add_attrib_content_type(si,
| 0-20 | ||||||||||||||||||
145 | ((void *)0)
| 0-20 | ||||||||||||||||||
146 | )
| 0-20 | ||||||||||||||||||
147 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
148 | - | |||||||||||||||||||
149 | if (!(flags & 0x200)
| 0-20 | ||||||||||||||||||
150 | if ((
| 0-20 | ||||||||||||||||||
151 | ((void *)0)
| 0-20 | ||||||||||||||||||
152 | ) { | - | ||||||||||||||||||
153 | ERR_put_error(33,(137),((1|64)),__FILE__,138); | - | ||||||||||||||||||
154 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
155 | } | - | ||||||||||||||||||
156 | if (!add_cipher_smcap(smcap, 427, -1)
| 0-20 | ||||||||||||||||||
157 | || !add_digest_smcap(smcap, 982, -1)
| 0-20 | ||||||||||||||||||
158 | || !add_digest_smcap(smcap, 983, -1)
| 0-20 | ||||||||||||||||||
159 | || !add_digest_smcap(smcap, 809, -1)
| 0-20 | ||||||||||||||||||
160 | || !add_cipher_smcap(smcap, 813, -1)
| 0-20 | ||||||||||||||||||
161 | || !add_cipher_smcap(smcap, 423, -1)
| 0-20 | ||||||||||||||||||
162 | || !add_cipher_smcap(smcap, 419, -1)
| 0-20 | ||||||||||||||||||
163 | || !add_cipher_smcap(smcap, 44, -1)
| 0-20 | ||||||||||||||||||
164 | || !add_cipher_smcap(smcap, 37, 128)
| 0-20 | ||||||||||||||||||
165 | || !add_cipher_smcap(smcap, 37, 64)
| 0-20 | ||||||||||||||||||
166 | || !add_cipher_smcap(smcap, 31, -1)
| 0-20 | ||||||||||||||||||
167 | || !add_cipher_smcap(smcap, 37, 40)
| 0-20 | ||||||||||||||||||
168 | || !PKCS7_add_attrib_smimecap(si, smcap)
| 0-20 | ||||||||||||||||||
169 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
170 | sk_X509_ALGOR_pop_free(smcap, X509_ALGOR_free); | - | ||||||||||||||||||
171 | smcap = | - | ||||||||||||||||||
172 | ((void *)0) | - | ||||||||||||||||||
173 | ; | - | ||||||||||||||||||
174 | } executed 20 times by 1 test: end of block Executed by:
| 20 | ||||||||||||||||||
175 | if (flags & 0x8000
| 1-19 | ||||||||||||||||||
176 | if (!pkcs7_copy_existing_digest(p7, si)
| 0-1 | ||||||||||||||||||
177 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
178 | if (!(flags & 0x4000)
| 0-1 | ||||||||||||||||||
179 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
180 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||
181 | } executed 20 times by 1 test: end of block Executed by:
| 20 | ||||||||||||||||||
182 | return executed 24 times by 1 test: si;return si; Executed by:
executed 24 times by 1 test: return si; Executed by:
| 24 | ||||||||||||||||||
183 | err: | - | ||||||||||||||||||
184 | sk_X509_ALGOR_pop_free(smcap, X509_ALGOR_free); | - | ||||||||||||||||||
185 | return never executed: return ((void *)0) ; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
186 | ((void *)0) never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
187 | ; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
188 | } | - | ||||||||||||||||||
189 | - | |||||||||||||||||||
190 | - | |||||||||||||||||||
191 | - | |||||||||||||||||||
192 | - | |||||||||||||||||||
193 | - | |||||||||||||||||||
194 | - | |||||||||||||||||||
195 | static int pkcs7_copy_existing_digest(PKCS7 *p7, PKCS7_SIGNER_INFO *si) | - | ||||||||||||||||||
196 | { | - | ||||||||||||||||||
197 | int i; | - | ||||||||||||||||||
198 | struct stack_st_PKCS7_SIGNER_INFO *sinfos; | - | ||||||||||||||||||
199 | PKCS7_SIGNER_INFO *sitmp; | - | ||||||||||||||||||
200 | ASN1_OCTET_STRING *osdig = | - | ||||||||||||||||||
201 | ((void *)0) | - | ||||||||||||||||||
202 | ; | - | ||||||||||||||||||
203 | sinfos = PKCS7_get_signer_info(p7); | - | ||||||||||||||||||
204 | for (i = 0; i < sk_PKCS7_SIGNER_INFO_num(sinfos)
| 0-1 | ||||||||||||||||||
205 | sitmp = sk_PKCS7_SIGNER_INFO_value(sinfos, i); | - | ||||||||||||||||||
206 | if (si == sitmp
| 0-1 | ||||||||||||||||||
207 | break; never executed: break; | 0 | ||||||||||||||||||
208 | if (sk_X509_ATTRIBUTE_num(sitmp->auth_attr) <= 0
| 0-1 | ||||||||||||||||||
209 | continue; never executed: continue; | 0 | ||||||||||||||||||
210 | if (!OBJ_cmp(si->digest_alg->algorithm, sitmp->digest_alg->algorithm)
| 0-1 | ||||||||||||||||||
211 | osdig = PKCS7_digest_from_attributes(sitmp->auth_attr); | - | ||||||||||||||||||
212 | break; executed 1 time by 1 test: break; Executed by:
| 1 | ||||||||||||||||||
213 | } | - | ||||||||||||||||||
214 | - | |||||||||||||||||||
215 | } never executed: end of block | 0 | ||||||||||||||||||
216 | - | |||||||||||||||||||
217 | if (osdig
| 0-1 | ||||||||||||||||||
218 | return executed 1 time by 1 test: PKCS7_add1_attrib_digest(si, osdig->data, osdig->length);return PKCS7_add1_attrib_digest(si, osdig->data, osdig->length); Executed by:
executed 1 time by 1 test: return PKCS7_add1_attrib_digest(si, osdig->data, osdig->length); Executed by:
| 1 | ||||||||||||||||||
219 | - | |||||||||||||||||||
220 | ERR_put_error(33,(138),(154),__FILE__,200) | - | ||||||||||||||||||
221 | ; | - | ||||||||||||||||||
222 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
223 | } | - | ||||||||||||||||||
224 | - | |||||||||||||||||||
225 | int PKCS7_verify(PKCS7 *p7, struct stack_st_X509 *certs, X509_STORE *store, | - | ||||||||||||||||||
226 | BIO *indata, BIO *out, int flags) | - | ||||||||||||||||||
227 | { | - | ||||||||||||||||||
228 | struct stack_st_X509 *signers; | - | ||||||||||||||||||
229 | X509 *signer; | - | ||||||||||||||||||
230 | struct stack_st_PKCS7_SIGNER_INFO *sinfos; | - | ||||||||||||||||||
231 | PKCS7_SIGNER_INFO *si; | - | ||||||||||||||||||
232 | X509_STORE_CTX *cert_ctx = | - | ||||||||||||||||||
233 | ((void *)0) | - | ||||||||||||||||||
234 | ; | - | ||||||||||||||||||
235 | char *buf = | - | ||||||||||||||||||
236 | ((void *)0) | - | ||||||||||||||||||
237 | ; | - | ||||||||||||||||||
238 | int i, j = 0, k, ret = 0; | - | ||||||||||||||||||
239 | BIO *p7bio = | - | ||||||||||||||||||
240 | ((void *)0) | - | ||||||||||||||||||
241 | ; | - | ||||||||||||||||||
242 | BIO *tmpin = | - | ||||||||||||||||||
243 | ((void *)0) | - | ||||||||||||||||||
244 | , *tmpout = | - | ||||||||||||||||||
245 | ((void *)0) | - | ||||||||||||||||||
246 | ; | - | ||||||||||||||||||
247 | - | |||||||||||||||||||
248 | if (!p7
| 0-12 | ||||||||||||||||||
249 | ERR_put_error(33,(117),(143),__FILE__,218); | - | ||||||||||||||||||
250 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
251 | } | - | ||||||||||||||||||
252 | - | |||||||||||||||||||
253 | if (!(OBJ_obj2nid((p7)->type) == 22)
| 0-12 | ||||||||||||||||||
254 | ERR_put_error(33,(117),(113),__FILE__,223); | - | ||||||||||||||||||
255 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
256 | } | - | ||||||||||||||||||
257 | - | |||||||||||||||||||
258 | - | |||||||||||||||||||
259 | if (PKCS7_ctrl(p7,2,0,
| 5-7 | ||||||||||||||||||
260 | ((void *)0)
| 5-7 | ||||||||||||||||||
261 | )
| 0-7 | ||||||||||||||||||
262 | ERR_put_error(33,(117),(122),__FILE__,229); | - | ||||||||||||||||||
263 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
264 | } | - | ||||||||||||||||||
265 | - | |||||||||||||||||||
266 | if (flags & 0x10000
| 0-12 | ||||||||||||||||||
267 | - | |||||||||||||||||||
268 | - | |||||||||||||||||||
269 | - | |||||||||||||||||||
270 | - | |||||||||||||||||||
271 | - | |||||||||||||||||||
272 | - | |||||||||||||||||||
273 | - | |||||||||||||||||||
274 | if (!PKCS7_ctrl(p7,2,0,
| 0 | ||||||||||||||||||
275 | ((void *)0)
| 0 | ||||||||||||||||||
276 | )
| 0 | ||||||||||||||||||
277 | ERR_put_error(33,(117),(118),__FILE__,242); | - | ||||||||||||||||||
278 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
279 | } | - | ||||||||||||||||||
280 | } never executed: end of block | 0 | ||||||||||||||||||
281 | - | |||||||||||||||||||
282 | sinfos = PKCS7_get_signer_info(p7); | - | ||||||||||||||||||
283 | - | |||||||||||||||||||
284 | if (!sinfos
| 0-12 | ||||||||||||||||||
285 | ERR_put_error(33,(117),(123),__FILE__,250); | - | ||||||||||||||||||
286 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
287 | } | - | ||||||||||||||||||
288 | - | |||||||||||||||||||
289 | signers = PKCS7_get0_signers(p7, certs, flags); | - | ||||||||||||||||||
290 | if (!signers
| 0-12 | ||||||||||||||||||
291 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
292 | - | |||||||||||||||||||
293 | - | |||||||||||||||||||
294 | - | |||||||||||||||||||
295 | cert_ctx = X509_STORE_CTX_new(); | - | ||||||||||||||||||
296 | if (cert_ctx ==
| 0-12 | ||||||||||||||||||
297 | ((void *)0)
| 0-12 | ||||||||||||||||||
298 | ) | - | ||||||||||||||||||
299 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
300 | if (!(flags & 0x20)
| 0-12 | ||||||||||||||||||
301 | for (k = 0; k < sk_X509_num(signers)
| 12-25 | ||||||||||||||||||
302 | signer = sk_X509_value(signers, k); | - | ||||||||||||||||||
303 | if (!(flags & 0x8)
| 0-25 | ||||||||||||||||||
304 | if (!X509_STORE_CTX_init(cert_ctx, store, signer,
| 0-25 | ||||||||||||||||||
305 | p7->d.sign->cert)
| 0-25 | ||||||||||||||||||
306 | ERR_put_error(33,(117),(11),__FILE__,269); | - | ||||||||||||||||||
307 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
308 | } | - | ||||||||||||||||||
309 | X509_STORE_CTX_set_default(cert_ctx, "smime_sign"); | - | ||||||||||||||||||
310 | } executed 25 times by 1 test: else if (!X509_STORE_CTX_init(cert_ctx, store, signer, end of block Executed by:
| 0-25 | ||||||||||||||||||
311 | ((void *)0)
| 0 | ||||||||||||||||||
312 | )
| 0 | ||||||||||||||||||
313 | ERR_put_error(33,(117),(11),__FILE__,274); | - | ||||||||||||||||||
314 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
315 | } | - | ||||||||||||||||||
316 | if (!(flags & 0x2000)
| 0-25 | ||||||||||||||||||
317 | X509_STORE_CTX_set0_crls(cert_ctx, p7->d.sign->crl); executed 25 times by 1 test: X509_STORE_CTX_set0_crls(cert_ctx, p7->d.sign->crl); Executed by:
| 25 | ||||||||||||||||||
318 | i = X509_verify_cert(cert_ctx); | - | ||||||||||||||||||
319 | if (i <= 0
| 0-25 | ||||||||||||||||||
320 | j = X509_STORE_CTX_get_error(cert_ctx); never executed: j = X509_STORE_CTX_get_error(cert_ctx); | 0 | ||||||||||||||||||
321 | X509_STORE_CTX_cleanup(cert_ctx); | - | ||||||||||||||||||
322 | if (i <= 0
| 0-25 | ||||||||||||||||||
323 | ERR_put_error(33,(117),(117),__FILE__,285) | - | ||||||||||||||||||
324 | ; | - | ||||||||||||||||||
325 | ERR_add_error_data(2, "Verify error:", | - | ||||||||||||||||||
326 | X509_verify_cert_error_string(j)); | - | ||||||||||||||||||
327 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
328 | } | - | ||||||||||||||||||
329 | - | |||||||||||||||||||
330 | } executed 25 times by 1 test: end of block Executed by:
| 25 | ||||||||||||||||||
331 | if (indata
| 2-7 | ||||||||||||||||||
332 | char *ptr; | - | ||||||||||||||||||
333 | long len; | - | ||||||||||||||||||
334 | len = BIO_ctrl(indata,3,0,(char *)(&ptr)); | - | ||||||||||||||||||
335 | tmpin = BIO_new_mem_buf(ptr, len); | - | ||||||||||||||||||
336 | if (tmpin ==
| 0-2 | ||||||||||||||||||
337 | ((void *)0)
| 0-2 | ||||||||||||||||||
338 | ) { | - | ||||||||||||||||||
339 | ERR_put_error(33,(117),((1|64)),__FILE__,306); | - | ||||||||||||||||||
340 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
341 | } | - | ||||||||||||||||||
342 | } executed 2 times by 1 test: elseend of block Executed by:
| 2 | ||||||||||||||||||
343 | tmpin = indata; executed 10 times by 1 test: tmpin = indata; Executed by:
| 10 | ||||||||||||||||||
344 | - | |||||||||||||||||||
345 | if ((
| 0-12 | ||||||||||||||||||
346 | ((void *)0)
| 0-12 | ||||||||||||||||||
347 | ) | - | ||||||||||||||||||
348 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
349 | - | |||||||||||||||||||
350 | if (flags & 0x1
| 0-12 | ||||||||||||||||||
351 | if ((
| 0 | ||||||||||||||||||
352 | ((void *)0)
| 0 | ||||||||||||||||||
353 | ) { | - | ||||||||||||||||||
354 | ERR_put_error(33,(117),((1|64)),__FILE__,317); | - | ||||||||||||||||||
355 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
356 | } | - | ||||||||||||||||||
357 | BIO_ctrl(tmpout,130,0, | - | ||||||||||||||||||
358 | ((void *)0) | - | ||||||||||||||||||
359 | ); | - | ||||||||||||||||||
360 | } never executed: elseend of block | 0 | ||||||||||||||||||
361 | tmpout = out; executed 12 times by 1 test: tmpout = out; Executed by:
| 12 | ||||||||||||||||||
362 | - | |||||||||||||||||||
363 | - | |||||||||||||||||||
364 | if ((
| 0-12 | ||||||||||||||||||
365 | ((void *)0)
| 0-12 | ||||||||||||||||||
366 | ) { | - | ||||||||||||||||||
367 | ERR_put_error(33,(117),((1|64)),__FILE__,326); | - | ||||||||||||||||||
368 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
369 | } | - | ||||||||||||||||||
370 | for (;;) { | - | ||||||||||||||||||
371 | i = BIO_read(p7bio, buf, 4096); | - | ||||||||||||||||||
372 | if (i <= 0
| 12 | ||||||||||||||||||
373 | break; executed 12 times by 1 test: break; Executed by:
| 12 | ||||||||||||||||||
374 | if (tmpout
| 0-12 | ||||||||||||||||||
375 | BIO_write(tmpout, buf, i); executed 12 times by 1 test: BIO_write(tmpout, buf, i); Executed by:
| 12 | ||||||||||||||||||
376 | } executed 12 times by 1 test: end of block Executed by:
| 12 | ||||||||||||||||||
377 | - | |||||||||||||||||||
378 | if (flags & 0x1
| 0-12 | ||||||||||||||||||
379 | if (!SMIME_text(tmpout, out)
| 0 | ||||||||||||||||||
380 | ERR_put_error(33,(117),(129),__FILE__,339); | - | ||||||||||||||||||
381 | BIO_free(tmpout); | - | ||||||||||||||||||
382 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
383 | } | - | ||||||||||||||||||
384 | BIO_free(tmpout); | - | ||||||||||||||||||
385 | } never executed: end of block | 0 | ||||||||||||||||||
386 | - | |||||||||||||||||||
387 | - | |||||||||||||||||||
388 | if (!(flags & 0x4)
| 0-12 | ||||||||||||||||||
389 | for (i = 0; i < sk_PKCS7_SIGNER_INFO_num(sinfos)
| 12-25 | ||||||||||||||||||
390 | si = sk_PKCS7_SIGNER_INFO_value(sinfos, i); | - | ||||||||||||||||||
391 | signer = sk_X509_value(signers, i); | - | ||||||||||||||||||
392 | j = PKCS7_signatureVerify(p7bio, p7, si, signer); | - | ||||||||||||||||||
393 | if (j <= 0
| 0-25 | ||||||||||||||||||
394 | ERR_put_error(33,(117),(105),__FILE__,353); | - | ||||||||||||||||||
395 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
396 | } | - | ||||||||||||||||||
397 | } executed 25 times by 1 test: end of block Executed by:
| 25 | ||||||||||||||||||
398 | - | |||||||||||||||||||
399 | ret = 1; | - | ||||||||||||||||||
400 | - | |||||||||||||||||||
401 | err: code before this statement executed 12 times by 1 test: err: Executed by:
| 12 | ||||||||||||||||||
402 | X509_STORE_CTX_free(cert_ctx); | - | ||||||||||||||||||
403 | CRYPTO_free(buf, __FILE__, 362); | - | ||||||||||||||||||
404 | if (tmpin == indata
| 2-10 | ||||||||||||||||||
405 | if (indata
| 3-7 | ||||||||||||||||||
406 | BIO_pop(p7bio); executed 3 times by 1 test: BIO_pop(p7bio); Executed by:
| 3 | ||||||||||||||||||
407 | } executed 10 times by 1 test: end of block Executed by:
| 10 | ||||||||||||||||||
408 | BIO_free_all(p7bio); | - | ||||||||||||||||||
409 | sk_X509_free(signers); | - | ||||||||||||||||||
410 | return executed 12 times by 1 test: ret;return ret; Executed by:
executed 12 times by 1 test: return ret; Executed by:
| 12 | ||||||||||||||||||
411 | } | - | ||||||||||||||||||
412 | - | |||||||||||||||||||
413 | struct stack_st_X509 *PKCS7_get0_signers(PKCS7 *p7, struct stack_st_X509 *certs, | - | ||||||||||||||||||
414 | int flags) | - | ||||||||||||||||||
415 | { | - | ||||||||||||||||||
416 | struct stack_st_X509 *signers; | - | ||||||||||||||||||
417 | struct stack_st_PKCS7_SIGNER_INFO *sinfos; | - | ||||||||||||||||||
418 | PKCS7_SIGNER_INFO *si; | - | ||||||||||||||||||
419 | PKCS7_ISSUER_AND_SERIAL *ias; | - | ||||||||||||||||||
420 | X509 *signer; | - | ||||||||||||||||||
421 | int i; | - | ||||||||||||||||||
422 | - | |||||||||||||||||||
423 | if (!p7
| 0-24 | ||||||||||||||||||
424 | ERR_put_error(33,(124),(143),__FILE__,383); | - | ||||||||||||||||||
425 | return never executed: return ((void *)0) ; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
426 | ((void *)0) never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
427 | ; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
428 | } | - | ||||||||||||||||||
429 | - | |||||||||||||||||||
430 | if (!(OBJ_obj2nid((p7)->type) == 22)
| 0-24 | ||||||||||||||||||
431 | ERR_put_error(33,(124),(113),__FILE__,388); | - | ||||||||||||||||||
432 | return never executed: return ((void *)0) ; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
433 | ((void *)0) never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
434 | ; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
435 | } | - | ||||||||||||||||||
436 | - | |||||||||||||||||||
437 | - | |||||||||||||||||||
438 | - | |||||||||||||||||||
439 | sinfos = PKCS7_get_signer_info(p7); | - | ||||||||||||||||||
440 | - | |||||||||||||||||||
441 | if (sk_PKCS7_SIGNER_INFO_num(sinfos) <= 0
| 0-24 | ||||||||||||||||||
442 | ERR_put_error(33,(124),(142),__FILE__,397); | - | ||||||||||||||||||
443 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
444 | } | - | ||||||||||||||||||
445 | - | |||||||||||||||||||
446 | if ((
| 0-24 | ||||||||||||||||||
447 | ((void *)0)
| 0-24 | ||||||||||||||||||
448 | ) { | - | ||||||||||||||||||
449 | ERR_put_error(33,(124),((1|64)),__FILE__,402); | - | ||||||||||||||||||
450 | return never executed: return ((void *)0) ; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
451 | ((void *)0) never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
452 | ; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
453 | } | - | ||||||||||||||||||
454 | - | |||||||||||||||||||
455 | for (i = 0; i < sk_PKCS7_SIGNER_INFO_num(sinfos)
| 24-50 | ||||||||||||||||||
456 | si = sk_PKCS7_SIGNER_INFO_value(sinfos, i); | - | ||||||||||||||||||
457 | ias = si->issuer_and_serial; | - | ||||||||||||||||||
458 | signer = | - | ||||||||||||||||||
459 | ((void *)0) | - | ||||||||||||||||||
460 | ; | - | ||||||||||||||||||
461 | - | |||||||||||||||||||
462 | if (certs
| 0-50 | ||||||||||||||||||
463 | signer = X509_find_by_issuer_and_serial(certs, never executed: signer = X509_find_by_issuer_and_serial(certs, ias->issuer, ias->serial); | 0 | ||||||||||||||||||
464 | ias->issuer, ias->serial); never executed: signer = X509_find_by_issuer_and_serial(certs, ias->issuer, ias->serial); | 0 | ||||||||||||||||||
465 | if (!signer
| 0-50 | ||||||||||||||||||
466 | && p7->d.sign->cert
| 0-50 | ||||||||||||||||||
467 | signer = executed 50 times by 1 test: signer = X509_find_by_issuer_and_serial(p7->d.sign->cert, ias->issuer, ias->serial); Executed by:
| 50 | ||||||||||||||||||
468 | X509_find_by_issuer_and_serial(p7->d.sign->cert, executed 50 times by 1 test: signer = X509_find_by_issuer_and_serial(p7->d.sign->cert, ias->issuer, ias->serial); Executed by:
| 50 | ||||||||||||||||||
469 | ias->issuer, ias->serial); executed 50 times by 1 test: signer = X509_find_by_issuer_and_serial(p7->d.sign->cert, ias->issuer, ias->serial); Executed by:
| 50 | ||||||||||||||||||
470 | if (!signer
| 0-50 | ||||||||||||||||||
471 | ERR_put_error(33,(124),(128),__FILE__,421) | - | ||||||||||||||||||
472 | ; | - | ||||||||||||||||||
473 | sk_X509_free(signers); | - | ||||||||||||||||||
474 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
475 | } | - | ||||||||||||||||||
476 | - | |||||||||||||||||||
477 | if (!sk_X509_push(signers, signer)
| 0-50 | ||||||||||||||||||
478 | sk_X509_free(signers); | - | ||||||||||||||||||
479 | return never executed: return ((void *)0) ; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
480 | ((void *)0) never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
481 | ; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
482 | } | - | ||||||||||||||||||
483 | } executed 50 times by 1 test: end of block Executed by:
| 50 | ||||||||||||||||||
484 | return executed 24 times by 1 test: signers;return signers; Executed by:
executed 24 times by 1 test: return signers; Executed by:
| 24 | ||||||||||||||||||
485 | } | - | ||||||||||||||||||
486 | - | |||||||||||||||||||
487 | - | |||||||||||||||||||
488 | - | |||||||||||||||||||
489 | PKCS7 *PKCS7_encrypt(struct stack_st_X509 *certs, BIO *in, const EVP_CIPHER *cipher, | - | ||||||||||||||||||
490 | int flags) | - | ||||||||||||||||||
491 | { | - | ||||||||||||||||||
492 | PKCS7 *p7; | - | ||||||||||||||||||
493 | BIO *p7bio = | - | ||||||||||||||||||
494 | ((void *)0) | - | ||||||||||||||||||
495 | ; | - | ||||||||||||||||||
496 | int i; | - | ||||||||||||||||||
497 | X509 *x509; | - | ||||||||||||||||||
498 | if ((
| 0-4 | ||||||||||||||||||
499 | ((void *)0)
| 0-4 | ||||||||||||||||||
500 | ) { | - | ||||||||||||||||||
501 | ERR_put_error(33,(115),((1|64)),__FILE__,444); | - | ||||||||||||||||||
502 | return never executed: return ((void *)0) ; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
503 | ((void *)0) never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
504 | ; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
505 | } | - | ||||||||||||||||||
506 | - | |||||||||||||||||||
507 | if (!PKCS7_set_type(p7, 23)
| 0-4 | ||||||||||||||||||
508 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
509 | if (!PKCS7_set_cipher(p7, cipher)
| 0-4 | ||||||||||||||||||
510 | ERR_put_error(33,(115),(121),__FILE__,451); | - | ||||||||||||||||||
511 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
512 | } | - | ||||||||||||||||||
513 | - | |||||||||||||||||||
514 | for (i = 0; i < sk_X509_num(certs)
| 4-12 | ||||||||||||||||||
515 | x509 = sk_X509_value(certs, i); | - | ||||||||||||||||||
516 | if (!PKCS7_add_recipient(p7, x509)
| 0-12 | ||||||||||||||||||
517 | ERR_put_error(33,(115),(120),__FILE__,458); | - | ||||||||||||||||||
518 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
519 | } | - | ||||||||||||||||||
520 | } executed 12 times by 1 test: end of block Executed by:
| 12 | ||||||||||||||||||
521 | - | |||||||||||||||||||
522 | if (flags & 0x1000
| 0-4 | ||||||||||||||||||
523 | return executed 4 times by 1 test: p7;return p7; Executed by:
executed 4 times by 1 test: return p7; Executed by:
| 4 | ||||||||||||||||||
524 | - | |||||||||||||||||||
525 | if (PKCS7_final(p7, in, flags)
| 0 | ||||||||||||||||||
526 | return never executed: p7;return p7; never executed: return p7; | 0 | ||||||||||||||||||
527 | - | |||||||||||||||||||
528 | err: code before this statement never executed: err: | 0 | ||||||||||||||||||
529 | - | |||||||||||||||||||
530 | BIO_free_all(p7bio); | - | ||||||||||||||||||
531 | PKCS7_free(p7); | - | ||||||||||||||||||
532 | return never executed: return ((void *)0) ; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
533 | ((void *)0) never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
534 | ; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
535 | - | |||||||||||||||||||
536 | } | - | ||||||||||||||||||
537 | - | |||||||||||||||||||
538 | int PKCS7_decrypt(PKCS7 *p7, EVP_PKEY *pkey, X509 *cert, BIO *data, int flags) | - | ||||||||||||||||||
539 | { | - | ||||||||||||||||||
540 | BIO *tmpmem; | - | ||||||||||||||||||
541 | int ret = 0, i; | - | ||||||||||||||||||
542 | char *buf = | - | ||||||||||||||||||
543 | ((void *)0) | - | ||||||||||||||||||
544 | ; | - | ||||||||||||||||||
545 | - | |||||||||||||||||||
546 | if (!p7
| 0-4 | ||||||||||||||||||
547 | ERR_put_error(33,(114),(143),__FILE__,484); | - | ||||||||||||||||||
548 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
549 | } | - | ||||||||||||||||||
550 | - | |||||||||||||||||||
551 | if (!(OBJ_obj2nid((p7)->type) == 23)
| 0-4 | ||||||||||||||||||
552 | ERR_put_error(33,(114),(113),__FILE__,489); | - | ||||||||||||||||||
553 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
554 | } | - | ||||||||||||||||||
555 | - | |||||||||||||||||||
556 | if (cert
| 0-3 | ||||||||||||||||||
557 | ERR_put_error(33,(114),(127),__FILE__,495) | - | ||||||||||||||||||
558 | ; | - | ||||||||||||||||||
559 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
560 | } | - | ||||||||||||||||||
561 | - | |||||||||||||||||||
562 | if ((
| 0-4 | ||||||||||||||||||
563 | ((void *)0)
| 0-4 | ||||||||||||||||||
564 | , cert)) ==
| 0-4 | ||||||||||||||||||
565 | ((void *)0)
| 0-4 | ||||||||||||||||||
566 | ) { | - | ||||||||||||||||||
567 | ERR_put_error(33,(114),(119),__FILE__,500); | - | ||||||||||||||||||
568 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
569 | } | - | ||||||||||||||||||
570 | - | |||||||||||||||||||
571 | if (flags & 0x1
| 0-4 | ||||||||||||||||||
572 | BIO *tmpbuf, *bread; | - | ||||||||||||||||||
573 | - | |||||||||||||||||||
574 | if ((
| 0 | ||||||||||||||||||
575 | ((void *)0)
| 0 | ||||||||||||||||||
576 | ) { | - | ||||||||||||||||||
577 | ERR_put_error(33,(114),((1|64)),__FILE__,508); | - | ||||||||||||||||||
578 | BIO_free_all(tmpmem); | - | ||||||||||||||||||
579 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
580 | } | - | ||||||||||||||||||
581 | if ((
| 0 | ||||||||||||||||||
582 | ((void *)0)
| 0 | ||||||||||||||||||
583 | ) { | - | ||||||||||||||||||
584 | ERR_put_error(33,(114),((1|64)),__FILE__,513); | - | ||||||||||||||||||
585 | BIO_free_all(tmpbuf); | - | ||||||||||||||||||
586 | BIO_free_all(tmpmem); | - | ||||||||||||||||||
587 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||||||||
588 | } | - | ||||||||||||||||||
589 | ret = SMIME_text(bread, data); | - | ||||||||||||||||||
590 | if (ret > 0
| 0 | ||||||||||||||||||
591 | if (!BIO_ctrl(tmpmem,113,0,
| 0 | ||||||||||||||||||
592 | ((void *)0)
| 0 | ||||||||||||||||||
593 | )
| 0 | ||||||||||||||||||
594 | ret = 0; never executed: ret = 0; | 0 | ||||||||||||||||||
595 | } never executed: end of block | 0 | ||||||||||||||||||
596 | BIO_free_all(bread); | - | ||||||||||||||||||
597 | return never executed: ret;return ret; never executed: return ret; | 0 | ||||||||||||||||||
598 | } | - | ||||||||||||||||||
599 | if ((
| 0-4 | ||||||||||||||||||
600 | ((void *)0)
| 0-4 | ||||||||||||||||||
601 | ) { | - | ||||||||||||||||||
602 | ERR_put_error(33,(114),((1|64)),__FILE__,527); | - | ||||||||||||||||||
603 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||||||||
604 | } | - | ||||||||||||||||||
605 | for (;;) { | - | ||||||||||||||||||
606 | i = BIO_read(tmpmem, buf, 4096); | - | ||||||||||||||||||
607 | if (i <= 0
| 4 | ||||||||||||||||||
608 | ret = 1; | - | ||||||||||||||||||
609 | if (BIO_method_type(tmpmem) == (10|0x0200)
| 0-4 | ||||||||||||||||||
610 | if (!BIO_ctrl(tmpmem,113,0,
| 0-4 | ||||||||||||||||||
611 | ((void *)0)
| 0-4 | ||||||||||||||||||
612 | )
| 0-4 | ||||||||||||||||||
613 | ret = 0; never executed: ret = 0; | 0 | ||||||||||||||||||
614 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||
615 | - | |||||||||||||||||||
616 | break; executed 4 times by 1 test: break; Executed by:
| 4 | ||||||||||||||||||
617 | } | - | ||||||||||||||||||
618 | if (BIO_write(data, buf, i) != i
| 0-4 | ||||||||||||||||||
619 | break; never executed: break; | 0 | ||||||||||||||||||
620 | } | - | ||||||||||||||||||
621 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||
622 | err: code before this statement executed 4 times by 1 test: err: Executed by:
| 4 | ||||||||||||||||||
623 | CRYPTO_free(buf, __FILE__, 546); | - | ||||||||||||||||||
624 | BIO_free_all(tmpmem); | - | ||||||||||||||||||
625 | return executed 4 times by 1 test: ret;return ret; Executed by:
executed 4 times by 1 test: return ret; Executed by:
| 4 | ||||||||||||||||||
626 | } | - | ||||||||||||||||||
Switch to Source code | Preprocessed file |