Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/libressl/src/tls/tls.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||
2 | - | |||||||||||||
3 | - | |||||||||||||
4 | - | |||||||||||||
5 | - | |||||||||||||
6 | - | |||||||||||||
7 | static struct tls_config *tls_config_default; | - | ||||||||||||
8 | - | |||||||||||||
9 | static int tls_init_rv = -1; | - | ||||||||||||
10 | - | |||||||||||||
11 | static void | - | ||||||||||||
12 | tls_do_init(void) | - | ||||||||||||
13 | { | - | ||||||||||||
14 | OPENSSL_init_ssl(0x00000001L, | - | ||||||||||||
15 | ((void *)0) | - | ||||||||||||
16 | ); | - | ||||||||||||
17 | - | |||||||||||||
18 | if (BIO_sock_init() != 1
| 0-3 | ||||||||||||
19 | return; never executed: return; | 0 | ||||||||||||
20 | - | |||||||||||||
21 | if ((
| 0-3 | ||||||||||||
22 | ((void *)0)
| 0-3 | ||||||||||||
23 | ) | - | ||||||||||||
24 | return; never executed: return; | 0 | ||||||||||||
25 | - | |||||||||||||
26 | tls_config_default->refcount++; | - | ||||||||||||
27 | - | |||||||||||||
28 | tls_init_rv = 0; | - | ||||||||||||
29 | } executed 3 times by 3 tests: end of block Executed by:
| 3 | ||||||||||||
30 | - | |||||||||||||
31 | int | - | ||||||||||||
32 | tls_init(void) | - | ||||||||||||
33 | { | - | ||||||||||||
34 | static pthread_once_t once = | - | ||||||||||||
35 | 0 | - | ||||||||||||
36 | ; | - | ||||||||||||
37 | - | |||||||||||||
38 | if (pthread_once(&once, tls_do_init) != 0
| 0-38 | ||||||||||||
39 | return never executed: -1;return -1; never executed: return -1; | 0 | ||||||||||||
40 | - | |||||||||||||
41 | return executed 38 times by 3 tests: tls_init_rv;return tls_init_rv; Executed by:
executed 38 times by 3 tests: return tls_init_rv; Executed by:
| 38 | ||||||||||||
42 | } | - | ||||||||||||
43 | - | |||||||||||||
44 | const char * | - | ||||||||||||
45 | tls_error(struct tls *ctx) | - | ||||||||||||
46 | { | - | ||||||||||||
47 | return never executed: ctx->error.msg;return ctx->error.msg; never executed: return ctx->error.msg; | 0 | ||||||||||||
48 | } | - | ||||||||||||
49 | - | |||||||||||||
50 | void | - | ||||||||||||
51 | tls_error_clear(struct tls_error *error) | - | ||||||||||||
52 | { | - | ||||||||||||
53 | free(error->msg); | - | ||||||||||||
54 | error->msg = | - | ||||||||||||
55 | ((void *)0) | - | ||||||||||||
56 | ; | - | ||||||||||||
57 | error->num = 0; | - | ||||||||||||
58 | error->tls = 0; | - | ||||||||||||
59 | } executed 53 times by 2 tests: end of block Executed by:
| 53 | ||||||||||||
60 | - | |||||||||||||
61 | static int | - | ||||||||||||
62 | tls_error_vset(struct tls_error *error, int errnum, const char *fmt, va_list ap) | - | ||||||||||||
63 | { | - | ||||||||||||
64 | char *errmsg = | - | ||||||||||||
65 | ((void *)0) | - | ||||||||||||
66 | ; | - | ||||||||||||
67 | int rv = -1; | - | ||||||||||||
68 | - | |||||||||||||
69 | tls_error_clear(error); | - | ||||||||||||
70 | - | |||||||||||||
71 | error->num = errnum; | - | ||||||||||||
72 | error->tls = 1; | - | ||||||||||||
73 | - | |||||||||||||
74 | if (vasprintf(&errmsg, fmt, ap) == -1
| 0-14 | ||||||||||||
75 | errmsg = | - | ||||||||||||
76 | ((void *)0) | - | ||||||||||||
77 | ; | - | ||||||||||||
78 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
79 | } | - | ||||||||||||
80 | - | |||||||||||||
81 | if (errnum == -1
| 0-14 | ||||||||||||
82 | error->msg = errmsg; | - | ||||||||||||
83 | return executed 14 times by 2 tests: (0);return (0); Executed by:
executed 14 times by 2 tests: return (0); Executed by:
| 14 | ||||||||||||
84 | } | - | ||||||||||||
85 | - | |||||||||||||
86 | if (asprintf(&error->msg, "%s: %s", errmsg, strerror(errnum)) == -1
| 0 | ||||||||||||
87 | error->msg = | - | ||||||||||||
88 | ((void *)0) | - | ||||||||||||
89 | ; | - | ||||||||||||
90 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
91 | } | - | ||||||||||||
92 | rv = 0; | - | ||||||||||||
93 | - | |||||||||||||
94 | err: code before this statement never executed: err: | 0 | ||||||||||||
95 | free(errmsg); | - | ||||||||||||
96 | - | |||||||||||||
97 | return never executed: (rv);return (rv); never executed: return (rv); | 0 | ||||||||||||
98 | } | - | ||||||||||||
99 | - | |||||||||||||
100 | int | - | ||||||||||||
101 | tls_error_set(struct tls_error *error, const char *fmt, ...) | - | ||||||||||||
102 | { | - | ||||||||||||
103 | va_list ap; | - | ||||||||||||
104 | int errnum, rv; | - | ||||||||||||
105 | - | |||||||||||||
106 | errnum = | - | ||||||||||||
107 | (*__errno_location ()) | - | ||||||||||||
108 | ; | - | ||||||||||||
109 | - | |||||||||||||
110 | - | |||||||||||||
111 | __builtin_va_start( | - | ||||||||||||
112 | ap | - | ||||||||||||
113 | , | - | ||||||||||||
114 | fmt | - | ||||||||||||
115 | ) | - | ||||||||||||
116 | ; | - | ||||||||||||
117 | rv = tls_error_vset(error, errnum, fmt, ap); | - | ||||||||||||
118 | - | |||||||||||||
119 | __builtin_va_end( | - | ||||||||||||
120 | ap | - | ||||||||||||
121 | ) | - | ||||||||||||
122 | ; | - | ||||||||||||
123 | - | |||||||||||||
124 | return never executed: (rv);return (rv); never executed: return (rv); | 0 | ||||||||||||
125 | } | - | ||||||||||||
126 | - | |||||||||||||
127 | int | - | ||||||||||||
128 | tls_error_setx(struct tls_error *error, const char *fmt, ...) | - | ||||||||||||
129 | { | - | ||||||||||||
130 | va_list ap; | - | ||||||||||||
131 | int rv; | - | ||||||||||||
132 | - | |||||||||||||
133 | - | |||||||||||||
134 | __builtin_va_start( | - | ||||||||||||
135 | ap | - | ||||||||||||
136 | , | - | ||||||||||||
137 | fmt | - | ||||||||||||
138 | ) | - | ||||||||||||
139 | ; | - | ||||||||||||
140 | rv = tls_error_vset(error, -1, fmt, ap); | - | ||||||||||||
141 | - | |||||||||||||
142 | __builtin_va_end( | - | ||||||||||||
143 | ap | - | ||||||||||||
144 | ) | - | ||||||||||||
145 | ; | - | ||||||||||||
146 | - | |||||||||||||
147 | return never executed: (rv);return (rv); never executed: return (rv); | 0 | ||||||||||||
148 | } | - | ||||||||||||
149 | - | |||||||||||||
150 | int | - | ||||||||||||
151 | tls_config_set_error(struct tls_config *config, const char *fmt, ...) | - | ||||||||||||
152 | { | - | ||||||||||||
153 | va_list ap; | - | ||||||||||||
154 | int errnum, rv; | - | ||||||||||||
155 | - | |||||||||||||
156 | errnum = | - | ||||||||||||
157 | (*__errno_location ()) | - | ||||||||||||
158 | ; | - | ||||||||||||
159 | - | |||||||||||||
160 | - | |||||||||||||
161 | __builtin_va_start( | - | ||||||||||||
162 | ap | - | ||||||||||||
163 | , | - | ||||||||||||
164 | fmt | - | ||||||||||||
165 | ) | - | ||||||||||||
166 | ; | - | ||||||||||||
167 | rv = tls_error_vset(&config->error, errnum, fmt, ap); | - | ||||||||||||
168 | - | |||||||||||||
169 | __builtin_va_end( | - | ||||||||||||
170 | ap | - | ||||||||||||
171 | ) | - | ||||||||||||
172 | ; | - | ||||||||||||
173 | - | |||||||||||||
174 | return never executed: (rv);return (rv); never executed: return (rv); | 0 | ||||||||||||
175 | } | - | ||||||||||||
176 | - | |||||||||||||
177 | int | - | ||||||||||||
178 | tls_config_set_errorx(struct tls_config *config, const char *fmt, ...) | - | ||||||||||||
179 | { | - | ||||||||||||
180 | va_list ap; | - | ||||||||||||
181 | int rv; | - | ||||||||||||
182 | - | |||||||||||||
183 | - | |||||||||||||
184 | __builtin_va_start( | - | ||||||||||||
185 | ap | - | ||||||||||||
186 | , | - | ||||||||||||
187 | fmt | - | ||||||||||||
188 | ) | - | ||||||||||||
189 | ; | - | ||||||||||||
190 | rv = tls_error_vset(&config->error, -1, fmt, ap); | - | ||||||||||||
191 | - | |||||||||||||
192 | __builtin_va_end( | - | ||||||||||||
193 | ap | - | ||||||||||||
194 | ) | - | ||||||||||||
195 | ; | - | ||||||||||||
196 | - | |||||||||||||
197 | return never executed: (rv);return (rv); never executed: return (rv); | 0 | ||||||||||||
198 | } | - | ||||||||||||
199 | - | |||||||||||||
200 | int | - | ||||||||||||
201 | tls_set_error(struct tls *ctx, const char *fmt, ...) | - | ||||||||||||
202 | { | - | ||||||||||||
203 | va_list ap; | - | ||||||||||||
204 | int errnum, rv; | - | ||||||||||||
205 | - | |||||||||||||
206 | errnum = | - | ||||||||||||
207 | (*__errno_location ()) | - | ||||||||||||
208 | ; | - | ||||||||||||
209 | - | |||||||||||||
210 | - | |||||||||||||
211 | __builtin_va_start( | - | ||||||||||||
212 | ap | - | ||||||||||||
213 | , | - | ||||||||||||
214 | fmt | - | ||||||||||||
215 | ) | - | ||||||||||||
216 | ; | - | ||||||||||||
217 | rv = tls_error_vset(&ctx->error, errnum, fmt, ap); | - | ||||||||||||
218 | - | |||||||||||||
219 | __builtin_va_end( | - | ||||||||||||
220 | ap | - | ||||||||||||
221 | ) | - | ||||||||||||
222 | ; | - | ||||||||||||
223 | - | |||||||||||||
224 | return never executed: (rv);return (rv); never executed: return (rv); | 0 | ||||||||||||
225 | } | - | ||||||||||||
226 | - | |||||||||||||
227 | int | - | ||||||||||||
228 | tls_set_errorx(struct tls *ctx, const char *fmt, ...) | - | ||||||||||||
229 | { | - | ||||||||||||
230 | va_list ap; | - | ||||||||||||
231 | int rv; | - | ||||||||||||
232 | - | |||||||||||||
233 | - | |||||||||||||
234 | __builtin_va_start( | - | ||||||||||||
235 | ap | - | ||||||||||||
236 | , | - | ||||||||||||
237 | fmt | - | ||||||||||||
238 | ) | - | ||||||||||||
239 | ; | - | ||||||||||||
240 | rv = tls_error_vset(&ctx->error, -1, fmt, ap); | - | ||||||||||||
241 | - | |||||||||||||
242 | __builtin_va_end( | - | ||||||||||||
243 | ap | - | ||||||||||||
244 | ) | - | ||||||||||||
245 | ; | - | ||||||||||||
246 | - | |||||||||||||
247 | return executed 14 times by 2 tests: (rv);return (rv); Executed by:
executed 14 times by 2 tests: return (rv); Executed by:
| 14 | ||||||||||||
248 | } | - | ||||||||||||
249 | - | |||||||||||||
250 | int | - | ||||||||||||
251 | tls_set_ssl_errorx(struct tls *ctx, const char *fmt, ...) | - | ||||||||||||
252 | { | - | ||||||||||||
253 | va_list ap; | - | ||||||||||||
254 | int rv; | - | ||||||||||||
255 | - | |||||||||||||
256 | - | |||||||||||||
257 | if (ctx->error.tls != 0
| 0 | ||||||||||||
258 | return never executed: (0);return (0); never executed: return (0); | 0 | ||||||||||||
259 | - | |||||||||||||
260 | - | |||||||||||||
261 | __builtin_va_start( | - | ||||||||||||
262 | ap | - | ||||||||||||
263 | , | - | ||||||||||||
264 | fmt | - | ||||||||||||
265 | ) | - | ||||||||||||
266 | ; | - | ||||||||||||
267 | rv = tls_error_vset(&ctx->error, -1, fmt, ap); | - | ||||||||||||
268 | - | |||||||||||||
269 | __builtin_va_end( | - | ||||||||||||
270 | ap | - | ||||||||||||
271 | ) | - | ||||||||||||
272 | ; | - | ||||||||||||
273 | - | |||||||||||||
274 | return never executed: (rv);return (rv); never executed: return (rv); | 0 | ||||||||||||
275 | } | - | ||||||||||||
276 | - | |||||||||||||
277 | struct tls_sni_ctx * | - | ||||||||||||
278 | tls_sni_ctx_new(void) | - | ||||||||||||
279 | { | - | ||||||||||||
280 | return never executed: (calloc(1, sizeof(struct tls_sni_ctx)));return (calloc(1, sizeof(struct tls_sni_ctx))); never executed: return (calloc(1, sizeof(struct tls_sni_ctx))); | 0 | ||||||||||||
281 | } | - | ||||||||||||
282 | - | |||||||||||||
283 | void | - | ||||||||||||
284 | tls_sni_ctx_free(struct tls_sni_ctx *sni_ctx) | - | ||||||||||||
285 | { | - | ||||||||||||
286 | if (sni_ctx ==
| 0 | ||||||||||||
287 | ((void *)0)
| 0 | ||||||||||||
288 | ) | - | ||||||||||||
289 | return; never executed: return; | 0 | ||||||||||||
290 | - | |||||||||||||
291 | SSL_CTX_free(sni_ctx->ssl_ctx); | - | ||||||||||||
292 | X509_free(sni_ctx->ssl_cert); | - | ||||||||||||
293 | - | |||||||||||||
294 | free(sni_ctx); | - | ||||||||||||
295 | } never executed: end of block | 0 | ||||||||||||
296 | - | |||||||||||||
297 | struct tls * | - | ||||||||||||
298 | tls_new(void) | - | ||||||||||||
299 | { | - | ||||||||||||
300 | struct tls *ctx; | - | ||||||||||||
301 | - | |||||||||||||
302 | if ((
| 0-36 | ||||||||||||
303 | ((void *)0)
| 0-36 | ||||||||||||
304 | ) | - | ||||||||||||
305 | return never executed: (return ( ((void *)0) ); never executed: return ( ((void *)0) ); | 0 | ||||||||||||
306 | ((void *)0) never executed: return ( ((void *)0) ); | 0 | ||||||||||||
307 | ); never executed: return ( ((void *)0) ); | 0 | ||||||||||||
308 | - | |||||||||||||
309 | tls_reset(ctx); | - | ||||||||||||
310 | - | |||||||||||||
311 | if (tls_configure(ctx, tls_config_default) == -1
| 0-36 | ||||||||||||
312 | free(ctx); | - | ||||||||||||
313 | return never executed: return ((void *)0) ; never executed: return ((void *)0) ; | 0 | ||||||||||||
314 | ((void *)0) never executed: return ((void *)0) ; | 0 | ||||||||||||
315 | ; never executed: return ((void *)0) ; | 0 | ||||||||||||
316 | } | - | ||||||||||||
317 | - | |||||||||||||
318 | return executed 36 times by 2 tests: (ctx);return (ctx); Executed by:
executed 36 times by 2 tests: return (ctx); Executed by:
| 36 | ||||||||||||
319 | } | - | ||||||||||||
320 | - | |||||||||||||
321 | int | - | ||||||||||||
322 | tls_configure(struct tls *ctx, struct tls_config *config) | - | ||||||||||||
323 | { | - | ||||||||||||
324 | if (config ==
| 0-44 | ||||||||||||
325 | ((void *)0)
| 0-44 | ||||||||||||
326 | ) | - | ||||||||||||
327 | config = tls_config_default; never executed: config = tls_config_default; | 0 | ||||||||||||
328 | - | |||||||||||||
329 | config->refcount++; | - | ||||||||||||
330 | - | |||||||||||||
331 | tls_config_free(ctx->config); | - | ||||||||||||
332 | - | |||||||||||||
333 | ctx->config = config; | - | ||||||||||||
334 | ctx->keypair = config->keypair; | - | ||||||||||||
335 | - | |||||||||||||
336 | if ((
| 4-40 | ||||||||||||
337 | return executed 4 times by 1 test: (tls_configure_server(ctx));return (tls_configure_server(ctx)); Executed by:
executed 4 times by 1 test: return (tls_configure_server(ctx)); Executed by:
| 4 | ||||||||||||
338 | - | |||||||||||||
339 | return executed 40 times by 2 tests: (0);return (0); Executed by:
executed 40 times by 2 tests: return (0); Executed by:
| 40 | ||||||||||||
340 | } | - | ||||||||||||
341 | - | |||||||||||||
342 | int | - | ||||||||||||
343 | tls_cert_hash(X509 *cert, char **hash) | - | ||||||||||||
344 | { | - | ||||||||||||
345 | char d[64], *dhex = | - | ||||||||||||
346 | ((void *)0) | - | ||||||||||||
347 | ; | - | ||||||||||||
348 | int dlen, rv = -1; | - | ||||||||||||
349 | - | |||||||||||||
350 | free(*hash); | - | ||||||||||||
351 | *hash = | - | ||||||||||||
352 | ((void *)0) | - | ||||||||||||
353 | ; | - | ||||||||||||
354 | - | |||||||||||||
355 | if (X509_digest(cert, EVP_sha256(), d, &dlen) != 1
| 0-4 | ||||||||||||
356 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
357 | - | |||||||||||||
358 | if (tls_hex_string(d, dlen, &dhex,
| 0-4 | ||||||||||||
359 | ((void *)0)
| 0-4 | ||||||||||||
360 | ) != 0
| 0-4 | ||||||||||||
361 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
362 | - | |||||||||||||
363 | if (asprintf(hash, "SHA256:%s", dhex) == -1
| 0-4 | ||||||||||||
364 | *hash = | - | ||||||||||||
365 | ((void *)0) | - | ||||||||||||
366 | ; | - | ||||||||||||
367 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
368 | } | - | ||||||||||||
369 | - | |||||||||||||
370 | rv = 0; | - | ||||||||||||
371 | err: code before this statement executed 4 times by 1 test: err: Executed by:
| 4 | ||||||||||||
372 | free(dhex); | - | ||||||||||||
373 | - | |||||||||||||
374 | return executed 4 times by 1 test: (rv);return (rv); Executed by:
executed 4 times by 1 test: return (rv); Executed by:
| 4 | ||||||||||||
375 | } | - | ||||||||||||
376 | - | |||||||||||||
377 | int | - | ||||||||||||
378 | tls_cert_pubkey_hash(X509 *cert, char **hash) | - | ||||||||||||
379 | { | - | ||||||||||||
380 | char d[64], *dhex = | - | ||||||||||||
381 | ((void *)0) | - | ||||||||||||
382 | ; | - | ||||||||||||
383 | int dlen, rv = -1; | - | ||||||||||||
384 | - | |||||||||||||
385 | free(*hash); | - | ||||||||||||
386 | *hash = | - | ||||||||||||
387 | ((void *)0) | - | ||||||||||||
388 | ; | - | ||||||||||||
389 | - | |||||||||||||
390 | if (X509_pubkey_digest(cert, EVP_sha256(), d, &dlen) != 1
| 0-4 | ||||||||||||
391 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
392 | - | |||||||||||||
393 | if (tls_hex_string(d, dlen, &dhex,
| 0-4 | ||||||||||||
394 | ((void *)0)
| 0-4 | ||||||||||||
395 | ) != 0
| 0-4 | ||||||||||||
396 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
397 | - | |||||||||||||
398 | if (asprintf(hash, "SHA256:%s", dhex) == -1
| 0-4 | ||||||||||||
399 | *hash = | - | ||||||||||||
400 | ((void *)0) | - | ||||||||||||
401 | ; | - | ||||||||||||
402 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
403 | } | - | ||||||||||||
404 | - | |||||||||||||
405 | rv = 0; | - | ||||||||||||
406 | - | |||||||||||||
407 | err: code before this statement executed 4 times by 2 tests: err: Executed by:
| 4 | ||||||||||||
408 | free(dhex); | - | ||||||||||||
409 | - | |||||||||||||
410 | return executed 4 times by 2 tests: (rv);return (rv); Executed by:
executed 4 times by 2 tests: return (rv); Executed by:
| 4 | ||||||||||||
411 | } | - | ||||||||||||
412 | - | |||||||||||||
413 | int | - | ||||||||||||
414 | tls_configure_ssl_keypair(struct tls *ctx, SSL_CTX *ssl_ctx, | - | ||||||||||||
415 | struct tls_keypair *keypair, int required) | - | ||||||||||||
416 | { | - | ||||||||||||
417 | EVP_PKEY *pkey = | - | ||||||||||||
418 | ((void *)0) | - | ||||||||||||
419 | ; | - | ||||||||||||
420 | BIO *bio = | - | ||||||||||||
421 | ((void *)0) | - | ||||||||||||
422 | ; | - | ||||||||||||
423 | - | |||||||||||||
424 | if (!required
| 4 | ||||||||||||
425 | keypair->cert_mem ==
| 0-4 | ||||||||||||
426 | ((void *)0)
| 0-4 | ||||||||||||
427 | && | - | ||||||||||||
428 | keypair->key_mem ==
| 0-4 | ||||||||||||
429 | ((void *)0)
| 0-4 | ||||||||||||
430 | ) | - | ||||||||||||
431 | return executed 4 times by 1 test: (0);return(0); Executed by:
executed 4 times by 1 test: return(0); Executed by:
| 4 | ||||||||||||
432 | - | |||||||||||||
433 | if (keypair->cert_mem !=
| 0-4 | ||||||||||||
434 | ((void *)0)
| 0-4 | ||||||||||||
435 | ) { | - | ||||||||||||
436 | if (keypair->cert_len > 0x7fffffff
| 0-4 | ||||||||||||
437 | tls_set_errorx(ctx, "certificate too long"); | - | ||||||||||||
438 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
439 | } | - | ||||||||||||
440 | - | |||||||||||||
441 | if (SSL_CTX_use_certificate_chain_mem(ssl_ctx,
| 0-4 | ||||||||||||
442 | keypair->cert_mem, keypair->cert_len) != 1
| 0-4 | ||||||||||||
443 | tls_set_errorx(ctx, "failed to load certificate"); | - | ||||||||||||
444 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
445 | } | - | ||||||||||||
446 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||
447 | - | |||||||||||||
448 | if (keypair->key_mem !=
| 0-4 | ||||||||||||
449 | ((void *)0)
| 0-4 | ||||||||||||
450 | ) { | - | ||||||||||||
451 | if (keypair->key_len > 0x7fffffff
| 0-4 | ||||||||||||
452 | tls_set_errorx(ctx, "key too long"); | - | ||||||||||||
453 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
454 | } | - | ||||||||||||
455 | - | |||||||||||||
456 | if ((
| 0-4 | ||||||||||||
457 | keypair->key_len)) ==
| 0-4 | ||||||||||||
458 | ((void *)0)
| 0-4 | ||||||||||||
459 | ) { | - | ||||||||||||
460 | tls_set_errorx(ctx, "failed to create buffer"); | - | ||||||||||||
461 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
462 | } | - | ||||||||||||
463 | if ((
| 0-4 | ||||||||||||
464 | ((void *)0)
| 0-4 | ||||||||||||
465 | , tls_password_cb,
| 0-4 | ||||||||||||
466 |
| 0-4 | ||||||||||||
467 | ((void *)0)
| 0-4 | ||||||||||||
468 | )) ==
| 0-4 | ||||||||||||
469 | ((void *)0)
| 0-4 | ||||||||||||
470 | ) { | - | ||||||||||||
471 | tls_set_errorx(ctx, "failed to read private key"); | - | ||||||||||||
472 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
473 | } | - | ||||||||||||
474 | - | |||||||||||||
475 | if (keypair->pubkey_hash !=
| 0-4 | ||||||||||||
476 | ((void *)0)
| 0-4 | ||||||||||||
477 | ) { | - | ||||||||||||
478 | RSA *rsa; | - | ||||||||||||
479 | - | |||||||||||||
480 | if ((
| 0-4 | ||||||||||||
481 | ((void *)0)
| 0-4 | ||||||||||||
482 | ) { | - | ||||||||||||
483 | RSA_set_ex_data(rsa, 0, keypair->pubkey_hash); | - | ||||||||||||
484 | RSA_free(rsa); | - | ||||||||||||
485 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||
486 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||
487 | - | |||||||||||||
488 | if (SSL_CTX_use_PrivateKey(ssl_ctx, pkey) != 1
| 0-4 | ||||||||||||
489 | tls_set_errorx(ctx, "failed to load private key"); | - | ||||||||||||
490 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
491 | } | - | ||||||||||||
492 | BIO_free(bio); | - | ||||||||||||
493 | bio = | - | ||||||||||||
494 | ((void *)0) | - | ||||||||||||
495 | ; | - | ||||||||||||
496 | EVP_PKEY_free(pkey); | - | ||||||||||||
497 | pkey = | - | ||||||||||||
498 | ((void *)0) | - | ||||||||||||
499 | ; | - | ||||||||||||
500 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||
501 | - | |||||||||||||
502 | if (!ctx->config->skip_private_key_check
| 0-4 | ||||||||||||
503 | SSL_CTX_check_private_key(ssl_ctx) != 1
| 0-4 | ||||||||||||
504 | tls_set_errorx(ctx, "private/public key mismatch"); | - | ||||||||||||
505 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
506 | } | - | ||||||||||||
507 | - | |||||||||||||
508 | return executed 4 times by 1 test: (0);return (0); Executed by:
executed 4 times by 1 test: return (0); Executed by:
| 4 | ||||||||||||
509 | - | |||||||||||||
510 | err: | - | ||||||||||||
511 | EVP_PKEY_free(pkey); | - | ||||||||||||
512 | BIO_free(bio); | - | ||||||||||||
513 | - | |||||||||||||
514 | return never executed: (1);return (1); never executed: return (1); | 0 | ||||||||||||
515 | } | - | ||||||||||||
516 | - | |||||||||||||
517 | int | - | ||||||||||||
518 | tls_configure_ssl(struct tls *ctx, SSL_CTX *ssl_ctx) | - | ||||||||||||
519 | { | - | ||||||||||||
520 | SSL_CTX_ctrl((ssl_ctx),33,(0x00000001L), | - | ||||||||||||
521 | ((void *)0) | - | ||||||||||||
522 | ); | - | ||||||||||||
523 | SSL_CTX_ctrl((ssl_ctx),33,(0x00000002L), | - | ||||||||||||
524 | ((void *)0) | - | ||||||||||||
525 | ); | - | ||||||||||||
526 | - | |||||||||||||
527 | SSL_CTX_ctrl((ssl_ctx),32,(0x0), | - | ||||||||||||
528 | ((void *)0) | - | ||||||||||||
529 | ); | - | ||||||||||||
530 | SSL_CTX_ctrl((ssl_ctx),32,(0x0), | - | ||||||||||||
531 | ((void *)0) | - | ||||||||||||
532 | ); | - | ||||||||||||
533 | - | |||||||||||||
534 | SSL_CTX_ctrl((ssl_ctx),77,(0x04000000L), | - | ||||||||||||
535 | ((void *)0) | - | ||||||||||||
536 | ); | - | ||||||||||||
537 | SSL_CTX_ctrl((ssl_ctx),77,(0x10000000L), | - | ||||||||||||
538 | ((void *)0) | - | ||||||||||||
539 | ); | - | ||||||||||||
540 | SSL_CTX_ctrl((ssl_ctx),77,(0x08000000L), | - | ||||||||||||
541 | ((void *)0) | - | ||||||||||||
542 | ); | - | ||||||||||||
543 | - | |||||||||||||
544 | if ((
| 0-8 | ||||||||||||
545 | SSL_CTX_ctrl((ssl_ctx),32,(0x04000000L), executed 8 times by 1 test: SSL_CTX_ctrl((ssl_ctx),32,(0x04000000L), ((void *)0) ); Executed by:
| 8 | ||||||||||||
546 | ((void *)0) executed 8 times by 1 test: SSL_CTX_ctrl((ssl_ctx),32,(0x04000000L), ((void *)0) ); Executed by:
| 8 | ||||||||||||
547 | ); executed 8 times by 1 test: SSL_CTX_ctrl((ssl_ctx),32,(0x04000000L), ((void *)0) ); Executed by:
| 8 | ||||||||||||
548 | if ((
| 0-8 | ||||||||||||
549 | SSL_CTX_ctrl((ssl_ctx),32,(0x10000000L), executed 8 times by 1 test: SSL_CTX_ctrl((ssl_ctx),32,(0x10000000L), ((void *)0) ); Executed by:
| 8 | ||||||||||||
550 | ((void *)0) executed 8 times by 1 test: SSL_CTX_ctrl((ssl_ctx),32,(0x10000000L), ((void *)0) ); Executed by:
| 8 | ||||||||||||
551 | ); executed 8 times by 1 test: SSL_CTX_ctrl((ssl_ctx),32,(0x10000000L), ((void *)0) ); Executed by:
| 8 | ||||||||||||
552 | if ((
| 0-8 | ||||||||||||
553 | SSL_CTX_ctrl((ssl_ctx),32,(0x08000000L), never executed: SSL_CTX_ctrl((ssl_ctx),32,(0x08000000L), ((void *)0) ); | 0 | ||||||||||||
554 | ((void *)0) never executed: SSL_CTX_ctrl((ssl_ctx),32,(0x08000000L), ((void *)0) ); | 0 | ||||||||||||
555 | ); never executed: SSL_CTX_ctrl((ssl_ctx),32,(0x08000000L), ((void *)0) ); | 0 | ||||||||||||
556 | - | |||||||||||||
557 | if (ctx->config->alpn !=
| 0-8 | ||||||||||||
558 | ((void *)0)
| 0-8 | ||||||||||||
559 | ) { | - | ||||||||||||
560 | if (SSL_CTX_set_alpn_protos(ssl_ctx, ctx->config->alpn,
| 0 | ||||||||||||
561 | ctx->config->alpn_len) != 0
| 0 | ||||||||||||
562 | tls_set_errorx(ctx, "failed to set alpn"); | - | ||||||||||||
563 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
564 | } | - | ||||||||||||
565 | } never executed: end of block | 0 | ||||||||||||
566 | - | |||||||||||||
567 | if (ctx->config->ciphers !=
| 0-8 | ||||||||||||
568 | ((void *)0)
| 0-8 | ||||||||||||
569 | ) { | - | ||||||||||||
570 | if (SSL_CTX_set_cipher_list(ssl_ctx,
| 0-8 | ||||||||||||
571 | ctx->config->ciphers) != 1
| 0-8 | ||||||||||||
572 | tls_set_errorx(ctx, "failed to set ciphers"); | - | ||||||||||||
573 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
574 | } | - | ||||||||||||
575 | } executed 8 times by 1 test: end of block Executed by:
| 8 | ||||||||||||
576 | - | |||||||||||||
577 | if (ctx->config->verify_time == 0
| 0-8 | ||||||||||||
578 | X509_VERIFY_PARAM_set_flags(ssl_ctx->param, | - | ||||||||||||
579 | 0x200000); | - | ||||||||||||
580 | } never executed: end of block | 0 | ||||||||||||
581 | - | |||||||||||||
582 | - | |||||||||||||
583 | SSL_CTX_ctrl(ssl_ctx,44,0x0000, | - | ||||||||||||
584 | ((void *)0) | - | ||||||||||||
585 | ); | - | ||||||||||||
586 | SSL_CTX_ctrl((ssl_ctx),32,(0x00004000L), | - | ||||||||||||
587 | ((void *)0) | - | ||||||||||||
588 | ); | - | ||||||||||||
589 | - | |||||||||||||
590 | return executed 8 times by 1 test: (0);return (0); Executed by:
executed 8 times by 1 test: return (0); Executed by:
| 8 | ||||||||||||
591 | - | |||||||||||||
592 | err: | - | ||||||||||||
593 | return never executed: (-1);return (-1); never executed: return (-1); | 0 | ||||||||||||
594 | } | - | ||||||||||||
595 | - | |||||||||||||
596 | static int | - | ||||||||||||
597 | tls_ssl_cert_verify_cb(X509_STORE_CTX *x509_ctx, void *arg) | - | ||||||||||||
598 | { | - | ||||||||||||
599 | struct tls *ctx = arg; | - | ||||||||||||
600 | int x509_err; | - | ||||||||||||
601 | - | |||||||||||||
602 | if (ctx->config->verify_cert == 0
| 0-4 | ||||||||||||
603 | return never executed: (1);return (1); never executed: return (1); | 0 | ||||||||||||
604 | - | |||||||||||||
605 | if ((
| 0-4 | ||||||||||||
606 | tls_set_errorx(ctx, "X509 verify cert failed"); | - | ||||||||||||
607 | return never executed: (0);return (0); never executed: return (0); | 0 | ||||||||||||
608 | } | - | ||||||||||||
609 | - | |||||||||||||
610 | x509_err = X509_STORE_CTX_get_error(x509_ctx); | - | ||||||||||||
611 | if (x509_err == 0
| 0-4 | ||||||||||||
612 | return executed 4 times by 1 test: (1);return (1); Executed by:
executed 4 times by 1 test: return (1); Executed by:
| 4 | ||||||||||||
613 | - | |||||||||||||
614 | tls_set_errorx(ctx, "certificate verification failed: %s", | - | ||||||||||||
615 | X509_verify_cert_error_string(x509_err)); | - | ||||||||||||
616 | - | |||||||||||||
617 | return never executed: (0);return (0); never executed: return (0); | 0 | ||||||||||||
618 | } | - | ||||||||||||
619 | - | |||||||||||||
620 | int | - | ||||||||||||
621 | tls_configure_ssl_verify(struct tls *ctx, SSL_CTX *ssl_ctx, int verify) | - | ||||||||||||
622 | { | - | ||||||||||||
623 | size_t ca_len = ctx->config->ca_len; | - | ||||||||||||
624 | char *ca_mem = ctx->config->ca_mem; | - | ||||||||||||
625 | char *crl_mem = ctx->config->crl_mem; | - | ||||||||||||
626 | size_t crl_len = ctx->config->crl_len; | - | ||||||||||||
627 | char *ca_free = | - | ||||||||||||
628 | ((void *)0) | - | ||||||||||||
629 | ; | - | ||||||||||||
630 | struct stack_st_X509_INFO *xis = | - | ||||||||||||
631 | ((void *)0) | - | ||||||||||||
632 | ; | - | ||||||||||||
633 | X509_STORE *store; | - | ||||||||||||
634 | X509_INFO *xi; | - | ||||||||||||
635 | BIO *bio = | - | ||||||||||||
636 | ((void *)0) | - | ||||||||||||
637 | ; | - | ||||||||||||
638 | int rv = -1; | - | ||||||||||||
639 | int i; | - | ||||||||||||
640 | - | |||||||||||||
641 | SSL_CTX_set_verify(ssl_ctx, verify, | - | ||||||||||||
642 | ((void *)0) | - | ||||||||||||
643 | ); | - | ||||||||||||
644 | SSL_CTX_set_cert_verify_callback(ssl_ctx, tls_ssl_cert_verify_cb, ctx); | - | ||||||||||||
645 | - | |||||||||||||
646 | if (ctx->config->verify_depth >= 0
| 0-4 | ||||||||||||
647 | SSL_CTX_set_verify_depth(ssl_ctx, ctx->config->verify_depth); executed 4 times by 1 test: SSL_CTX_set_verify_depth(ssl_ctx, ctx->config->verify_depth); Executed by:
| 4 | ||||||||||||
648 | - | |||||||||||||
649 | if (ctx->config->verify_cert == 0
| 0-4 | ||||||||||||
650 | goto never executed: done;goto done; never executed: goto done; | 0 | ||||||||||||
651 | - | |||||||||||||
652 | - | |||||||||||||
653 | if (ctx->config->ca_mem ==
| 0-4 | ||||||||||||
654 | ((void *)0)
| 0-4 | ||||||||||||
655 | && ctx->config->ca_path ==
| 0 | ||||||||||||
656 | ((void *)0)
| 0 | ||||||||||||
657 | ) { | - | ||||||||||||
658 | if (tls_config_load_file(&ctx->error, "CA", "/usr/local/etc/ssl/cert.pem",
| 0 | ||||||||||||
659 | &ca_mem, &ca_len) != 0
| 0 | ||||||||||||
660 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
661 | ca_free = ca_mem; | - | ||||||||||||
662 | } never executed: end of block | 0 | ||||||||||||
663 | - | |||||||||||||
664 | if (ca_mem !=
| 0-4 | ||||||||||||
665 | ((void *)0)
| 0-4 | ||||||||||||
666 | ) { | - | ||||||||||||
667 | if (ca_len > 0x7fffffff
| 0-4 | ||||||||||||
668 | tls_set_errorx(ctx, "ca too long"); | - | ||||||||||||
669 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
670 | } | - | ||||||||||||
671 | if (SSL_CTX_load_verify_mem(ssl_ctx, ca_mem, ca_len) != 1
| 0-4 | ||||||||||||
672 | tls_set_errorx(ctx, "ssl verify memory setup failure"); | - | ||||||||||||
673 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
674 | } | - | ||||||||||||
675 | } executed 4 times by 1 test: else if (SSL_CTX_load_verify_locations(ssl_ctx, end of block Executed by:
| 0-4 | ||||||||||||
676 | ((void *)0)
| 0 | ||||||||||||
677 | ,
| 0 | ||||||||||||
678 | ctx->config->ca_path) != 1
| 0 | ||||||||||||
679 | tls_set_errorx(ctx, "ssl verify locations failure"); | - | ||||||||||||
680 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
681 | } | - | ||||||||||||
682 | - | |||||||||||||
683 | if (crl_mem !=
| 0-4 | ||||||||||||
684 | ((void *)0)
| 0-4 | ||||||||||||
685 | ) { | - | ||||||||||||
686 | if (crl_len > 0x7fffffff
| 0 | ||||||||||||
687 | tls_set_errorx(ctx, "crl too long"); | - | ||||||||||||
688 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
689 | } | - | ||||||||||||
690 | if ((
| 0 | ||||||||||||
691 | ((void *)0)
| 0 | ||||||||||||
692 | ) { | - | ||||||||||||
693 | tls_set_errorx(ctx, "failed to create buffer"); | - | ||||||||||||
694 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
695 | } | - | ||||||||||||
696 | if ((
| 0 | ||||||||||||
697 | ((void *)0)
| 0 | ||||||||||||
698 | , tls_password_cb,
| 0 | ||||||||||||
699 |
| 0 | ||||||||||||
700 | ((void *)0)
| 0 | ||||||||||||
701 | )) ==
| 0 | ||||||||||||
702 | ((void *)0)
| 0 | ||||||||||||
703 | ) { | - | ||||||||||||
704 | tls_set_errorx(ctx, "failed to parse crl"); | - | ||||||||||||
705 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
706 | } | - | ||||||||||||
707 | store = SSL_CTX_get_cert_store(ssl_ctx); | - | ||||||||||||
708 | for (i = 0; i < sk_num(((_STACK*) (1 ? (xis) : (struct stack_st_X509_INFO*)0)))
| 0 | ||||||||||||
709 | xi = ((X509_INFO *)sk_value(((_STACK*) (1 ? (xis) : (struct stack_st_X509_INFO*)0)), (i))); | - | ||||||||||||
710 | if (xi->crl ==
| 0 | ||||||||||||
711 | ((void *)0)
| 0 | ||||||||||||
712 | ) | - | ||||||||||||
713 | continue; never executed: continue; | 0 | ||||||||||||
714 | if (!X509_STORE_add_crl(store, xi->crl)
| 0 | ||||||||||||
715 | tls_set_error(ctx, "failed to add crl"); | - | ||||||||||||
716 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
717 | } | - | ||||||||||||
718 | xi->crl = | - | ||||||||||||
719 | ((void *)0) | - | ||||||||||||
720 | ; | - | ||||||||||||
721 | } never executed: end of block | 0 | ||||||||||||
722 | X509_VERIFY_PARAM_set_flags(store->param, | - | ||||||||||||
723 | 0x4 | 0x8); | - | ||||||||||||
724 | } never executed: end of block | 0 | ||||||||||||
725 | - | |||||||||||||
726 | done: code before this statement executed 4 times by 1 test: done: Executed by:
| 4 | ||||||||||||
727 | rv = 0; | - | ||||||||||||
728 | - | |||||||||||||
729 | err: code before this statement executed 4 times by 1 test: err: Executed by:
| 4 | ||||||||||||
730 | sk_pop_free(((_STACK*) (1 ? (xis) : (struct stack_st_X509_INFO*)0)), ((void (*)(void *)) ((1 ? (X509_INFO_free) : (void (*)(X509_INFO *))0)))); | - | ||||||||||||
731 | BIO_free(bio); | - | ||||||||||||
732 | free(ca_free); | - | ||||||||||||
733 | - | |||||||||||||
734 | return executed 4 times by 1 test: (rv);return (rv); Executed by:
executed 4 times by 1 test: return (rv); Executed by:
| 4 | ||||||||||||
735 | } | - | ||||||||||||
736 | - | |||||||||||||
737 | void | - | ||||||||||||
738 | tls_free(struct tls *ctx) | - | ||||||||||||
739 | { | - | ||||||||||||
740 | if (ctx ==
| 0-36 | ||||||||||||
741 | ((void *)0)
| 0-36 | ||||||||||||
742 | ) | - | ||||||||||||
743 | return; never executed: return; | 0 | ||||||||||||
744 | - | |||||||||||||
745 | tls_reset(ctx); | - | ||||||||||||
746 | - | |||||||||||||
747 | free(ctx); | - | ||||||||||||
748 | } executed 36 times by 2 tests: end of block Executed by:
| 36 | ||||||||||||
749 | - | |||||||||||||
750 | void | - | ||||||||||||
751 | tls_reset(struct tls *ctx) | - | ||||||||||||
752 | { | - | ||||||||||||
753 | struct tls_sni_ctx *sni, *nsni; | - | ||||||||||||
754 | - | |||||||||||||
755 | tls_config_free(ctx->config); | - | ||||||||||||
756 | ctx->config = | - | ||||||||||||
757 | ((void *)0) | - | ||||||||||||
758 | ; | - | ||||||||||||
759 | - | |||||||||||||
760 | SSL_CTX_free(ctx->ssl_ctx); | - | ||||||||||||
761 | SSL_free(ctx->ssl_conn); | - | ||||||||||||
762 | X509_free(ctx->ssl_peer_cert); | - | ||||||||||||
763 | - | |||||||||||||
764 | ctx->ssl_conn = | - | ||||||||||||
765 | ((void *)0) | - | ||||||||||||
766 | ; | - | ||||||||||||
767 | ctx->ssl_ctx = | - | ||||||||||||
768 | ((void *)0) | - | ||||||||||||
769 | ; | - | ||||||||||||
770 | ctx->ssl_peer_cert = | - | ||||||||||||
771 | ((void *)0) | - | ||||||||||||
772 | ; | - | ||||||||||||
773 | - | |||||||||||||
774 | ctx->ssl_peer_chain = | - | ||||||||||||
775 | ((void *)0) | - | ||||||||||||
776 | ; | - | ||||||||||||
777 | - | |||||||||||||
778 | ctx->socket = -1; | - | ||||||||||||
779 | ctx->state = 0; | - | ||||||||||||
780 | - | |||||||||||||
781 | free(ctx->servername); | - | ||||||||||||
782 | ctx->servername = | - | ||||||||||||
783 | ((void *)0) | - | ||||||||||||
784 | ; | - | ||||||||||||
785 | - | |||||||||||||
786 | free(ctx->error.msg); | - | ||||||||||||
787 | ctx->error.msg = | - | ||||||||||||
788 | ((void *)0) | - | ||||||||||||
789 | ; | - | ||||||||||||
790 | ctx->error.num = -1; | - | ||||||||||||
791 | - | |||||||||||||
792 | tls_conninfo_free(ctx->conninfo); | - | ||||||||||||
793 | ctx->conninfo = | - | ||||||||||||
794 | ((void *)0) | - | ||||||||||||
795 | ; | - | ||||||||||||
796 | - | |||||||||||||
797 | tls_ocsp_free(ctx->ocsp); | - | ||||||||||||
798 | ctx->ocsp = | - | ||||||||||||
799 | ((void *)0) | - | ||||||||||||
800 | ; | - | ||||||||||||
801 | - | |||||||||||||
802 | for (sni = ctx->sni_ctx; sni !=
| 0-78 | ||||||||||||
803 | ((void *)0)
| 0-78 | ||||||||||||
804 | ; sni = nsni) { | - | ||||||||||||
805 | nsni = sni->next; | - | ||||||||||||
806 | tls_sni_ctx_free(sni); | - | ||||||||||||
807 | } never executed: end of block | 0 | ||||||||||||
808 | ctx->sni_ctx = | - | ||||||||||||
809 | ((void *)0) | - | ||||||||||||
810 | ; | - | ||||||||||||
811 | - | |||||||||||||
812 | ctx->read_cb = | - | ||||||||||||
813 | ((void *)0) | - | ||||||||||||
814 | ; | - | ||||||||||||
815 | ctx->write_cb = | - | ||||||||||||
816 | ((void *)0) | - | ||||||||||||
817 | ; | - | ||||||||||||
818 | ctx->cb_arg = | - | ||||||||||||
819 | ((void *)0) | - | ||||||||||||
820 | ; | - | ||||||||||||
821 | } executed 78 times by 2 tests: end of block Executed by:
| 78 | ||||||||||||
822 | - | |||||||||||||
823 | int | - | ||||||||||||
824 | tls_ssl_error(struct tls *ctx, SSL *ssl_conn, int ssl_ret, const char *prefix) | - | ||||||||||||
825 | { | - | ||||||||||||
826 | const char *errstr = "unknown error"; | - | ||||||||||||
827 | unsigned long err; | - | ||||||||||||
828 | int ssl_err; | - | ||||||||||||
829 | - | |||||||||||||
830 | ssl_err = SSL_get_error(ssl_conn, ssl_ret); | - | ||||||||||||
831 | switch (ssl_err) { | - | ||||||||||||
832 | case never executed: 0:case 0: never executed: case 0: | 0 | ||||||||||||
833 | case never executed: 6:case 6: never executed: case 6: | 0 | ||||||||||||
834 | return never executed: (0);return (0); never executed: return (0); | 0 | ||||||||||||
835 | - | |||||||||||||
836 | case executed 16 times by 1 test: 2:case 2: Executed by:
executed 16 times by 1 test: case 2: Executed by:
| 16 | ||||||||||||
837 | return executed 16 times by 1 test: (-2);return (-2); Executed by:
executed 16 times by 1 test: return (-2); Executed by:
| 16 | ||||||||||||
838 | - | |||||||||||||
839 | case executed 4 times by 1 test: 3:case 3: Executed by:
executed 4 times by 1 test: case 3: Executed by:
| 4 | ||||||||||||
840 | return executed 4 times by 1 test: (-3);return (-3); Executed by:
executed 4 times by 1 test: return (-3); Executed by:
| 4 | ||||||||||||
841 | - | |||||||||||||
842 | case never executed: 5:case 5: never executed: case 5: | 0 | ||||||||||||
843 | if ((
| 0 | ||||||||||||
844 | errstr = ERR_error_string(err, | - | ||||||||||||
845 | ((void *)0) | - | ||||||||||||
846 | ); | - | ||||||||||||
847 | } never executed: else if (ssl_ret == 0end of block
| 0 | ||||||||||||
848 | if ((
| 0 | ||||||||||||
849 | ctx->state |= (1 << 0); | - | ||||||||||||
850 | return never executed: (0);return (0); never executed: return (0); | 0 | ||||||||||||
851 | } | - | ||||||||||||
852 | errstr = "unexpected EOF"; | - | ||||||||||||
853 | } never executed: else if (ssl_ret == -1end of block
| 0 | ||||||||||||
854 | errstr = strerror( | - | ||||||||||||
855 | (*__errno_location ()) | - | ||||||||||||
856 | ); | - | ||||||||||||
857 | } never executed: end of block | 0 | ||||||||||||
858 | tls_set_ssl_errorx(ctx, "%s failed: %s", prefix, errstr); | - | ||||||||||||
859 | return never executed: (-1);return (-1); never executed: return (-1); | 0 | ||||||||||||
860 | - | |||||||||||||
861 | case never executed: 1:case 1: never executed: case 1: | 0 | ||||||||||||
862 | if ((
| 0 | ||||||||||||
863 | errstr = ERR_error_string(err, | - | ||||||||||||
864 | ((void *)0) | - | ||||||||||||
865 | ); | - | ||||||||||||
866 | } never executed: end of block | 0 | ||||||||||||
867 | tls_set_ssl_errorx(ctx, "%s failed: %s", prefix, errstr); | - | ||||||||||||
868 | return never executed: (-1);return (-1); never executed: return (-1); | 0 | ||||||||||||
869 | - | |||||||||||||
870 | case never executed: 7:case 7: never executed: case 7: | 0 | ||||||||||||
871 | case never executed: 8:case 8: never executed: case 8: | 0 | ||||||||||||
872 | case never executed: 4:case 4: never executed: case 4: | 0 | ||||||||||||
873 | default never executed: :default: never executed: default: | 0 | ||||||||||||
874 | tls_set_ssl_errorx(ctx, "%s failed (%i)", prefix, ssl_err); | - | ||||||||||||
875 | return never executed: (-1);return (-1); never executed: return (-1); | 0 | ||||||||||||
876 | } | - | ||||||||||||
877 | } | - | ||||||||||||
878 | - | |||||||||||||
879 | int | - | ||||||||||||
880 | tls_handshake(struct tls *ctx) | - | ||||||||||||
881 | { | - | ||||||||||||
882 | int rv = -1; | - | ||||||||||||
883 | - | |||||||||||||
884 | tls_error_clear(&ctx->error); | - | ||||||||||||
885 | - | |||||||||||||
886 | if ((
| 0-31 | ||||||||||||
887 | tls_set_errorx(ctx, "invalid operation for context"); | - | ||||||||||||
888 | goto never executed: out;goto out; never executed: goto out; | 0 | ||||||||||||
889 | } | - | ||||||||||||
890 | - | |||||||||||||
891 | if ((
| 2-29 | ||||||||||||
892 | tls_set_errorx(ctx, "handshake already completed"); | - | ||||||||||||
893 | goto executed 2 times by 1 test: out;goto out; Executed by:
executed 2 times by 1 test: goto out; Executed by:
| 2 | ||||||||||||
894 | } | - | ||||||||||||
895 | - | |||||||||||||
896 | if ((
| 12-17 | ||||||||||||
897 | rv = tls_handshake_client(ctx); executed 17 times by 1 test: rv = tls_handshake_client(ctx); Executed by:
| 17 | ||||||||||||
898 | else if ((
| 0-12 | ||||||||||||
899 | rv = tls_handshake_server(ctx); executed 12 times by 1 test: rv = tls_handshake_server(ctx); Executed by:
| 12 | ||||||||||||
900 | - | |||||||||||||
901 | if (rv == 0
| 8-21 | ||||||||||||
902 | ctx->ssl_peer_cert = SSL_get_peer_certificate(ctx->ssl_conn); | - | ||||||||||||
903 | ctx->ssl_peer_chain = SSL_get_peer_cert_chain(ctx->ssl_conn); | - | ||||||||||||
904 | if (tls_conninfo_populate(ctx) == -1
| 0-8 | ||||||||||||
905 | rv = -1; never executed: rv = -1; | 0 | ||||||||||||
906 | if (ctx->ocsp ==
| 0-8 | ||||||||||||
907 | ((void *)0)
| 0-8 | ||||||||||||
908 | ) | - | ||||||||||||
909 | ctx->ocsp = tls_ocsp_setup_from_peer(ctx); executed 8 times by 1 test: ctx->ocsp = tls_ocsp_setup_from_peer(ctx); Executed by:
| 8 | ||||||||||||
910 | } executed 8 times by 1 test: end of block Executed by:
| 8 | ||||||||||||
911 | out: code before this statement executed 29 times by 1 test: out: Executed by:
| 29 | ||||||||||||
912 | - | |||||||||||||
913 | - | |||||||||||||
914 | (*__errno_location ()) | - | ||||||||||||
915 | = 0; | - | ||||||||||||
916 | return executed 31 times by 1 test: (rv);return (rv); Executed by:
executed 31 times by 1 test: return (rv); Executed by:
| 31 | ||||||||||||
917 | } | - | ||||||||||||
918 | - | |||||||||||||
919 | ssize_t | - | ||||||||||||
920 | tls_read(struct tls *ctx, void *buf, size_t buflen) | - | ||||||||||||
921 | { | - | ||||||||||||
922 | ssize_t rv = -1; | - | ||||||||||||
923 | int ssl_ret; | - | ||||||||||||
924 | - | |||||||||||||
925 | tls_error_clear(&ctx->error); | - | ||||||||||||
926 | - | |||||||||||||
927 | if ((
| 0 | ||||||||||||
928 | if ((
| 0 | ||||||||||||
929 | goto never executed: out;goto out; never executed: goto out; | 0 | ||||||||||||
930 | } never executed: end of block | 0 | ||||||||||||
931 | - | |||||||||||||
932 | if (buflen > 0x7fffffff
| 0 | ||||||||||||
933 | tls_set_errorx(ctx, "buflen too long"); | - | ||||||||||||
934 | goto never executed: out;goto out; never executed: goto out; | 0 | ||||||||||||
935 | } | - | ||||||||||||
936 | - | |||||||||||||
937 | ERR_clear_error(); | - | ||||||||||||
938 | if ((
| 0 | ||||||||||||
939 | rv = (ssize_t)ssl_ret; | - | ||||||||||||
940 | goto never executed: out;goto out; never executed: goto out; | 0 | ||||||||||||
941 | } | - | ||||||||||||
942 | rv = (ssize_t)tls_ssl_error(ctx, ctx->ssl_conn, ssl_ret, "read"); | - | ||||||||||||
943 | - | |||||||||||||
944 | out: code before this statement never executed: out: | 0 | ||||||||||||
945 | - | |||||||||||||
946 | - | |||||||||||||
947 | (*__errno_location ()) | - | ||||||||||||
948 | = 0; | - | ||||||||||||
949 | return never executed: (rv);return (rv); never executed: return (rv); | 0 | ||||||||||||
950 | } | - | ||||||||||||
951 | - | |||||||||||||
952 | ssize_t | - | ||||||||||||
953 | tls_write(struct tls *ctx, const void *buf, size_t buflen) | - | ||||||||||||
954 | { | - | ||||||||||||
955 | ssize_t rv = -1; | - | ||||||||||||
956 | int ssl_ret; | - | ||||||||||||
957 | - | |||||||||||||
958 | tls_error_clear(&ctx->error); | - | ||||||||||||
959 | - | |||||||||||||
960 | if ((
| 0 | ||||||||||||
961 | if ((
| 0 | ||||||||||||
962 | goto never executed: out;goto out; never executed: goto out; | 0 | ||||||||||||
963 | } never executed: end of block | 0 | ||||||||||||
964 | - | |||||||||||||
965 | if (buflen > 0x7fffffff
| 0 | ||||||||||||
966 | tls_set_errorx(ctx, "buflen too long"); | - | ||||||||||||
967 | goto never executed: out;goto out; never executed: goto out; | 0 | ||||||||||||
968 | } | - | ||||||||||||
969 | - | |||||||||||||
970 | ERR_clear_error(); | - | ||||||||||||
971 | if ((
| 0 | ||||||||||||
972 | rv = (ssize_t)ssl_ret; | - | ||||||||||||
973 | goto never executed: out;goto out; never executed: goto out; | 0 | ||||||||||||
974 | } | - | ||||||||||||
975 | rv = (ssize_t)tls_ssl_error(ctx, ctx->ssl_conn, ssl_ret, "write"); | - | ||||||||||||
976 | - | |||||||||||||
977 | out: code before this statement never executed: out: | 0 | ||||||||||||
978 | - | |||||||||||||
979 | - | |||||||||||||
980 | (*__errno_location ()) | - | ||||||||||||
981 | = 0; | - | ||||||||||||
982 | return never executed: (rv);return (rv); never executed: return (rv); | 0 | ||||||||||||
983 | } | - | ||||||||||||
984 | - | |||||||||||||
985 | int | - | ||||||||||||
986 | tls_close(struct tls *ctx) | - | ||||||||||||
987 | { | - | ||||||||||||
988 | int ssl_ret; | - | ||||||||||||
989 | int rv = 0; | - | ||||||||||||
990 | - | |||||||||||||
991 | tls_error_clear(&ctx->error); | - | ||||||||||||
992 | - | |||||||||||||
993 | if ((
| 0-8 | ||||||||||||
994 | tls_set_errorx(ctx, "invalid operation for context"); | - | ||||||||||||
995 | rv = -1; | - | ||||||||||||
996 | goto never executed: out;goto out; never executed: goto out; | 0 | ||||||||||||
997 | } | - | ||||||||||||
998 | - | |||||||||||||
999 | if (ctx->state & (1 << 3)
| 0-8 | ||||||||||||
1000 | ERR_clear_error(); | - | ||||||||||||
1001 | ssl_ret = SSL_shutdown(ctx->ssl_conn); | - | ||||||||||||
1002 | if (ssl_ret < 0
| 0-8 | ||||||||||||
1003 | rv = tls_ssl_error(ctx, ctx->ssl_conn, ssl_ret, | - | ||||||||||||
1004 | "shutdown"); | - | ||||||||||||
1005 | if (rv == -2
| 0 | ||||||||||||
1006 | goto never executed: out;goto out; never executed: goto out; | 0 | ||||||||||||
1007 | } never executed: end of block | 0 | ||||||||||||
1008 | ctx->state &= ~(1 << 3); | - | ||||||||||||
1009 | } executed 8 times by 1 test: end of block Executed by:
| 8 | ||||||||||||
1010 | - | |||||||||||||
1011 | if (ctx->socket != -1
| 0-8 | ||||||||||||
1012 | if (shutdown(ctx->socket,
| 0 | ||||||||||||
1013 | SHUT_RDWR
| 0 | ||||||||||||
1014 | ) != 0
| 0 | ||||||||||||
1015 | if (rv == 0
| 0 | ||||||||||||
1016 | - | |||||||||||||
1017 | (*
| 0 | ||||||||||||
1018 | !=
| 0 | ||||||||||||
1019 | 107
| 0 | ||||||||||||
1020 | && | - | ||||||||||||
1021 | (*
| 0 | ||||||||||||
1022 | !=
| 0 | ||||||||||||
1023 | 104
| 0 | ||||||||||||
1024 | ) { | - | ||||||||||||
1025 | tls_set_error(ctx, "shutdown"); | - | ||||||||||||
1026 | rv = -1; | - | ||||||||||||
1027 | } never executed: end of block | 0 | ||||||||||||
1028 | } never executed: end of block | 0 | ||||||||||||
1029 | if (close(ctx->socket) != 0
| 0 | ||||||||||||
1030 | if (rv == 0
| 0 | ||||||||||||
1031 | tls_set_error(ctx, "close"); | - | ||||||||||||
1032 | rv = -1; | - | ||||||||||||
1033 | } never executed: end of block | 0 | ||||||||||||
1034 | } never executed: end of block | 0 | ||||||||||||
1035 | ctx->socket = -1; | - | ||||||||||||
1036 | } never executed: end of block | 0 | ||||||||||||
1037 | - | |||||||||||||
1038 | if ((
| 0-8 | ||||||||||||
1039 | tls_set_errorx(ctx, "EOF without close notify"); | - | ||||||||||||
1040 | rv = -1; | - | ||||||||||||
1041 | } never executed: end of block | 0 | ||||||||||||
1042 | - | |||||||||||||
1043 | out: code before this statement executed 8 times by 1 test: out: Executed by:
| 8 | ||||||||||||
1044 | - | |||||||||||||
1045 | - | |||||||||||||
1046 | (*__errno_location ()) | - | ||||||||||||
1047 | = 0; | - | ||||||||||||
1048 | return executed 8 times by 1 test: (rv);return (rv); Executed by:
executed 8 times by 1 test: return (rv); Executed by:
| 8 | ||||||||||||
1049 | } | - | ||||||||||||
Switch to Source code | Preprocessed file |