Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/ssl/bio_ssl.c |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /* | - | ||||||||||||
2 | * Copyright 1995-2016 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 <stdio.h> | - | ||||||||||||
11 | #include <stdlib.h> | - | ||||||||||||
12 | #include <string.h> | - | ||||||||||||
13 | #include <errno.h> | - | ||||||||||||
14 | #include <openssl/crypto.h> | - | ||||||||||||
15 | #include "internal/bio.h" | - | ||||||||||||
16 | #include <openssl/err.h> | - | ||||||||||||
17 | #include "ssl_locl.h" | - | ||||||||||||
18 | - | |||||||||||||
19 | static int ssl_write(BIO *h, const char *buf, size_t size, size_t *written); | - | ||||||||||||
20 | static int ssl_read(BIO *b, char *buf, size_t size, size_t *readbytes); | - | ||||||||||||
21 | static int ssl_puts(BIO *h, const char *str); | - | ||||||||||||
22 | static long ssl_ctrl(BIO *h, int cmd, long arg1, void *arg2); | - | ||||||||||||
23 | static int ssl_new(BIO *h); | - | ||||||||||||
24 | static int ssl_free(BIO *data); | - | ||||||||||||
25 | static long ssl_callback_ctrl(BIO *h, int cmd, BIO_info_cb *fp); | - | ||||||||||||
26 | typedef struct bio_ssl_st { | - | ||||||||||||
27 | SSL *ssl; /* The ssl handle :-) */ | - | ||||||||||||
28 | /* re-negotiate every time the total number of bytes is this size */ | - | ||||||||||||
29 | int num_renegotiates; | - | ||||||||||||
30 | unsigned long renegotiate_count; | - | ||||||||||||
31 | size_t byte_count; | - | ||||||||||||
32 | unsigned long renegotiate_timeout; | - | ||||||||||||
33 | unsigned long last_time; | - | ||||||||||||
34 | } BIO_SSL; | - | ||||||||||||
35 | - | |||||||||||||
36 | static const BIO_METHOD methods_sslp = { | - | ||||||||||||
37 | BIO_TYPE_SSL, | - | ||||||||||||
38 | "ssl", | - | ||||||||||||
39 | ssl_write, | - | ||||||||||||
40 | NULL, /* ssl_write_old, */ | - | ||||||||||||
41 | ssl_read, | - | ||||||||||||
42 | NULL, /* ssl_read_old, */ | - | ||||||||||||
43 | ssl_puts, | - | ||||||||||||
44 | NULL, /* ssl_gets, */ | - | ||||||||||||
45 | ssl_ctrl, | - | ||||||||||||
46 | ssl_new, | - | ||||||||||||
47 | ssl_free, | - | ||||||||||||
48 | ssl_callback_ctrl, | - | ||||||||||||
49 | }; | - | ||||||||||||
50 | - | |||||||||||||
51 | const BIO_METHOD *BIO_f_ssl(void) | - | ||||||||||||
52 | { | - | ||||||||||||
53 | return &methods_sslp; executed 487 times by 1 test: return &methods_sslp; Executed by:
| 487 | ||||||||||||
54 | } | - | ||||||||||||
55 | - | |||||||||||||
56 | static int ssl_new(BIO *bi) | - | ||||||||||||
57 | { | - | ||||||||||||
58 | BIO_SSL *bs = OPENSSL_zalloc(sizeof(*bs)); | - | ||||||||||||
59 | - | |||||||||||||
60 | if (bs == NULL) {
| 0-487 | ||||||||||||
61 | BIOerr(BIO_F_SSL_NEW, ERR_R_MALLOC_FAILURE); | - | ||||||||||||
62 | return 0; never executed: return 0; | 0 | ||||||||||||
63 | } | - | ||||||||||||
64 | BIO_set_init(bi, 0); | - | ||||||||||||
65 | BIO_set_data(bi, bs); | - | ||||||||||||
66 | /* Clear all flags */ | - | ||||||||||||
67 | BIO_clear_flags(bi, ~0); | - | ||||||||||||
68 | - | |||||||||||||
69 | return 1; executed 487 times by 1 test: return 1; Executed by:
| 487 | ||||||||||||
70 | } | - | ||||||||||||
71 | - | |||||||||||||
72 | static int ssl_free(BIO *a) | - | ||||||||||||
73 | { | - | ||||||||||||
74 | BIO_SSL *bs; | - | ||||||||||||
75 | - | |||||||||||||
76 | if (a == NULL)
| 0-487 | ||||||||||||
77 | return 0; never executed: return 0; | 0 | ||||||||||||
78 | bs = BIO_get_data(a); | - | ||||||||||||
79 | if (bs->ssl != NULL)
| 0-487 | ||||||||||||
80 | SSL_shutdown(bs->ssl); executed 487 times by 1 test: SSL_shutdown(bs->ssl); Executed by:
| 487 | ||||||||||||
81 | if (BIO_get_shutdown(a)) {
| 195-292 | ||||||||||||
82 | if (BIO_get_init(a))
| 0-195 | ||||||||||||
83 | SSL_free(bs->ssl); executed 195 times by 1 test: SSL_free(bs->ssl); Executed by:
| 195 | ||||||||||||
84 | /* Clear all flags */ | - | ||||||||||||
85 | BIO_clear_flags(a, ~0); | - | ||||||||||||
86 | BIO_set_init(a, 0); | - | ||||||||||||
87 | } executed 195 times by 1 test: end of block Executed by:
| 195 | ||||||||||||
88 | OPENSSL_free(bs); | - | ||||||||||||
89 | return 1; executed 487 times by 1 test: return 1; Executed by:
| 487 | ||||||||||||
90 | } | - | ||||||||||||
91 | - | |||||||||||||
92 | static int ssl_read(BIO *b, char *buf, size_t size, size_t *readbytes) | - | ||||||||||||
93 | { | - | ||||||||||||
94 | int ret = 1; | - | ||||||||||||
95 | BIO_SSL *sb; | - | ||||||||||||
96 | SSL *ssl; | - | ||||||||||||
97 | int retry_reason = 0; | - | ||||||||||||
98 | int r = 0; | - | ||||||||||||
99 | - | |||||||||||||
100 | if (buf == NULL)
| 0-10191 | ||||||||||||
101 | return 0; never executed: return 0; | 0 | ||||||||||||
102 | sb = BIO_get_data(b); | - | ||||||||||||
103 | ssl = sb->ssl; | - | ||||||||||||
104 | - | |||||||||||||
105 | BIO_clear_retry_flags(b); | - | ||||||||||||
106 | - | |||||||||||||
107 | ret = ssl_read_internal(ssl, buf, size, readbytes); | - | ||||||||||||
108 | - | |||||||||||||
109 | switch (SSL_get_error(ssl, ret)) { | - | ||||||||||||
110 | case SSL_ERROR_NONE: executed 401 times by 1 test: case 0: Executed by:
| 401 | ||||||||||||
111 | if (sb->renegotiate_count > 0) {
| 0-401 | ||||||||||||
112 | sb->byte_count += *readbytes; | - | ||||||||||||
113 | if (sb->byte_count > sb->renegotiate_count) {
| 0 | ||||||||||||
114 | sb->byte_count = 0; | - | ||||||||||||
115 | sb->num_renegotiates++; | - | ||||||||||||
116 | SSL_renegotiate(ssl); | - | ||||||||||||
117 | r = 1; | - | ||||||||||||
118 | } never executed: end of block | 0 | ||||||||||||
119 | } never executed: end of block | 0 | ||||||||||||
120 | if ((sb->renegotiate_timeout > 0) && (!r)) {
| 0-401 | ||||||||||||
121 | unsigned long tm; | - | ||||||||||||
122 | - | |||||||||||||
123 | tm = (unsigned long)time(NULL); | - | ||||||||||||
124 | if (tm > sb->last_time + sb->renegotiate_timeout) {
| 0 | ||||||||||||
125 | sb->last_time = tm; | - | ||||||||||||
126 | sb->num_renegotiates++; | - | ||||||||||||
127 | SSL_renegotiate(ssl); | - | ||||||||||||
128 | } never executed: end of block | 0 | ||||||||||||
129 | } never executed: end of block | 0 | ||||||||||||
130 | - | |||||||||||||
131 | break; executed 401 times by 1 test: break; Executed by:
| 401 | ||||||||||||
132 | case SSL_ERROR_WANT_READ: executed 9252 times by 1 test: case 2: Executed by:
| 9252 | ||||||||||||
133 | BIO_set_retry_read(b); | - | ||||||||||||
134 | break; executed 9252 times by 1 test: break; Executed by:
| 9252 | ||||||||||||
135 | case SSL_ERROR_WANT_WRITE: executed 303 times by 1 test: case 3: Executed by:
| 303 | ||||||||||||
136 | BIO_set_retry_write(b); | - | ||||||||||||
137 | break; executed 303 times by 1 test: break; Executed by:
| 303 | ||||||||||||
138 | case SSL_ERROR_WANT_X509_LOOKUP: never executed: case 4: | 0 | ||||||||||||
139 | BIO_set_retry_special(b); | - | ||||||||||||
140 | retry_reason = BIO_RR_SSL_X509_LOOKUP; | - | ||||||||||||
141 | break; never executed: break; | 0 | ||||||||||||
142 | case SSL_ERROR_WANT_ACCEPT: never executed: case 8: | 0 | ||||||||||||
143 | BIO_set_retry_special(b); | - | ||||||||||||
144 | retry_reason = BIO_RR_ACCEPT; | - | ||||||||||||
145 | break; never executed: break; | 0 | ||||||||||||
146 | case SSL_ERROR_WANT_CONNECT: never executed: case 7: | 0 | ||||||||||||
147 | BIO_set_retry_special(b); | - | ||||||||||||
148 | retry_reason = BIO_RR_CONNECT; | - | ||||||||||||
149 | break; never executed: break; | 0 | ||||||||||||
150 | case SSL_ERROR_SYSCALL: executed 6 times by 1 test: case 5: Executed by:
| 6 | ||||||||||||
151 | case SSL_ERROR_SSL: executed 9 times by 1 test: case 1: Executed by:
| 9 | ||||||||||||
152 | case SSL_ERROR_ZERO_RETURN: executed 220 times by 1 test: case 6: Executed by:
| 220 | ||||||||||||
153 | default: never executed: default: | 0 | ||||||||||||
154 | break; executed 235 times by 1 test: break; Executed by:
| 235 | ||||||||||||
155 | } | - | ||||||||||||
156 | - | |||||||||||||
157 | BIO_set_retry_reason(b, retry_reason); | - | ||||||||||||
158 | - | |||||||||||||
159 | return ret; executed 10191 times by 1 test: return ret; Executed by:
| 10191 | ||||||||||||
160 | } | - | ||||||||||||
161 | - | |||||||||||||
162 | static int ssl_write(BIO *b, const char *buf, size_t size, size_t *written) | - | ||||||||||||
163 | { | - | ||||||||||||
164 | int ret, r = 0; | - | ||||||||||||
165 | int retry_reason = 0; | - | ||||||||||||
166 | SSL *ssl; | - | ||||||||||||
167 | BIO_SSL *bs; | - | ||||||||||||
168 | - | |||||||||||||
169 | if (buf == NULL)
| 0-2925 | ||||||||||||
170 | return 0; never executed: return 0; | 0 | ||||||||||||
171 | bs = BIO_get_data(b); | - | ||||||||||||
172 | ssl = bs->ssl; | - | ||||||||||||
173 | - | |||||||||||||
174 | BIO_clear_retry_flags(b); | - | ||||||||||||
175 | - | |||||||||||||
176 | ret = ssl_write_internal(ssl, buf, size, written); | - | ||||||||||||
177 | - | |||||||||||||
178 | switch (SSL_get_error(ssl, ret)) { | - | ||||||||||||
179 | case SSL_ERROR_NONE: executed 401 times by 1 test: case 0: Executed by:
| 401 | ||||||||||||
180 | if (bs->renegotiate_count > 0) {
| 0-401 | ||||||||||||
181 | bs->byte_count += *written; | - | ||||||||||||
182 | if (bs->byte_count > bs->renegotiate_count) {
| 0 | ||||||||||||
183 | bs->byte_count = 0; | - | ||||||||||||
184 | bs->num_renegotiates++; | - | ||||||||||||
185 | SSL_renegotiate(ssl); | - | ||||||||||||
186 | r = 1; | - | ||||||||||||
187 | } never executed: end of block | 0 | ||||||||||||
188 | } never executed: end of block | 0 | ||||||||||||
189 | if ((bs->renegotiate_timeout > 0) && (!r)) {
| 0-401 | ||||||||||||
190 | unsigned long tm; | - | ||||||||||||
191 | - | |||||||||||||
192 | tm = (unsigned long)time(NULL); | - | ||||||||||||
193 | if (tm > bs->last_time + bs->renegotiate_timeout) {
| 0 | ||||||||||||
194 | bs->last_time = tm; | - | ||||||||||||
195 | bs->num_renegotiates++; | - | ||||||||||||
196 | SSL_renegotiate(ssl); | - | ||||||||||||
197 | } never executed: end of block | 0 | ||||||||||||
198 | } never executed: end of block | 0 | ||||||||||||
199 | break; executed 401 times by 1 test: break; Executed by:
| 401 | ||||||||||||
200 | case SSL_ERROR_WANT_WRITE: executed 744 times by 1 test: case 3: Executed by:
| 744 | ||||||||||||
201 | BIO_set_retry_write(b); | - | ||||||||||||
202 | break; executed 744 times by 1 test: break; Executed by:
| 744 | ||||||||||||
203 | case SSL_ERROR_WANT_READ: executed 1780 times by 1 test: case 2: Executed by:
| 1780 | ||||||||||||
204 | BIO_set_retry_read(b); | - | ||||||||||||
205 | break; executed 1780 times by 1 test: break; Executed by:
| 1780 | ||||||||||||
206 | case SSL_ERROR_WANT_X509_LOOKUP: never executed: case 4: | 0 | ||||||||||||
207 | BIO_set_retry_special(b); | - | ||||||||||||
208 | retry_reason = BIO_RR_SSL_X509_LOOKUP; | - | ||||||||||||
209 | break; never executed: break; | 0 | ||||||||||||
210 | case SSL_ERROR_WANT_CONNECT: never executed: case 7: | 0 | ||||||||||||
211 | BIO_set_retry_special(b); | - | ||||||||||||
212 | retry_reason = BIO_RR_CONNECT; | - | ||||||||||||
213 | case SSL_ERROR_SYSCALL: code before this statement never executed: case 5: never executed: case 5: | 0 | ||||||||||||
214 | case SSL_ERROR_SSL: never executed: case 1: | 0 | ||||||||||||
215 | default: never executed: default: | 0 | ||||||||||||
216 | break; never executed: break; | 0 | ||||||||||||
217 | } | - | ||||||||||||
218 | - | |||||||||||||
219 | BIO_set_retry_reason(b, retry_reason); | - | ||||||||||||
220 | - | |||||||||||||
221 | return ret; executed 2925 times by 1 test: return ret; Executed by:
| 2925 | ||||||||||||
222 | } | - | ||||||||||||
223 | - | |||||||||||||
224 | static long ssl_ctrl(BIO *b, int cmd, long num, void *ptr) | - | ||||||||||||
225 | { | - | ||||||||||||
226 | SSL **sslp, *ssl; | - | ||||||||||||
227 | BIO_SSL *bs, *dbs; | - | ||||||||||||
228 | BIO *dbio, *bio; | - | ||||||||||||
229 | long ret = 1; | - | ||||||||||||
230 | BIO *next; | - | ||||||||||||
231 | - | |||||||||||||
232 | bs = BIO_get_data(b); | - | ||||||||||||
233 | next = BIO_next(b); | - | ||||||||||||
234 | ssl = bs->ssl; | - | ||||||||||||
235 | if ((ssl == NULL) && (cmd != BIO_C_SET_SSL))
| 0-2064 | ||||||||||||
236 | return 0; never executed: return 0; | 0 | ||||||||||||
237 | switch (cmd) { | - | ||||||||||||
238 | case BIO_CTRL_RESET: never executed: case 1: | 0 | ||||||||||||
239 | SSL_shutdown(ssl); | - | ||||||||||||
240 | - | |||||||||||||
241 | if (ssl->handshake_func == ssl->method->ssl_connect)
| 0 | ||||||||||||
242 | SSL_set_connect_state(ssl); never executed: SSL_set_connect_state(ssl); | 0 | ||||||||||||
243 | else if (ssl->handshake_func == ssl->method->ssl_accept)
| 0 | ||||||||||||
244 | SSL_set_accept_state(ssl); never executed: SSL_set_accept_state(ssl); | 0 | ||||||||||||
245 | - | |||||||||||||
246 | if (!SSL_clear(ssl)) {
| 0 | ||||||||||||
247 | ret = 0; | - | ||||||||||||
248 | break; never executed: break; | 0 | ||||||||||||
249 | } | - | ||||||||||||
250 | - | |||||||||||||
251 | if (next != NULL)
| 0 | ||||||||||||
252 | ret = BIO_ctrl(next, cmd, num, ptr); never executed: ret = BIO_ctrl(next, cmd, num, ptr); | 0 | ||||||||||||
253 | else if (ssl->rbio != NULL)
| 0 | ||||||||||||
254 | ret = BIO_ctrl(ssl->rbio, cmd, num, ptr); never executed: ret = BIO_ctrl(ssl->rbio, cmd, num, ptr); | 0 | ||||||||||||
255 | else | - | ||||||||||||
256 | ret = 1; never executed: ret = 1; | 0 | ||||||||||||
257 | break; never executed: break; | 0 | ||||||||||||
258 | case BIO_CTRL_INFO: never executed: case 3: | 0 | ||||||||||||
259 | ret = 0; | - | ||||||||||||
260 | break; never executed: break; | 0 | ||||||||||||
261 | case BIO_C_SSL_MODE: never executed: case 119: | 0 | ||||||||||||
262 | if (num) /* client mode */
| 0 | ||||||||||||
263 | SSL_set_connect_state(ssl); never executed: SSL_set_connect_state(ssl); | 0 | ||||||||||||
264 | else | - | ||||||||||||
265 | SSL_set_accept_state(ssl); never executed: SSL_set_accept_state(ssl); | 0 | ||||||||||||
266 | break; never executed: break; | 0 | ||||||||||||
267 | case BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT: never executed: case 127: | 0 | ||||||||||||
268 | ret = bs->renegotiate_timeout; | - | ||||||||||||
269 | if (num < 60)
| 0 | ||||||||||||
270 | num = 5; never executed: num = 5; | 0 | ||||||||||||
271 | bs->renegotiate_timeout = (unsigned long)num; | - | ||||||||||||
272 | bs->last_time = (unsigned long)time(NULL); | - | ||||||||||||
273 | break; never executed: break; | 0 | ||||||||||||
274 | case BIO_C_SET_SSL_RENEGOTIATE_BYTES: never executed: case 125: | 0 | ||||||||||||
275 | ret = bs->renegotiate_count; | - | ||||||||||||
276 | if ((long)num >= 512)
| 0 | ||||||||||||
277 | bs->renegotiate_count = (unsigned long)num; never executed: bs->renegotiate_count = (unsigned long)num; | 0 | ||||||||||||
278 | break; never executed: break; | 0 | ||||||||||||
279 | case BIO_C_GET_SSL_NUM_RENEGOTIATES: never executed: case 126: | 0 | ||||||||||||
280 | ret = bs->num_renegotiates; | - | ||||||||||||
281 | break; never executed: break; | 0 | ||||||||||||
282 | case BIO_C_SET_SSL: executed 487 times by 1 test: case 109: Executed by:
| 487 | ||||||||||||
283 | if (ssl != NULL) {
| 0-487 | ||||||||||||
284 | ssl_free(b); | - | ||||||||||||
285 | if (!ssl_new(b))
| 0 | ||||||||||||
286 | return 0; never executed: return 0; | 0 | ||||||||||||
287 | } never executed: end of block | 0 | ||||||||||||
288 | BIO_set_shutdown(b, num); | - | ||||||||||||
289 | ssl = (SSL *)ptr; | - | ||||||||||||
290 | bs->ssl = ssl; | - | ||||||||||||
291 | bio = SSL_get_rbio(ssl); | - | ||||||||||||
292 | if (bio != NULL) {
| 4-483 | ||||||||||||
293 | if (next != NULL)
| 0-483 | ||||||||||||
294 | BIO_push(bio, next); never executed: BIO_push(bio, next); | 0 | ||||||||||||
295 | BIO_set_next(b, bio); | - | ||||||||||||
296 | BIO_up_ref(bio); | - | ||||||||||||
297 | } executed 483 times by 1 test: end of block Executed by:
| 483 | ||||||||||||
298 | BIO_set_init(b, 1); | - | ||||||||||||
299 | break; executed 487 times by 1 test: break; Executed by:
| 487 | ||||||||||||
300 | case BIO_C_GET_SSL: never executed: case 110: | 0 | ||||||||||||
301 | if (ptr != NULL) {
| 0 | ||||||||||||
302 | sslp = (SSL **)ptr; | - | ||||||||||||
303 | *sslp = ssl; | - | ||||||||||||
304 | } else never executed: end of block | 0 | ||||||||||||
305 | ret = 0; never executed: ret = 0; | 0 | ||||||||||||
306 | break; never executed: break; | 0 | ||||||||||||
307 | case BIO_CTRL_GET_CLOSE: never executed: case 8: | 0 | ||||||||||||
308 | ret = BIO_get_shutdown(b); | - | ||||||||||||
309 | break; never executed: break; | 0 | ||||||||||||
310 | case BIO_CTRL_SET_CLOSE: never executed: case 9: | 0 | ||||||||||||
311 | BIO_set_shutdown(b, (int)num); | - | ||||||||||||
312 | break; never executed: break; | 0 | ||||||||||||
313 | case BIO_CTRL_WPENDING: never executed: case 13: | 0 | ||||||||||||
314 | ret = BIO_ctrl(ssl->wbio, cmd, num, ptr); | - | ||||||||||||
315 | break; never executed: break; | 0 | ||||||||||||
316 | case BIO_CTRL_PENDING: executed 1564 times by 1 test: case 10: Executed by:
| 1564 | ||||||||||||
317 | ret = SSL_pending(ssl); | - | ||||||||||||
318 | if (ret == 0)
| 0-1564 | ||||||||||||
319 | ret = BIO_pending(ssl->rbio); executed 1564 times by 1 test: ret = (int)BIO_ctrl(ssl->rbio,10,0, ((void *)0) ); Executed by:
| 1564 | ||||||||||||
320 | break; executed 1564 times by 1 test: break; Executed by:
| 1564 | ||||||||||||
321 | case BIO_CTRL_FLUSH: executed 113 times by 1 test: case 11: Executed by:
| 113 | ||||||||||||
322 | BIO_clear_retry_flags(b); | - | ||||||||||||
323 | ret = BIO_ctrl(ssl->wbio, cmd, num, ptr); | - | ||||||||||||
324 | BIO_copy_next_retry(b); | - | ||||||||||||
325 | break; executed 113 times by 1 test: break; Executed by:
| 113 | ||||||||||||
326 | case BIO_CTRL_PUSH: executed 195 times by 1 test: case 6: Executed by:
| 195 | ||||||||||||
327 | if ((next != NULL) && (next != ssl->rbio)) {
| 0-195 | ||||||||||||
328 | /* | - | ||||||||||||
329 | * We are going to pass ownership of next to the SSL object...but | - | ||||||||||||
330 | * we don't own a reference to pass yet - so up ref | - | ||||||||||||
331 | */ | - | ||||||||||||
332 | BIO_up_ref(next); | - | ||||||||||||
333 | SSL_set_bio(ssl, next, next); | - | ||||||||||||
334 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||
335 | break; executed 195 times by 1 test: break; Executed by:
| 195 | ||||||||||||
336 | case BIO_CTRL_POP: executed 1 time by 1 test: case 7: Executed by:
| 1 | ||||||||||||
337 | /* Only detach if we are the BIO explicitly being popped */ | - | ||||||||||||
338 | if (b == ptr) {
| 0-1 | ||||||||||||
339 | /* This will clear the reference we obtained during push */ | - | ||||||||||||
340 | SSL_set_bio(ssl, NULL, NULL); | - | ||||||||||||
341 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||
342 | break; executed 1 time by 1 test: break; Executed by:
| 1 | ||||||||||||
343 | case BIO_C_DO_STATE_MACHINE: executed 191 times by 1 test: case 101: Executed by:
| 191 | ||||||||||||
344 | BIO_clear_retry_flags(b); | - | ||||||||||||
345 | - | |||||||||||||
346 | BIO_set_retry_reason(b, 0); | - | ||||||||||||
347 | ret = (int)SSL_do_handshake(ssl); | - | ||||||||||||
348 | - | |||||||||||||
349 | switch (SSL_get_error(ssl, (int)ret)) { | - | ||||||||||||
350 | case SSL_ERROR_WANT_READ: never executed: case 2: | 0 | ||||||||||||
351 | BIO_set_flags(b, BIO_FLAGS_READ | BIO_FLAGS_SHOULD_RETRY); | - | ||||||||||||
352 | break; never executed: break; | 0 | ||||||||||||
353 | case SSL_ERROR_WANT_WRITE: never executed: case 3: | 0 | ||||||||||||
354 | BIO_set_flags(b, BIO_FLAGS_WRITE | BIO_FLAGS_SHOULD_RETRY); | - | ||||||||||||
355 | break; never executed: break; | 0 | ||||||||||||
356 | case SSL_ERROR_WANT_CONNECT: never executed: case 7: | 0 | ||||||||||||
357 | BIO_set_flags(b, BIO_FLAGS_IO_SPECIAL | BIO_FLAGS_SHOULD_RETRY); | - | ||||||||||||
358 | BIO_set_retry_reason(b, BIO_get_retry_reason(next)); | - | ||||||||||||
359 | break; never executed: break; | 0 | ||||||||||||
360 | case SSL_ERROR_WANT_X509_LOOKUP: never executed: case 4: | 0 | ||||||||||||
361 | BIO_set_retry_special(b); | - | ||||||||||||
362 | BIO_set_retry_reason(b, BIO_RR_SSL_X509_LOOKUP); | - | ||||||||||||
363 | break; never executed: break; | 0 | ||||||||||||
364 | default: executed 191 times by 1 test: default: Executed by:
| 191 | ||||||||||||
365 | break; executed 191 times by 1 test: break; Executed by:
| 191 | ||||||||||||
366 | } | - | ||||||||||||
367 | break; executed 191 times by 1 test: break; Executed by:
| 191 | ||||||||||||
368 | case BIO_CTRL_DUP: never executed: case 12: | 0 | ||||||||||||
369 | dbio = (BIO *)ptr; | - | ||||||||||||
370 | dbs = BIO_get_data(dbio); | - | ||||||||||||
371 | SSL_free(dbs->ssl); | - | ||||||||||||
372 | dbs->ssl = SSL_dup(ssl); | - | ||||||||||||
373 | dbs->num_renegotiates = bs->num_renegotiates; | - | ||||||||||||
374 | dbs->renegotiate_count = bs->renegotiate_count; | - | ||||||||||||
375 | dbs->byte_count = bs->byte_count; | - | ||||||||||||
376 | dbs->renegotiate_timeout = bs->renegotiate_timeout; | - | ||||||||||||
377 | dbs->last_time = bs->last_time; | - | ||||||||||||
378 | ret = (dbs->ssl != NULL); | - | ||||||||||||
379 | break; never executed: break; | 0 | ||||||||||||
380 | case BIO_C_GET_FD: never executed: case 105: | 0 | ||||||||||||
381 | ret = BIO_ctrl(ssl->rbio, cmd, num, ptr); | - | ||||||||||||
382 | break; never executed: break; | 0 | ||||||||||||
383 | case BIO_CTRL_SET_CALLBACK: never executed: case 14: | 0 | ||||||||||||
384 | ret = 0; /* use callback ctrl */ | - | ||||||||||||
385 | break; never executed: break; | 0 | ||||||||||||
386 | default: never executed: default: | 0 | ||||||||||||
387 | ret = BIO_ctrl(ssl->rbio, cmd, num, ptr); | - | ||||||||||||
388 | break; never executed: break; | 0 | ||||||||||||
389 | } | - | ||||||||||||
390 | return ret; executed 2551 times by 1 test: return ret; Executed by:
| 2551 | ||||||||||||
391 | } | - | ||||||||||||
392 | - | |||||||||||||
393 | static long ssl_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp) | - | ||||||||||||
394 | { | - | ||||||||||||
395 | SSL *ssl; | - | ||||||||||||
396 | BIO_SSL *bs; | - | ||||||||||||
397 | long ret = 1; | - | ||||||||||||
398 | - | |||||||||||||
399 | bs = BIO_get_data(b); | - | ||||||||||||
400 | ssl = bs->ssl; | - | ||||||||||||
401 | switch (cmd) { | - | ||||||||||||
402 | case BIO_CTRL_SET_CALLBACK: never executed: case 14: | 0 | ||||||||||||
403 | ret = BIO_callback_ctrl(ssl->rbio, cmd, fp); | - | ||||||||||||
404 | break; never executed: break; | 0 | ||||||||||||
405 | default: never executed: default: | 0 | ||||||||||||
406 | ret = 0; | - | ||||||||||||
407 | break; never executed: break; | 0 | ||||||||||||
408 | } | - | ||||||||||||
409 | return ret; never executed: return ret; | 0 | ||||||||||||
410 | } | - | ||||||||||||
411 | - | |||||||||||||
412 | static int ssl_puts(BIO *bp, const char *str) | - | ||||||||||||
413 | { | - | ||||||||||||
414 | int n, ret; | - | ||||||||||||
415 | - | |||||||||||||
416 | n = strlen(str); | - | ||||||||||||
417 | ret = BIO_write(bp, str, n); | - | ||||||||||||
418 | return ret; never executed: return ret; | 0 | ||||||||||||
419 | } | - | ||||||||||||
420 | - | |||||||||||||
421 | BIO *BIO_new_buffer_ssl_connect(SSL_CTX *ctx) | - | ||||||||||||
422 | { | - | ||||||||||||
423 | #ifndef OPENSSL_NO_SOCK | - | ||||||||||||
424 | BIO *ret = NULL, *buf = NULL, *ssl = NULL; | - | ||||||||||||
425 | - | |||||||||||||
426 | if ((buf = BIO_new(BIO_f_buffer())) == NULL)
| 0 | ||||||||||||
427 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||
428 | if ((ssl = BIO_new_ssl_connect(ctx)) == NULL)
| 0 | ||||||||||||
429 | goto err; never executed: goto err; | 0 | ||||||||||||
430 | if ((ret = BIO_push(buf, ssl)) == NULL)
| 0 | ||||||||||||
431 | goto err; never executed: goto err; | 0 | ||||||||||||
432 | return ret; never executed: return ret; | 0 | ||||||||||||
433 | err: | - | ||||||||||||
434 | BIO_free(buf); | - | ||||||||||||
435 | BIO_free(ssl); | - | ||||||||||||
436 | #endif | - | ||||||||||||
437 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||
438 | } | - | ||||||||||||
439 | - | |||||||||||||
440 | BIO *BIO_new_ssl_connect(SSL_CTX *ctx) | - | ||||||||||||
441 | { | - | ||||||||||||
442 | #ifndef OPENSSL_NO_SOCK | - | ||||||||||||
443 | BIO *ret = NULL, *con = NULL, *ssl = NULL; | - | ||||||||||||
444 | - | |||||||||||||
445 | if ((con = BIO_new(BIO_s_connect())) == NULL)
| 0 | ||||||||||||
446 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||
447 | if ((ssl = BIO_new_ssl(ctx, 1)) == NULL)
| 0 | ||||||||||||
448 | goto err; never executed: goto err; | 0 | ||||||||||||
449 | if ((ret = BIO_push(ssl, con)) == NULL)
| 0 | ||||||||||||
450 | goto err; never executed: goto err; | 0 | ||||||||||||
451 | return ret; never executed: return ret; | 0 | ||||||||||||
452 | err: | - | ||||||||||||
453 | BIO_free(con); | - | ||||||||||||
454 | #endif | - | ||||||||||||
455 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||
456 | } | - | ||||||||||||
457 | - | |||||||||||||
458 | BIO *BIO_new_ssl(SSL_CTX *ctx, int client) | - | ||||||||||||
459 | { | - | ||||||||||||
460 | BIO *ret; | - | ||||||||||||
461 | SSL *ssl; | - | ||||||||||||
462 | - | |||||||||||||
463 | if ((ret = BIO_new(BIO_f_ssl())) == NULL)
| 0 | ||||||||||||
464 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||
465 | if ((ssl = SSL_new(ctx)) == NULL) {
| 0 | ||||||||||||
466 | BIO_free(ret); | - | ||||||||||||
467 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||
468 | } | - | ||||||||||||
469 | if (client)
| 0 | ||||||||||||
470 | SSL_set_connect_state(ssl); never executed: SSL_set_connect_state(ssl); | 0 | ||||||||||||
471 | else | - | ||||||||||||
472 | SSL_set_accept_state(ssl); never executed: SSL_set_accept_state(ssl); | 0 | ||||||||||||
473 | - | |||||||||||||
474 | BIO_set_ssl(ret, ssl, BIO_CLOSE); | - | ||||||||||||
475 | return ret; never executed: return ret; | 0 | ||||||||||||
476 | } | - | ||||||||||||
477 | - | |||||||||||||
478 | int BIO_ssl_copy_session_id(BIO *t, BIO *f) | - | ||||||||||||
479 | { | - | ||||||||||||
480 | BIO_SSL *tdata, *fdata; | - | ||||||||||||
481 | t = BIO_find_type(t, BIO_TYPE_SSL); | - | ||||||||||||
482 | f = BIO_find_type(f, BIO_TYPE_SSL); | - | ||||||||||||
483 | if ((t == NULL) || (f == NULL))
| 0 | ||||||||||||
484 | return 0; never executed: return 0; | 0 | ||||||||||||
485 | tdata = BIO_get_data(t); | - | ||||||||||||
486 | fdata = BIO_get_data(f); | - | ||||||||||||
487 | if ((tdata->ssl == NULL) || (fdata->ssl == NULL))
| 0 | ||||||||||||
488 | return 0; never executed: return 0; | 0 | ||||||||||||
489 | if (!SSL_copy_session_id(tdata->ssl, (fdata->ssl)))
| 0 | ||||||||||||
490 | return 0; never executed: return 0; | 0 | ||||||||||||
491 | return 1; never executed: return 1; | 0 | ||||||||||||
492 | } | - | ||||||||||||
493 | - | |||||||||||||
494 | void BIO_ssl_shutdown(BIO *b) | - | ||||||||||||
495 | { | - | ||||||||||||
496 | BIO_SSL *bdata; | - | ||||||||||||
497 | - | |||||||||||||
498 | for (; b != NULL; b = BIO_next(b)) {
| 0 | ||||||||||||
499 | if (BIO_method_type(b) != BIO_TYPE_SSL)
| 0 | ||||||||||||
500 | continue; never executed: continue; | 0 | ||||||||||||
501 | bdata = BIO_get_data(b); | - | ||||||||||||
502 | if (bdata != NULL && bdata->ssl != NULL)
| 0 | ||||||||||||
503 | SSL_shutdown(bdata->ssl); never executed: SSL_shutdown(bdata->ssl); | 0 | ||||||||||||
504 | } never executed: end of block | 0 | ||||||||||||
505 | } never executed: end of block | 0 | ||||||||||||
Source code | Switch to Preprocessed file |