OpenCoverage

d1_both.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/libressl/src/ssl/d1_both.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* $OpenBSD: d1_both.c,v 1.55 2018/09/05 16:58:59 jsing Exp $ */-
2/*-
3 * DTLS implementation written by Nagendra Modadugu-
4 * (nagendra@cs.stanford.edu) for the OpenSSL project 2005.-
5 */-
6/* ====================================================================-
7 * Copyright (c) 1998-2005 The OpenSSL Project. All rights reserved.-
8 *-
9 * Redistribution and use in source and binary forms, with or without-
10 * modification, are permitted provided that the following conditions-
11 * are met:-
12 *-
13 * 1. Redistributions of source code must retain the above copyright-
14 * notice, this list of conditions and the following disclaimer.-
15 *-
16 * 2. Redistributions in binary form must reproduce the above copyright-
17 * notice, this list of conditions and the following disclaimer in-
18 * the documentation and/or other materials provided with the-
19 * distribution.-
20 *-
21 * 3. All advertising materials mentioning features or use of this-
22 * software must display the following acknowledgment:-
23 * "This product includes software developed by the OpenSSL Project-
24 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"-
25 *-
26 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to-
27 * endorse or promote products derived from this software without-
28 * prior written permission. For written permission, please contact-
29 * openssl-core@openssl.org.-
30 *-
31 * 5. Products derived from this software may not be called "OpenSSL"-
32 * nor may "OpenSSL" appear in their names without prior written-
33 * permission of the OpenSSL Project.-
34 *-
35 * 6. Redistributions of any form whatsoever must retain the following-
36 * acknowledgment:-
37 * "This product includes software developed by the OpenSSL Project-
38 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"-
39 *-
40 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY-
41 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE-
42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR-
43 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR-
44 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,-
45 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT-
46 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;-
47 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)-
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,-
49 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)-
50 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED-
51 * OF THE POSSIBILITY OF SUCH DAMAGE.-
52 * ====================================================================-
53 *-
54 * This product includes cryptographic software written by Eric Young-
55 * (eay@cryptsoft.com). This product includes software written by Tim-
56 * Hudson (tjh@cryptsoft.com).-
57 *-
58 */-
59/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)-
60 * All rights reserved.-
61 *-
62 * This package is an SSL implementation written-
63 * by Eric Young (eay@cryptsoft.com).-
64 * The implementation was written so as to conform with Netscapes SSL.-
65 *-
66 * This library is free for commercial and non-commercial use as long as-
67 * the following conditions are aheared to. The following conditions-
68 * apply to all code found in this distribution, be it the RC4, RSA,-
69 * lhash, DES, etc., code; not just the SSL code. The SSL documentation-
70 * included with this distribution is covered by the same copyright terms-
71 * except that the holder is Tim Hudson (tjh@cryptsoft.com).-
72 *-
73 * Copyright remains Eric Young's, and as such any Copyright notices in-
74 * the code are not to be removed.-
75 * If this package is used in a product, Eric Young should be given attribution-
76 * as the author of the parts of the library used.-
77 * This can be in the form of a textual message at program startup or-
78 * in documentation (online or textual) provided with the package.-
79 *-
80 * Redistribution and use in source and binary forms, with or without-
81 * modification, are permitted provided that the following conditions-
82 * are met:-
83 * 1. Redistributions of source code must retain the copyright-
84 * notice, this list of conditions and the following disclaimer.-
85 * 2. Redistributions in binary form must reproduce the above copyright-
86 * notice, this list of conditions and the following disclaimer in the-
87 * documentation and/or other materials provided with the distribution.-
88 * 3. All advertising materials mentioning features or use of this software-
89 * must display the following acknowledgement:-
90 * "This product includes cryptographic software written by-
91 * Eric Young (eay@cryptsoft.com)"-
92 * The word 'cryptographic' can be left out if the rouines from the library-
93 * being used are not cryptographic related :-).-
94 * 4. If you include any Windows specific code (or a derivative thereof) from-
95 * the apps directory (application code) you must include an acknowledgement:-
96 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"-
97 *-
98 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND-
99 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE-
100 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE-
101 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE-
102 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL-
103 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS-
104 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)-
105 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT-
106 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY-
107 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF-
108 * SUCH DAMAGE.-
109 *-
110 * The licence and distribution terms for any publically available version or-
111 * derivative of this code cannot be changed. i.e. this code cannot simply be-
112 * copied and put under another distribution licence-
113 * [including the GNU Public Licence.]-
114 */-
115-
116#include <limits.h>-
117#include <stdio.h>-
118#include <string.h>-
119-
120#include "ssl_locl.h"-
121-
122#include <openssl/buffer.h>-
123#include <openssl/evp.h>-
124#include <openssl/objects.h>-
125#include <openssl/x509.h>-
126-
127#include "pqueue.h"-
128#include "bytestring.h"-
129-
130#define RSMBLY_BITMASK_SIZE(msg_len) (((msg_len) + 7) / 8)-
131-
132#define RSMBLY_BITMASK_MARK(bitmask, start, end) { \-
133 if ((end) - (start) <= 8) { \-
134 long ii; \-
135 for (ii = (start); ii < (end); ii++) bitmask[((ii) >> 3)] |= (1 << ((ii) & 7)); \-
136 } else { \-
137 long ii; \-
138 bitmask[((start) >> 3)] |= bitmask_start_values[((start) & 7)]; \-
139 for (ii = (((start) >> 3) + 1); ii < ((((end) - 1)) >> 3); ii++) bitmask[ii] = 0xff; \-
140 bitmask[(((end) - 1) >> 3)] |= bitmask_end_values[((end) & 7)]; \-
141 } }-
142-
143#define RSMBLY_BITMASK_IS_COMPLETE(bitmask, msg_len, is_complete) { \-
144 long ii; \-
145 OPENSSL_assert((msg_len) > 0); \-
146 is_complete = 1; \-
147 if (bitmask[(((msg_len) - 1) >> 3)] != bitmask_end_values[((msg_len) & 7)]) is_complete = 0; \-
148 if (is_complete) for (ii = (((msg_len) - 1) >> 3) - 1; ii >= 0 ; ii--) \-
149 if (bitmask[ii] != 0xff) { is_complete = 0; break; } }-
150-
151static unsigned char bitmask_start_values[] = {-
152 0xff, 0xfe, 0xfc, 0xf8, 0xf0, 0xe0, 0xc0, 0x80-
153};-
154static unsigned char bitmask_end_values[] = {-
155 0xff, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f-
156};-
157-
158/* XDTLS: figure out the right values */-
159static unsigned int g_probable_mtu[] = {1500 - 28, 512 - 28, 256 - 28};-
160-
161static unsigned int dtls1_guess_mtu(unsigned int curr_mtu);-
162static void dtls1_fix_message_header(SSL *s, unsigned long frag_off,-
163 unsigned long frag_len);-
164static int dtls1_write_message_header(const struct hm_header_st *msg_hdr,-
165 unsigned long frag_off, unsigned long frag_len, unsigned char *p);-
166static long dtls1_get_message_fragment(SSL *s, int st1, int stn, long max,-
167 int *ok);-
168-
169static hm_fragment *-
170dtls1_hm_fragment_new(unsigned long frag_len, int reassembly)-
171{-
172 hm_fragment *frag = NULL;-
173 unsigned char *buf = NULL;-
174 unsigned char *bitmask = NULL;-
175-
176 frag = malloc(sizeof(hm_fragment));-
177 if (frag == NULL)
frag == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 129 times by 2 tests
Evaluated by:
  • clienttest
  • ssltest
0-129
178 return NULL;
never executed: return ((void *)0) ;
0
179-
180 if (frag_len) {
frag_lenDescription
TRUEevaluated 129 times by 2 tests
Evaluated by:
  • clienttest
  • ssltest
FALSEnever evaluated
0-129
181 buf = malloc(frag_len);-
182 if (buf == NULL) {
buf == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 129 times by 2 tests
Evaluated by:
  • clienttest
  • ssltest
0-129
183 free(frag);-
184 return NULL;
never executed: return ((void *)0) ;
0
185 }-
186 }
executed 129 times by 2 tests: end of block
Executed by:
  • clienttest
  • ssltest
129
187-
188 /* zero length fragment gets zero frag->fragment */-
189 frag->fragment = buf;-
190-
191 /* Initialize reassembly bitmask if necessary */-
192 if (reassembly) {
reassemblyDescription
TRUEevaluated 8 times by 1 test
Evaluated by:
  • ssltest
FALSEevaluated 121 times by 2 tests
Evaluated by:
  • clienttest
  • ssltest
8-121
193 bitmask = malloc(RSMBLY_BITMASK_SIZE(frag_len));-
194 if (bitmask == NULL) {
bitmask == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • ssltest
0-8
195 free(buf);-
196 free(frag);-
197 return NULL;
never executed: return ((void *)0) ;
0
198 }-
199 memset(bitmask, 0, RSMBLY_BITMASK_SIZE(frag_len));-
200 }
executed 8 times by 1 test: end of block
Executed by:
  • ssltest
8
201-
202 frag->reassembly = bitmask;-
203-
204 return frag;
executed 129 times by 2 tests: return frag;
Executed by:
  • clienttest
  • ssltest
129
205}-
206-
207static void-
208dtls1_hm_fragment_free(hm_fragment *frag)-
209{-
210 if (frag == NULL)
frag == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 95 times by 1 test
Evaluated by:
  • ssltest
0-95
211 return;
never executed: return;
0
212-
213 if (frag->msg_header.is_ccs) {
frag->msg_header.is_ccsDescription
TRUEevaluated 11 times by 1 test
Evaluated by:
  • ssltest
FALSEevaluated 84 times by 1 test
Evaluated by:
  • ssltest
11-84
214 EVP_CIPHER_CTX_free(-
215 frag->msg_header.saved_retransmit_state.enc_write_ctx);-
216 EVP_MD_CTX_free(-
217 frag->msg_header.saved_retransmit_state.write_hash);-
218 }
executed 11 times by 1 test: end of block
Executed by:
  • ssltest
11
219 free(frag->fragment);-
220 free(frag->reassembly);-
221 free(frag);-
222}
executed 95 times by 1 test: end of block
Executed by:
  • ssltest
95
223-
224/* send s->internal->init_buf in records of type 'type' (SSL3_RT_HANDSHAKE or SSL3_RT_CHANGE_CIPHER_SPEC) */-
225int-
226dtls1_do_write(SSL *s, int type)-
227{-
228 int ret;-
229 int curr_mtu;-
230 unsigned int len, frag_off, mac_size, blocksize;-
231-
232 /* AHA! Figure out the MTU, and stick to the right size */-
233 if (D1I(s)->mtu < dtls1_min_mtu() &&
(s->d1->intern...tls1_min_mtu()Description
TRUEevaluated 23 times by 2 tests
Evaluated by:
  • clienttest
  • ssltest
FALSEevaluated 98 times by 1 test
Evaluated by:
  • ssltest
23-98
234 !(SSL_get_options(s) & SSL_OP_NO_QUERY_MTU)) {
!(SSL_ctrl((s)...& 0x00001000L)Description
TRUEevaluated 23 times by 2 tests
Evaluated by:
  • clienttest
  • ssltest
FALSEnever evaluated
0-23
235 D1I(s)->mtu = BIO_ctrl(SSL_get_wbio(s),-
236 BIO_CTRL_DGRAM_QUERY_MTU, 0, NULL);-
237-
238 /*-
239 * I've seen the kernel return bogus numbers when it-
240 * doesn't know the MTU (ie., the initial write), so just-
241 * make sure we have a reasonable number-
242 */-
243 if (D1I(s)->mtu < dtls1_min_mtu()) {
(s->d1->intern...tls1_min_mtu()Description
TRUEevaluated 23 times by 2 tests
Evaluated by:
  • clienttest
  • ssltest
FALSEnever evaluated
0-23
244 D1I(s)->mtu = 0;-
245 D1I(s)->mtu = dtls1_guess_mtu(D1I(s)->mtu);-
246 BIO_ctrl(SSL_get_wbio(s), BIO_CTRL_DGRAM_SET_MTU,-
247 D1I(s)->mtu, NULL);-
248 }
executed 23 times by 2 tests: end of block
Executed by:
  • clienttest
  • ssltest
23
249 }
executed 23 times by 2 tests: end of block
Executed by:
  • clienttest
  • ssltest
23
250-
251 OPENSSL_assert(D1I(s)->mtu >= dtls1_min_mtu());-
252 /* should have something reasonable now */-
253-
254 if (s->internal->init_off == 0 && type == SSL3_RT_HANDSHAKE)
s->internal->init_off == 0Description
TRUEevaluated 121 times by 2 tests
Evaluated by:
  • clienttest
  • ssltest
FALSEnever evaluated
type == 22Description
TRUEevaluated 99 times by 2 tests
Evaluated by:
  • clienttest
  • ssltest
FALSEevaluated 22 times by 1 test
Evaluated by:
  • ssltest
0-121
255 OPENSSL_assert(s->internal->init_num ==
executed 99 times by 2 tests: (void)((s->internal->init_num == (int)(s->d1->internal)->w_msg_hdr.msg_len + 12) ? 0 : (OpenSSLDie( __FILE__ , 256 , "s->internal->init_num == (int)D1I(s)->w_msg_hdr.msg_len + DTLS1_HM_HEADER_LENGTH"),1)) ;
Executed by:
  • clienttest
  • ssltest
99
256 (int)D1I(s)->w_msg_hdr.msg_len + DTLS1_HM_HEADER_LENGTH);
executed 99 times by 2 tests: (void)((s->internal->init_num == (int)(s->d1->internal)->w_msg_hdr.msg_len + 12) ? 0 : (OpenSSLDie( __FILE__ , 256 , "s->internal->init_num == (int)D1I(s)->w_msg_hdr.msg_len + DTLS1_HM_HEADER_LENGTH"),1)) ;
Executed by:
  • clienttest
  • ssltest
99
257-
258 if (s->internal->write_hash)
s->internal->write_hashDescription
TRUEevaluated 22 times by 1 test
Evaluated by:
  • ssltest
FALSEevaluated 99 times by 2 tests
Evaluated by:
  • clienttest
  • ssltest
22-99
259 mac_size = EVP_MD_CTX_size(s->internal->write_hash);
executed 22 times by 1 test: mac_size = EVP_MD_size(EVP_MD_CTX_md(s->internal->write_hash));
Executed by:
  • ssltest
22
260 else-
261 mac_size = 0;
executed 99 times by 2 tests: mac_size = 0;
Executed by:
  • clienttest
  • ssltest
99
262-
263 if (s->internal->enc_write_ctx &&
s->internal->enc_write_ctxDescription
TRUEevaluated 22 times by 1 test
Evaluated by:
  • ssltest
FALSEevaluated 99 times by 2 tests
Evaluated by:
  • clienttest
  • ssltest
22-99
264 (EVP_CIPHER_mode( s->internal->enc_write_ctx->cipher) & EVP_CIPH_CBC_MODE))
((EVP_CIPHER_f...xF0007) & 0x2)Description
TRUEevaluated 18 times by 1 test
Evaluated by:
  • ssltest
FALSEevaluated 4 times by 1 test
Evaluated by:
  • ssltest
4-18
265 blocksize = 2 * EVP_CIPHER_block_size(s->internal->enc_write_ctx->cipher);
executed 18 times by 1 test: blocksize = 2 * EVP_CIPHER_block_size(s->internal->enc_write_ctx->cipher);
Executed by:
  • ssltest
18
266 else-
267 blocksize = 0;
executed 103 times by 2 tests: blocksize = 0;
Executed by:
  • clienttest
  • ssltest
103
268-
269 frag_off = 0;-
270 while (s->internal->init_num) {
s->internal->init_numDescription
TRUEevaluated 132 times by 2 tests
Evaluated by:
  • clienttest
  • ssltest
FALSEnever evaluated
0-132
271 curr_mtu = D1I(s)->mtu - BIO_wpending(SSL_get_wbio(s)) --
272 DTLS1_RT_HEADER_LENGTH - mac_size - blocksize;-
273-
274 if (curr_mtu <= DTLS1_HM_HEADER_LENGTH) {
curr_mtu <= 12Description
TRUEevaluated 11 times by 1 test
Evaluated by:
  • ssltest
FALSEevaluated 121 times by 2 tests
Evaluated by:
  • clienttest
  • ssltest
11-121
275 /* grr.. we could get an error if MTU picked was wrong */-
276 ret = BIO_flush(SSL_get_wbio(s));-
277 if (ret <= 0)
ret <= 0Description
TRUEnever evaluated
FALSEevaluated 11 times by 1 test
Evaluated by:
  • ssltest
0-11
278 return ret;
never executed: return ret;
0
279 curr_mtu = D1I(s)->mtu - DTLS1_RT_HEADER_LENGTH --
280 mac_size - blocksize;-
281 }
executed 11 times by 1 test: end of block
Executed by:
  • ssltest
11
282-
283 if (s->internal->init_num > curr_mtu)
s->internal->i...num > curr_mtuDescription
TRUEevaluated 11 times by 1 test
Evaluated by:
  • ssltest
FALSEevaluated 121 times by 2 tests
Evaluated by:
  • clienttest
  • ssltest
11-121
284 len = curr_mtu;
executed 11 times by 1 test: len = curr_mtu;
Executed by:
  • ssltest
11
285 else-
286 len = s->internal->init_num;
executed 121 times by 2 tests: len = s->internal->init_num;
Executed by:
  • clienttest
  • ssltest
121
287-
288-
289 /* XDTLS: this function is too long. split out the CCS part */-
290 if (type == SSL3_RT_HANDSHAKE) {
type == 22Description
TRUEevaluated 110 times by 2 tests
Evaluated by:
  • clienttest
  • ssltest
FALSEevaluated 22 times by 1 test
Evaluated by:
  • ssltest
22-110
291 if (s->internal->init_off != 0) {
s->internal->init_off != 0Description
TRUEevaluated 11 times by 1 test
Evaluated by:
  • ssltest
FALSEevaluated 99 times by 2 tests
Evaluated by:
  • clienttest
  • ssltest
11-99
292 OPENSSL_assert(s->internal->init_off > DTLS1_HM_HEADER_LENGTH);-
293 s->internal->init_off -= DTLS1_HM_HEADER_LENGTH;-
294 s->internal->init_num += DTLS1_HM_HEADER_LENGTH;-
295-
296 if (s->internal->init_num > curr_mtu)
s->internal->i...num > curr_mtuDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • ssltest
FALSEevaluated 8 times by 1 test
Evaluated by:
  • ssltest
3-8
297 len = curr_mtu;
executed 3 times by 1 test: len = curr_mtu;
Executed by:
  • ssltest
3
298 else-
299 len = s->internal->init_num;
executed 8 times by 1 test: len = s->internal->init_num;
Executed by:
  • ssltest
8
300 }-
301-
302 dtls1_fix_message_header(s, frag_off,-
303 len - DTLS1_HM_HEADER_LENGTH);-
304-
305 if (!dtls1_write_message_header(&D1I(s)->w_msg_hdr,
!dtls1_write_m...al->init_off])Description
TRUEnever evaluated
FALSEevaluated 110 times by 2 tests
Evaluated by:
  • clienttest
  • ssltest
0-110
306 D1I(s)->w_msg_hdr.frag_off, D1I(s)->w_msg_hdr.frag_len,
!dtls1_write_m...al->init_off])Description
TRUEnever evaluated
FALSEevaluated 110 times by 2 tests
Evaluated by:
  • clienttest
  • ssltest
0-110
307 (unsigned char *)&s->internal->init_buf->data[s->internal->init_off]))
!dtls1_write_m...al->init_off])Description
TRUEnever evaluated
FALSEevaluated 110 times by 2 tests
Evaluated by:
  • clienttest
  • ssltest
0-110
308 return -1;
never executed: return -1;
0
309-
310 OPENSSL_assert(len >= DTLS1_HM_HEADER_LENGTH);-
311 }
executed 110 times by 2 tests: end of block
Executed by:
  • clienttest
  • ssltest
110
312-
313 ret = dtls1_write_bytes(s, type,-
314 &s->internal->init_buf->data[s->internal->init_off], len);-
315 if (ret < 0) {
ret < 0Description
TRUEnever evaluated
FALSEevaluated 132 times by 2 tests
Evaluated by:
  • clienttest
  • ssltest
0-132
316 /*-
317 * Might need to update MTU here, but we don't know-
318 * which previous packet caused the failure -- so-
319 * can't really retransmit anything. continue as-
320 * if everything is fine and wait for an alert to-
321 * handle the retransmit-
322 */-
323 if (BIO_ctrl(SSL_get_wbio(s),
BIO_ctrl(SSL_g...oid *)0) ) > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
324 BIO_CTRL_DGRAM_MTU_EXCEEDED, 0, NULL) > 0)
BIO_ctrl(SSL_g...oid *)0) ) > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
325 D1I(s)->mtu = BIO_ctrl(SSL_get_wbio(s),
never executed: (s->d1->internal)->mtu = BIO_ctrl(SSL_get_wbio(s), 40, 0, ((void *)0) );
0
326 BIO_CTRL_DGRAM_QUERY_MTU, 0, NULL);
never executed: (s->d1->internal)->mtu = BIO_ctrl(SSL_get_wbio(s), 40, 0, ((void *)0) );
0
327 else-
328 return (-1);
never executed: return (-1);
0
329 } else {-
330-
331 /*-
332 * Bad if this assert fails, only part of the-
333 * handshake message got sent. but why would-
334 * this happen?-
335 */-
336 OPENSSL_assert(len == (unsigned int)ret);-
337-
338 if (type == SSL3_RT_HANDSHAKE &&
type == 22Description
TRUEevaluated 110 times by 2 tests
Evaluated by:
  • clienttest
  • ssltest
FALSEevaluated 22 times by 1 test
Evaluated by:
  • ssltest
22-110
339 !D1I(s)->retransmitting) {
!(s->d1->inter...retransmittingDescription
TRUEevaluated 110 times by 2 tests
Evaluated by:
  • clienttest
  • ssltest
FALSEnever evaluated
0-110
340 /*-
341 * Should not be done for 'Hello Request's,-
342 * but in that case we'll ignore the result-
343 * anyway-
344 */-
345 unsigned char *p = (unsigned char *)&s->internal->init_buf->data[s->internal->init_off];-
346 const struct hm_header_st *msg_hdr = &D1I(s)->w_msg_hdr;-
347 int xlen;-
348-
349 if (frag_off == 0) {
frag_off == 0Description
TRUEevaluated 99 times by 2 tests
Evaluated by:
  • clienttest
  • ssltest
FALSEevaluated 11 times by 1 test
Evaluated by:
  • ssltest
11-99
350 /*-
351 * Reconstruct message header is if it-
352 * is being sent in single fragment-
353 */-
354 if (!dtls1_write_message_header(msg_hdr,
!dtls1_write_m...r->msg_len, p)Description
TRUEnever evaluated
FALSEevaluated 99 times by 2 tests
Evaluated by:
  • clienttest
  • ssltest
0-99
355 0, msg_hdr->msg_len, p))
!dtls1_write_m...r->msg_len, p)Description
TRUEnever evaluated
FALSEevaluated 99 times by 2 tests
Evaluated by:
  • clienttest
  • ssltest
0-99
356 return (-1);
never executed: return (-1);
0
357 xlen = ret;-
358 } else {
executed 99 times by 2 tests: end of block
Executed by:
  • clienttest
  • ssltest
99
359 p += DTLS1_HM_HEADER_LENGTH;-
360 xlen = ret - DTLS1_HM_HEADER_LENGTH;-
361 }
executed 11 times by 1 test: end of block
Executed by:
  • ssltest
11
362-
363 tls1_finish_mac(s, p, xlen);-
364 }
executed 110 times by 2 tests: end of block
Executed by:
  • clienttest
  • ssltest
110
365-
366 if (ret == s->internal->init_num) {
ret == s->internal->init_numDescription
TRUEevaluated 121 times by 2 tests
Evaluated by:
  • clienttest
  • ssltest
FALSEevaluated 11 times by 1 test
Evaluated by:
  • ssltest
11-121
367 if (s->internal->msg_callback)
s->internal->msg_callbackDescription
TRUEnever evaluated
FALSEevaluated 121 times by 2 tests
Evaluated by:
  • clienttest
  • ssltest
0-121
368 s->internal->msg_callback(1, s->version, type,
never executed: s->internal->msg_callback(1, s->version, type, s->internal->init_buf->data, (size_t)(s->internal->init_off + s->internal->init_num), s, s->internal->msg_callback_arg);
0
369 s->internal->init_buf->data,
never executed: s->internal->msg_callback(1, s->version, type, s->internal->init_buf->data, (size_t)(s->internal->init_off + s->internal->init_num), s, s->internal->msg_callback_arg);
0
370 (size_t)(s->internal->init_off + s->internal->init_num),
never executed: s->internal->msg_callback(1, s->version, type, s->internal->init_buf->data, (size_t)(s->internal->init_off + s->internal->init_num), s, s->internal->msg_callback_arg);
0
371 s, s->internal->msg_callback_arg);
never executed: s->internal->msg_callback(1, s->version, type, s->internal->init_buf->data, (size_t)(s->internal->init_off + s->internal->init_num), s, s->internal->msg_callback_arg);
0
372-
373 s->internal->init_off = 0;-
374 /* done writing this message */-
375 s->internal->init_num = 0;-
376-
377 return (1);
executed 121 times by 2 tests: return (1);
Executed by:
  • clienttest
  • ssltest
121
378 }-
379 s->internal->init_off += ret;-
380 s->internal->init_num -= ret;-
381 frag_off += (ret -= DTLS1_HM_HEADER_LENGTH);-
382 }
executed 11 times by 1 test: end of block
Executed by:
  • ssltest
11
383 }-
384 return (0);
never executed: return (0);
0
385}-
386-
387-
388/*-
389 * Obtain handshake message of message type 'mt' (any if mt == -1),-
390 * maximum acceptable body length 'max'.-
391 * Read an entire handshake message. Handshake messages arrive in-
392 * fragments.-
393 */-
394long-
395dtls1_get_message(SSL *s, int st1, int stn, int mt, long max, int *ok)-
396{-
397 int i, al;-
398 struct hm_header_st *msg_hdr;-
399 unsigned char *p;-
400 unsigned long msg_len;-
401-
402 /*-
403 * s3->internal->tmp is used to store messages that are unexpected, caused-
404 * by the absence of an optional handshake message-
405 */-
406 if (S3I(s)->tmp.reuse_message) {
(s->s3->intern....reuse_messageDescription
TRUEevaluated 36 times by 1 test
Evaluated by:
  • ssltest
FALSEevaluated 132 times by 2 tests
Evaluated by:
  • clienttest
  • ssltest
36-132
407 S3I(s)->tmp.reuse_message = 0;-
408 if ((mt >= 0) && (S3I(s)->tmp.message_type != mt)) {
(mt >= 0)Description
TRUEevaluated 18 times by 1 test
Evaluated by:
  • ssltest
FALSEevaluated 18 times by 1 test
Evaluated by:
  • ssltest
((s->s3->inter...ge_type != mt)Description
TRUEnever evaluated
FALSEevaluated 18 times by 1 test
Evaluated by:
  • ssltest
0-18
409 al = SSL_AD_UNEXPECTED_MESSAGE;-
410 SSLerror(s, SSL_R_UNEXPECTED_MESSAGE);-
411 goto f_err;
never executed: goto f_err;
0
412 }-
413 *ok = 1;-
414 s->internal->init_msg = s->internal->init_buf->data + DTLS1_HM_HEADER_LENGTH;-
415 s->internal->init_num = (int)S3I(s)->tmp.message_size;-
416 return s->internal->init_num;
executed 36 times by 1 test: return s->internal->init_num;
Executed by:
  • ssltest
36
417 }-
418-
419 msg_hdr = &D1I(s)->r_msg_hdr;-
420 memset(msg_hdr, 0x00, sizeof(struct hm_header_st));-
421-
422again:
code before this statement executed 132 times by 2 tests: again:
Executed by:
  • clienttest
  • ssltest
132
423 i = dtls1_get_message_fragment(s, st1, stn, max, ok);-
424 if (i == DTLS1_HM_BAD_FRAGMENT ||
i == -2Description
TRUEnever evaluated
FALSEevaluated 151 times by 2 tests
Evaluated by:
  • clienttest
  • ssltest
0-151
425 i == DTLS1_HM_FRAGMENT_RETRY) /* bad fragment received */
i == -3Description
TRUEevaluated 19 times by 1 test
Evaluated by:
  • ssltest
FALSEevaluated 132 times by 2 tests
Evaluated by:
  • clienttest
  • ssltest
19-132
426 goto again;
executed 19 times by 1 test: goto again;
Executed by:
  • ssltest
19
427 else if (i <= 0 && !*ok)
i <= 0Description
TRUEevaluated 45 times by 2 tests
Evaluated by:
  • clienttest
  • ssltest
FALSEevaluated 87 times by 1 test
Evaluated by:
  • ssltest
!*okDescription
TRUEevaluated 34 times by 2 tests
Evaluated by:
  • clienttest
  • ssltest
FALSEevaluated 11 times by 1 test
Evaluated by:
  • ssltest
11-87
428 return i;
executed 34 times by 2 tests: return i;
Executed by:
  • clienttest
  • ssltest
34
429-
430 p = (unsigned char *)s->internal->init_buf->data;-
431 msg_len = msg_hdr->msg_len;-
432-
433 /* reconstruct message header */-
434 if (!dtls1_write_message_header(msg_hdr, 0, msg_len, p))
!dtls1_write_m...0, msg_len, p)Description
TRUEnever evaluated
FALSEevaluated 98 times by 1 test
Evaluated by:
  • ssltest
0-98
435 return -1;
never executed: return -1;
0
436-
437 msg_len += DTLS1_HM_HEADER_LENGTH;-
438-
439 tls1_finish_mac(s, p, msg_len);-
440 if (s->internal->msg_callback)
s->internal->msg_callbackDescription
TRUEnever evaluated
FALSEevaluated 98 times by 1 test
Evaluated by:
  • ssltest
0-98
441 s->internal->msg_callback(0, s->version, SSL3_RT_HANDSHAKE, p, msg_len,
never executed: s->internal->msg_callback(0, s->version, 22, p, msg_len, s, s->internal->msg_callback_arg);
0
442 s, s->internal->msg_callback_arg);
never executed: s->internal->msg_callback(0, s->version, 22, p, msg_len, s, s->internal->msg_callback_arg);
0
443-
444 memset(msg_hdr, 0x00, sizeof(struct hm_header_st));-
445-
446 /* Don't change sequence numbers while listening */-
447 if (!D1I(s)->listen)
!(s->d1->internal)->listenDescription
TRUEevaluated 98 times by 1 test
Evaluated by:
  • ssltest
FALSEnever evaluated
0-98
448 D1I(s)->handshake_read_seq++;
executed 98 times by 1 test: (s->d1->internal)->handshake_read_seq++;
Executed by:
  • ssltest
98
449-
450 s->internal->init_msg = s->internal->init_buf->data + DTLS1_HM_HEADER_LENGTH;-
451 return s->internal->init_num;
executed 98 times by 1 test: return s->internal->init_num;
Executed by:
  • ssltest
98
452-
453f_err:-
454 ssl3_send_alert(s, SSL3_AL_FATAL, al);-
455 *ok = 0;-
456 return -1;
never executed: return -1;
0
457}-
458-
459-
460static int-
461dtls1_preprocess_fragment(SSL *s, struct hm_header_st *msg_hdr, int max)-
462{-
463 size_t frag_off, frag_len, msg_len;-
464-
465 msg_len = msg_hdr->msg_len;-
466 frag_off = msg_hdr->frag_off;-
467 frag_len = msg_hdr->frag_len;-
468-
469 /* sanity checking */-
470 if ((frag_off + frag_len) > msg_len) {
(frag_off + fr...len) > msg_lenDescription
TRUEnever evaluated
FALSEevaluated 98 times by 1 test
Evaluated by:
  • ssltest
0-98
471 SSLerror(s, SSL_R_EXCESSIVE_MESSAGE_SIZE);-
472 return SSL_AD_ILLEGAL_PARAMETER;
never executed: return 47;
0
473 }-
474-
475 if ((frag_off + frag_len) > (unsigned long)max) {
(frag_off + fr...igned long)maxDescription
TRUEnever evaluated
FALSEevaluated 98 times by 1 test
Evaluated by:
  • ssltest
0-98
476 SSLerror(s, SSL_R_EXCESSIVE_MESSAGE_SIZE);-
477 return SSL_AD_ILLEGAL_PARAMETER;
never executed: return 47;
0
478 }-
479-
480 if ( D1I(s)->r_msg_hdr.frag_off == 0) /* first fragment */
(s->d1->intern....frag_off == 0Description
TRUEevaluated 98 times by 1 test
Evaluated by:
  • ssltest
FALSEnever evaluated
0-98
481 {-
482 /*-
483 * msg_len is limited to 2^24, but is effectively checked-
484 * against max above-
485 */-
486 if (!BUF_MEM_grow_clean(s->internal->init_buf,
!BUF_MEM_grow_... msg_len + 12)Description
TRUEnever evaluated
FALSEevaluated 98 times by 1 test
Evaluated by:
  • ssltest
0-98
487 msg_len + DTLS1_HM_HEADER_LENGTH)) {
!BUF_MEM_grow_... msg_len + 12)Description
TRUEnever evaluated
FALSEevaluated 98 times by 1 test
Evaluated by:
  • ssltest
0-98
488 SSLerror(s, ERR_R_BUF_LIB);-
489 return SSL_AD_INTERNAL_ERROR;
never executed: return 80;
0
490 }-
491-
492 S3I(s)->tmp.message_size = msg_len;-
493 D1I(s)->r_msg_hdr.msg_len = msg_len;-
494 S3I(s)->tmp.message_type = msg_hdr->type;-
495 D1I(s)->r_msg_hdr.type = msg_hdr->type;-
496 D1I(s)->r_msg_hdr.seq = msg_hdr->seq;-
497 } else if (msg_len != D1I(s)->r_msg_hdr.msg_len) {
executed 98 times by 1 test: end of block
Executed by:
  • ssltest
msg_len != (s-...sg_hdr.msg_lenDescription
TRUEnever evaluated
FALSEnever evaluated
0-98
498 /*-
499 * They must be playing with us! BTW, failure to enforce-
500 * upper limit would open possibility for buffer overrun.-
501 */-
502 SSLerror(s, SSL_R_EXCESSIVE_MESSAGE_SIZE);-
503 return SSL_AD_ILLEGAL_PARAMETER;
never executed: return 47;
0
504 }-
505-
506 return 0; /* no error */
executed 98 times by 1 test: return 0;
Executed by:
  • ssltest
98
507}-
508-
509static int-
510dtls1_retrieve_buffered_fragment(SSL *s, long max, int *ok)-
511{-
512 /*-
513 * (0) check whether the desired fragment is available-
514 * if so:-
515 * (1) copy over the fragment to s->internal->init_buf->data[]-
516 * (2) update s->internal->init_num-
517 */-
518 pitem *item;-
519 hm_fragment *frag;-
520 int al;-
521-
522 *ok = 0;-
523 item = pqueue_peek(D1I(s)->buffered_messages);-
524 if (item == NULL)
item == ((void *)0)Description
TRUEevaluated 132 times by 2 tests
Evaluated by:
  • clienttest
  • ssltest
FALSEevaluated 19 times by 1 test
Evaluated by:
  • ssltest
19-132
525 return 0;
executed 132 times by 2 tests: return 0;
Executed by:
  • clienttest
  • ssltest
132
526-
527 frag = (hm_fragment *)item->data;-
528-
529 /* Don't return if reassembly still in progress */-
530 if (frag->reassembly != NULL)
frag->reassemb...!= ((void *)0)Description
TRUEevaluated 11 times by 1 test
Evaluated by:
  • ssltest
FALSEevaluated 8 times by 1 test
Evaluated by:
  • ssltest
8-11
531 return 0;
executed 11 times by 1 test: return 0;
Executed by:
  • ssltest
11
532-
533 if (D1I(s)->handshake_read_seq == frag->msg_header.seq) {
(s->d1->intern...msg_header.seqDescription
TRUEevaluated 8 times by 1 test
Evaluated by:
  • ssltest
FALSEnever evaluated
0-8
534 unsigned long frag_len = frag->msg_header.frag_len;-
535 pqueue_pop(D1I(s)->buffered_messages);-
536-
537 al = dtls1_preprocess_fragment(s, &frag->msg_header, max);-
538-
539 if (al == 0) /* no alert */
al == 0Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • ssltest
FALSEnever evaluated
0-8
540 {-
541 unsigned char *p = (unsigned char *)s->internal->init_buf->data + DTLS1_HM_HEADER_LENGTH;-
542 memcpy(&p[frag->msg_header.frag_off],-
543 frag->fragment, frag->msg_header.frag_len);-
544 }
executed 8 times by 1 test: end of block
Executed by:
  • ssltest
8
545-
546 dtls1_hm_fragment_free(frag);-
547 pitem_free(item);-
548-
549 if (al == 0) {
al == 0Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • ssltest
FALSEnever evaluated
0-8
550 *ok = 1;-
551 return frag_len;
executed 8 times by 1 test: return frag_len;
Executed by:
  • ssltest
8
552 }-
553-
554 ssl3_send_alert(s, SSL3_AL_FATAL, al);-
555 s->internal->init_num = 0;-
556 *ok = 0;-
557 return -1;
never executed: return -1;
0
558 } else-
559 return 0;
never executed: return 0;
0
560}-
561-
562/*-
563 * dtls1_max_handshake_message_len returns the maximum number of bytes-
564 * permitted in a DTLS handshake message for |s|. The minimum is 16KB,-
565 * but may be greater if the maximum certificate list size requires it.-
566 */-
567static unsigned long-
568dtls1_max_handshake_message_len(const SSL *s)-
569{-
570 unsigned long max_len;-
571-
572 max_len = DTLS1_HM_HEADER_LENGTH + SSL3_RT_MAX_ENCRYPTED_LENGTH;-
573 if (max_len < (unsigned long)s->internal->max_cert_list)
max_len < (uns...>max_cert_listDescription
TRUEevaluated 19 times by 1 test
Evaluated by:
  • ssltest
FALSEnever evaluated
0-19
574 return s->internal->max_cert_list;
executed 19 times by 1 test: return s->internal->max_cert_list;
Executed by:
  • ssltest
19
575 return max_len;
never executed: return max_len;
0
576}-
577-
578static int-
579dtls1_reassemble_fragment(SSL *s, struct hm_header_st* msg_hdr, int *ok)-
580{-
581 hm_fragment *frag = NULL;-
582 pitem *item = NULL;-
583 int i = -1, is_complete;-
584 unsigned char seq64be[8];-
585 unsigned long frag_len = msg_hdr->frag_len;-
586-
587 if ((msg_hdr->frag_off + frag_len) > msg_hdr->msg_len ||
(msg_hdr->frag...g_hdr->msg_lenDescription
TRUEnever evaluated
FALSEevaluated 19 times by 1 test
Evaluated by:
  • ssltest
0-19
588 msg_hdr->msg_len > dtls1_max_handshake_message_len(s))
msg_hdr->msg_l...message_len(s)Description
TRUEnever evaluated
FALSEevaluated 19 times by 1 test
Evaluated by:
  • ssltest
0-19
589 goto err;
never executed: goto err;
0
590-
591 if (frag_len == 0) {
frag_len == 0Description
TRUEnever evaluated
FALSEevaluated 19 times by 1 test
Evaluated by:
  • ssltest
0-19
592 i = DTLS1_HM_FRAGMENT_RETRY;-
593 goto err;
never executed: goto err;
0
594 }-
595-
596 /* Try to find item in queue */-
597 memset(seq64be, 0, sizeof(seq64be));-
598 seq64be[6] = (unsigned char)(msg_hdr->seq >> 8);-
599 seq64be[7] = (unsigned char)msg_hdr->seq;-
600 item = pqueue_find(D1I(s)->buffered_messages, seq64be);-
601-
602 if (item == NULL) {
item == ((void *)0)Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • ssltest
FALSEevaluated 11 times by 1 test
Evaluated by:
  • ssltest
8-11
603 frag = dtls1_hm_fragment_new(msg_hdr->msg_len, 1);-
604 if (frag == NULL)
frag == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • ssltest
0-8
605 goto err;
never executed: goto err;
0
606 memcpy(&(frag->msg_header), msg_hdr, sizeof(*msg_hdr));-
607 frag->msg_header.frag_len = frag->msg_header.msg_len;-
608 frag->msg_header.frag_off = 0;-
609 } else {
executed 8 times by 1 test: end of block
Executed by:
  • ssltest
8
610 frag = (hm_fragment*)item->data;-
611 if (frag->msg_header.msg_len != msg_hdr->msg_len) {
frag->msg_head...g_hdr->msg_lenDescription
TRUEnever evaluated
FALSEevaluated 11 times by 1 test
Evaluated by:
  • ssltest
0-11
612 item = NULL;-
613 frag = NULL;-
614 goto err;
never executed: goto err;
0
615 }-
616 }
executed 11 times by 1 test: end of block
Executed by:
  • ssltest
11
617-
618 /*-
619 * If message is already reassembled, this must be a-
620 * retransmit and can be dropped.-
621 */-
622 if (frag->reassembly == NULL) {
frag->reassemb...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 19 times by 1 test
Evaluated by:
  • ssltest
0-19
623 unsigned char devnull [256];-
624-
625 while (frag_len) {
frag_lenDescription
TRUEnever evaluated
FALSEnever evaluated
0
626 i = s->method->internal->ssl_read_bytes(s, SSL3_RT_HANDSHAKE,-
627 devnull, frag_len > sizeof(devnull) ?-
628 sizeof(devnull) : frag_len, 0);-
629 if (i <= 0)
i <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
630 goto err;
never executed: goto err;
0
631 frag_len -= i;-
632 }
never executed: end of block
0
633 i = DTLS1_HM_FRAGMENT_RETRY;-
634 goto err;
never executed: goto err;
0
635 }-
636-
637 /* read the body of the fragment (header has already been read */-
638 i = s->method->internal->ssl_read_bytes(s, SSL3_RT_HANDSHAKE,-
639 frag->fragment + msg_hdr->frag_off, frag_len, 0);-
640 if (i <= 0 || (unsigned long)i != frag_len)
i <= 0Description
TRUEnever evaluated
FALSEevaluated 19 times by 1 test
Evaluated by:
  • ssltest
(unsigned long)i != frag_lenDescription
TRUEnever evaluated
FALSEevaluated 19 times by 1 test
Evaluated by:
  • ssltest
0-19
641 goto err;
never executed: goto err;
0
642-
643 RSMBLY_BITMASK_MARK(frag->reassembly, (long)msg_hdr->frag_off,
executed 8 times by 1 test: frag->reassembly[((ii) >> 3)] |= (1 << ((ii) & 7));
Executed by:
  • ssltest
executed 2 times by 1 test: end of block
Executed by:
  • ssltest
executed 1870 times by 1 test: frag->reassembly[ii] = 0xff;
Executed by:
  • ssltest
executed 17 times by 1 test: end of block
Executed by:
  • ssltest
((long)(msg_hd...frag_off) <= 8Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • ssltest
FALSEevaluated 17 times by 1 test
Evaluated by:
  • ssltest
ii < ((long)(m...f + frag_len))Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • ssltest
FALSEevaluated 2 times by 1 test
Evaluated by:
  • ssltest
ii < (((((long...)) - 1)) >> 3)Description
TRUEevaluated 1870 times by 1 test
Evaluated by:
  • ssltest
FALSEevaluated 17 times by 1 test
Evaluated by:
  • ssltest
2-1870
644 (long)(msg_hdr->frag_off + frag_len));-
645-
646 RSMBLY_BITMASK_IS_COMPLETE(frag->reassembly, (long)msg_hdr->msg_len,
executed 11 times by 1 test: is_complete = 0;
Executed by:
  • ssltest
never executed: break;
frag->reassemb...msg_len) & 7)]Description
TRUEevaluated 11 times by 1 test
Evaluated by:
  • ssltest
FALSEevaluated 8 times by 1 test
Evaluated by:
  • ssltest
is_completeDescription
TRUEevaluated 8 times by 1 test
Evaluated by:
  • ssltest
FALSEevaluated 11 times by 1 test
Evaluated by:
  • ssltest
frag->reassembly[ii] != 0xffDescription
TRUEnever evaluated
FALSEevaluated 1887 times by 1 test
Evaluated by:
  • ssltest
ii >= 0Description
TRUEevaluated 1887 times by 1 test
Evaluated by:
  • ssltest
FALSEevaluated 8 times by 1 test
Evaluated by:
  • ssltest
0-1887
647 is_complete);-
648-
649 if (is_complete) {
is_completeDescription
TRUEevaluated 8 times by 1 test
Evaluated by:
  • ssltest
FALSEevaluated 11 times by 1 test
Evaluated by:
  • ssltest
8-11
650 free(frag->reassembly);-
651 frag->reassembly = NULL;-
652 }
executed 8 times by 1 test: end of block
Executed by:
  • ssltest
8
653-
654 if (item == NULL) {
item == ((void *)0)Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • ssltest
FALSEevaluated 11 times by 1 test
Evaluated by:
  • ssltest
8-11
655 memset(seq64be, 0, sizeof(seq64be));-
656 seq64be[6] = (unsigned char)(msg_hdr->seq >> 8);-
657 seq64be[7] = (unsigned char)(msg_hdr->seq);-
658-
659 item = pitem_new(seq64be, frag);-
660 if (item == NULL) {
item == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • ssltest
0-8
661 i = -1;-
662 goto err;
never executed: goto err;
0
663 }-
664-
665 pqueue_insert(D1I(s)->buffered_messages, item);-
666 }
executed 8 times by 1 test: end of block
Executed by:
  • ssltest
8
667-
668 return DTLS1_HM_FRAGMENT_RETRY;
executed 19 times by 1 test: return -3;
Executed by:
  • ssltest
19
669-
670err:-
671 if (item == NULL && frag != NULL)
item == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
frag != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
672 dtls1_hm_fragment_free(frag);
never executed: dtls1_hm_fragment_free(frag);
0
673 *ok = 0;-
674 return i;
never executed: return i;
0
675}-
676-
677-
678static int-
679dtls1_process_out_of_seq_message(SSL *s, struct hm_header_st* msg_hdr, int *ok)-
680{-
681 int i = -1;-
682 hm_fragment *frag = NULL;-
683 pitem *item = NULL;-
684 unsigned char seq64be[8];-
685 unsigned long frag_len = msg_hdr->frag_len;-
686-
687 if ((msg_hdr->frag_off + frag_len) > msg_hdr->msg_len)
(msg_hdr->frag...g_hdr->msg_lenDescription
TRUEnever evaluated
FALSEnever evaluated
0
688 goto err;
never executed: goto err;
0
689-
690 /* Try to find item in queue, to prevent duplicate entries */-
691 memset(seq64be, 0, sizeof(seq64be));-
692 seq64be[6] = (unsigned char) (msg_hdr->seq >> 8);-
693 seq64be[7] = (unsigned char) msg_hdr->seq;-
694 item = pqueue_find(D1I(s)->buffered_messages, seq64be);-
695-
696 /*-
697 * If we already have an entry and this one is a fragment,-
698 * don't discard it and rather try to reassemble it.-
699 */-
700 if (item != NULL && frag_len < msg_hdr->msg_len)
item != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
frag_len < msg_hdr->msg_lenDescription
TRUEnever evaluated
FALSEnever evaluated
0
701 item = NULL;
never executed: item = ((void *)0) ;
0
702-
703 /*-
704 * Discard the message if sequence number was already there, is-
705 * too far in the future, already in the queue or if we received-
706 * a FINISHED before the SERVER_HELLO, which then must be a stale-
707 * retransmit.-
708 */-
709 if (msg_hdr->seq <= D1I(s)->handshake_read_seq ||
msg_hdr->seq <...shake_read_seqDescription
TRUEnever evaluated
FALSEnever evaluated
0
710 msg_hdr->seq > D1I(s)->handshake_read_seq + 10 || item != NULL ||
msg_hdr->seq >..._read_seq + 10Description
TRUEnever evaluated
FALSEnever evaluated
item != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
711 (D1I(s)->handshake_read_seq == 0 &&
(s->d1->intern..._read_seq == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
712 msg_hdr->type == SSL3_MT_FINISHED)) {
msg_hdr->type == 20Description
TRUEnever evaluated
FALSEnever evaluated
0
713 unsigned char devnull [256];-
714-
715 while (frag_len) {
frag_lenDescription
TRUEnever evaluated
FALSEnever evaluated
0
716 i = s->method->internal->ssl_read_bytes(s, SSL3_RT_HANDSHAKE,-
717 devnull, frag_len > sizeof(devnull) ?-
718 sizeof(devnull) : frag_len, 0);-
719 if (i <= 0)
i <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
720 goto err;
never executed: goto err;
0
721 frag_len -= i;-
722 }
never executed: end of block
0
723 } else {
never executed: end of block
0
724 if (frag_len < msg_hdr->msg_len)
frag_len < msg_hdr->msg_lenDescription
TRUEnever evaluated
FALSEnever evaluated
0
725 return dtls1_reassemble_fragment(s, msg_hdr, ok);
never executed: return dtls1_reassemble_fragment(s, msg_hdr, ok);
0
726-
727 if (frag_len > dtls1_max_handshake_message_len(s))
frag_len > dtl...message_len(s)Description
TRUEnever evaluated
FALSEnever evaluated
0
728 goto err;
never executed: goto err;
0
729-
730 frag = dtls1_hm_fragment_new(frag_len, 0);-
731 if (frag == NULL)
frag == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
732 goto err;
never executed: goto err;
0
733-
734 memcpy(&(frag->msg_header), msg_hdr, sizeof(*msg_hdr));-
735-
736 if (frag_len) {
frag_lenDescription
TRUEnever evaluated
FALSEnever evaluated
0
737 /* read the body of the fragment (header has already been read */-
738 i = s->method->internal->ssl_read_bytes(s, SSL3_RT_HANDSHAKE,-
739 frag->fragment, frag_len, 0);-
740 if (i <= 0 || (unsigned long)i != frag_len)
i <= 0Description
TRUEnever evaluated
FALSEnever evaluated
(unsigned long)i != frag_lenDescription
TRUEnever evaluated
FALSEnever evaluated
0
741 goto err;
never executed: goto err;
0
742 }
never executed: end of block
0
743-
744 memset(seq64be, 0, sizeof(seq64be));-
745 seq64be[6] = (unsigned char)(msg_hdr->seq >> 8);-
746 seq64be[7] = (unsigned char)(msg_hdr->seq);-
747-
748 item = pitem_new(seq64be, frag);-
749 if (item == NULL)
item == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
750 goto err;
never executed: goto err;
0
751-
752 pqueue_insert(D1I(s)->buffered_messages, item);-
753 }
never executed: end of block
0
754-
755 return DTLS1_HM_FRAGMENT_RETRY;
never executed: return -3;
0
756-
757err:-
758 if (item == NULL && frag != NULL)
item == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
frag != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
759 dtls1_hm_fragment_free(frag);
never executed: dtls1_hm_fragment_free(frag);
0
760 *ok = 0;-
761 return i;
never executed: return i;
0
762}-
763-
764-
765static long-
766dtls1_get_message_fragment(SSL *s, int st1, int stn, long max, int *ok)-
767{-
768 unsigned char wire[DTLS1_HM_HEADER_LENGTH];-
769 unsigned long len, frag_off, frag_len;-
770 int i, al;-
771 struct hm_header_st msg_hdr;-
772-
773again:
code before this statement executed 151 times by 2 tests: again:
Executed by:
  • clienttest
  • ssltest
151
774 /* see if we have the required fragment already */-
775 if ((frag_len = dtls1_retrieve_buffered_fragment(s, max, ok)) || *ok) {
(frag_len = dt...t(s, max, ok))Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • ssltest
FALSEevaluated 143 times by 2 tests
Evaluated by:
  • clienttest
  • ssltest
*okDescription
TRUEnever evaluated
FALSEevaluated 143 times by 2 tests
Evaluated by:
  • clienttest
  • ssltest
0-143
776 if (*ok)
*okDescription
TRUEevaluated 8 times by 1 test
Evaluated by:
  • ssltest
FALSEnever evaluated
0-8
777 s->internal->init_num = frag_len;
executed 8 times by 1 test: s->internal->init_num = frag_len;
Executed by:
  • ssltest
8
778 return frag_len;
executed 8 times by 1 test: return frag_len;
Executed by:
  • ssltest
8
779 }-
780-
781 /* read handshake message header */-
782 i = s->method->internal->ssl_read_bytes(s, SSL3_RT_HANDSHAKE, wire,-
783 DTLS1_HM_HEADER_LENGTH, 0);-
784 if (i <= 0) /* nbio, or an error */
i <= 0Description
TRUEevaluated 34 times by 2 tests
Evaluated by:
  • clienttest
  • ssltest
FALSEevaluated 109 times by 1 test
Evaluated by:
  • ssltest
34-109
785 {-
786 s->internal->rwstate = SSL_READING;-
787 *ok = 0;-
788 return i;
executed 34 times by 2 tests: return i;
Executed by:
  • clienttest
  • ssltest
34
789 }-
790 /* Handshake fails if message header is incomplete */-
791 if (i != DTLS1_HM_HEADER_LENGTH ||
i != 12Description
TRUEnever evaluated
FALSEevaluated 109 times by 1 test
Evaluated by:
  • ssltest
0-109
792 /* parse the message fragment header */-
793 dtls1_get_message_header(wire, &msg_hdr) == 0) {
dtls1_get_mess...&msg_hdr) == 0Description
TRUEnever evaluated
FALSEevaluated 109 times by 1 test
Evaluated by:
  • ssltest
0-109
794 al = SSL_AD_UNEXPECTED_MESSAGE;-
795 SSLerror(s, SSL_R_UNEXPECTED_MESSAGE);-
796 goto f_err;
never executed: goto f_err;
0
797 }-
798-
799 /*-
800 * if this is a future (or stale) message it gets buffered-
801 * (or dropped)--no further processing at this time-
802 * While listening, we accept seq 1 (ClientHello with cookie)-
803 * although we're still expecting seq 0 (ClientHello)-
804 */-
805 if (msg_hdr.seq != D1I(s)->handshake_read_seq &&
msg_hdr.seq !=...shake_read_seqDescription
TRUEnever evaluated
FALSEevaluated 109 times by 1 test
Evaluated by:
  • ssltest
0-109
806 !(D1I(s)->listen && msg_hdr.seq == 1))
(s->d1->internal)->listenDescription
TRUEnever evaluated
FALSEnever evaluated
msg_hdr.seq == 1Description
TRUEnever evaluated
FALSEnever evaluated
0
807 return dtls1_process_out_of_seq_message(s, &msg_hdr, ok);
never executed: return dtls1_process_out_of_seq_message(s, &msg_hdr, ok);
0
808-
809 len = msg_hdr.msg_len;-
810 frag_off = msg_hdr.frag_off;-
811 frag_len = msg_hdr.frag_len;-
812-
813 if (frag_len && frag_len < len)
frag_lenDescription
TRUEevaluated 98 times by 1 test
Evaluated by:
  • ssltest
FALSEevaluated 11 times by 1 test
Evaluated by:
  • ssltest
frag_len < lenDescription
TRUEevaluated 19 times by 1 test
Evaluated by:
  • ssltest
FALSEevaluated 79 times by 1 test
Evaluated by:
  • ssltest
11-98
814 return dtls1_reassemble_fragment(s, &msg_hdr, ok);
executed 19 times by 1 test: return dtls1_reassemble_fragment(s, &msg_hdr, ok);
Executed by:
  • ssltest
19
815-
816 if (!s->server && D1I(s)->r_msg_hdr.frag_off == 0 &&
!s->serverDescription
TRUEevaluated 57 times by 1 test
Evaluated by:
  • ssltest
FALSEevaluated 33 times by 1 test
Evaluated by:
  • ssltest
(s->d1->intern....frag_off == 0Description
TRUEevaluated 57 times by 1 test
Evaluated by:
  • ssltest
FALSEnever evaluated
0-57
817 wire[0] == SSL3_MT_HELLO_REQUEST) {
wire[0] == 0Description
TRUEnever evaluated
FALSEevaluated 57 times by 1 test
Evaluated by:
  • ssltest
0-57
818 /*-
819 * The server may always send 'Hello Request' messages ---
820 * we are doing a handshake anyway now, so ignore them-
821 * if their format is correct. Does not count for-
822 * 'Finished' MAC.-
823 */-
824 if (wire[1] == 0 && wire[2] == 0 && wire[3] == 0) {
wire[1] == 0Description
TRUEnever evaluated
FALSEnever evaluated
wire[2] == 0Description
TRUEnever evaluated
FALSEnever evaluated
wire[3] == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
825 if (s->internal->msg_callback)
s->internal->msg_callbackDescription
TRUEnever evaluated
FALSEnever evaluated
0
826 s->internal->msg_callback(0, s->version,
never executed: s->internal->msg_callback(0, s->version, 22, wire, 12, s, s->internal->msg_callback_arg);
0
827 SSL3_RT_HANDSHAKE, wire,
never executed: s->internal->msg_callback(0, s->version, 22, wire, 12, s, s->internal->msg_callback_arg);
0
828 DTLS1_HM_HEADER_LENGTH, s,
never executed: s->internal->msg_callback(0, s->version, 22, wire, 12, s, s->internal->msg_callback_arg);
0
829 s->internal->msg_callback_arg);
never executed: s->internal->msg_callback(0, s->version, 22, wire, 12, s, s->internal->msg_callback_arg);
0
830-
831 s->internal->init_num = 0;-
832 goto again;
never executed: goto again;
0
833 }-
834 else /* Incorrectly formated Hello request */-
835 {-
836 al = SSL_AD_UNEXPECTED_MESSAGE;-
837 SSLerror(s, SSL_R_UNEXPECTED_MESSAGE);-
838 goto f_err;
never executed: goto f_err;
0
839 }-
840 }-
841-
842 if ((al = dtls1_preprocess_fragment(s, &msg_hdr, max)))
(al = dtls1_pr...msg_hdr, max))Description
TRUEnever evaluated
FALSEevaluated 90 times by 1 test
Evaluated by:
  • ssltest
0-90
843 goto f_err;
never executed: goto f_err;
0
844-
845 /* XDTLS: ressurect this when restart is in place */-
846 S3I(s)->hs.state = stn;-
847-
848 if (frag_len > 0) {
frag_len > 0Description
TRUEevaluated 79 times by 1 test
Evaluated by:
  • ssltest
FALSEevaluated 11 times by 1 test
Evaluated by:
  • ssltest
11-79
849 unsigned char *p = (unsigned char *)s->internal->init_buf->data + DTLS1_HM_HEADER_LENGTH;-
850-
851 i = s->method->internal->ssl_read_bytes(s, SSL3_RT_HANDSHAKE,-
852 &p[frag_off], frag_len, 0);-
853 /* XDTLS: fix this--message fragments cannot span multiple packets */-
854 if (i <= 0) {
i <= 0Description
TRUEnever evaluated
FALSEevaluated 79 times by 1 test
Evaluated by:
  • ssltest
0-79
855 s->internal->rwstate = SSL_READING;-
856 *ok = 0;-
857 return i;
never executed: return i;
0
858 }-
859 } else
executed 79 times by 1 test: end of block
Executed by:
  • ssltest
79
860 i = 0;
executed 11 times by 1 test: i = 0;
Executed by:
  • ssltest
11
861-
862 /*-
863 * XDTLS: an incorrectly formatted fragment should cause the-
864 * handshake to fail-
865 */-
866 if (i != (int)frag_len) {
i != (int)frag_lenDescription
TRUEnever evaluated
FALSEevaluated 90 times by 1 test
Evaluated by:
  • ssltest
0-90
867 al = SSL3_AD_ILLEGAL_PARAMETER;-
868 SSLerror(s, SSL3_AD_ILLEGAL_PARAMETER);-
869 goto f_err;
never executed: goto f_err;
0
870 }-
871-
872 *ok = 1;-
873-
874 /*-
875 * Note that s->internal->init_num is *not* used as current offset in-
876 * s->internal->init_buf->data, but as a counter summing up fragments'-
877 * lengths: as soon as they sum up to handshake packet-
878 * length, we assume we have got all the fragments.-
879 */-
880 s->internal->init_num = frag_len;-
881 return frag_len;
executed 90 times by 1 test: return frag_len;
Executed by:
  • ssltest
90
882-
883f_err:-
884 ssl3_send_alert(s, SSL3_AL_FATAL, al);-
885 s->internal->init_num = 0;-
886-
887 *ok = 0;-
888 return (-1);
never executed: return (-1);
0
889}-
890-
891int-
892dtls1_read_failed(SSL *s, int code)-
893{-
894 if (code > 0) {
code > 0Description
TRUEnever evaluated
FALSEevaluated 45 times by 2 tests
Evaluated by:
  • clienttest
  • ssltest
0-45
895#ifdef DEBUG-
896 fprintf(stderr, "invalid state reached %s:%d",-
897 __FILE__, __LINE__);-
898#endif-
899 return 1;
never executed: return 1;
0
900 }-
901-
902 if (!dtls1_is_timer_expired(s)) {
!dtls1_is_timer_expired(s)Description
TRUEevaluated 45 times by 2 tests
Evaluated by:
  • clienttest
  • ssltest
FALSEnever evaluated
0-45
903 /*-
904 * not a timeout, none of our business, let higher layers-
905 * handle this. in fact it's probably an error-
906 */-
907 return code;
executed 45 times by 2 tests: return code;
Executed by:
  • clienttest
  • ssltest
45
908 }-
909-
910 if (!SSL_in_init(s)) /* done, no need to send a retransmit */
!(SSL_state((s...x1000|0x2000))Description
TRUEnever evaluated
FALSEnever evaluated
0
911 {-
912 BIO_set_flags(SSL_get_rbio(s), BIO_FLAGS_READ);-
913 return code;
never executed: return code;
0
914 }-
915-
916 return dtls1_handle_timeout(s);
never executed: return dtls1_handle_timeout(s);
0
917}-
918-
919int-
920dtls1_get_queue_priority(unsigned short seq, int is_ccs)-
921{-
922 /*-
923 * The index of the retransmission queue actually is the message-
924 * sequence number, since the queue only contains messages of a-
925 * single handshake. However, the ChangeCipherSpec has no message-
926 * sequence number and so using only the sequence will result in-
927 * the CCS and Finished having the same index. To prevent this, the-
928 * sequence number is multiplied by 2. In case of a CCS 1 is-
929 * subtracted. This does not only differ CSS and Finished, it also-
930 * maintains the order of the index (important for priority queues)-
931 * and fits in the unsigned short variable.-
932 */-
933 return seq * 2 - is_ccs;
executed 242 times by 2 tests: return seq * 2 - is_ccs;
Executed by:
  • clienttest
  • ssltest
242
934}-
935-
936int-
937dtls1_retransmit_buffered_messages(SSL *s)-
938{-
939 pqueue sent = s->d1->sent_messages;-
940 piterator iter;-
941 pitem *item;-
942 hm_fragment *frag;-
943 int found = 0;-
944-
945 iter = pqueue_iterator(sent);-
946-
947 for (item = pqueue_next(&iter); item != NULL;
item != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
948 item = pqueue_next(&iter)) {-
949 frag = (hm_fragment *)item->data;-
950 if (dtls1_retransmit_message(s,
dtls1_retransm..., &found) <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
951 (unsigned short)dtls1_get_queue_priority(
dtls1_retransm..., &found) <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
952 frag->msg_header.seq, frag->msg_header.is_ccs), 0,
dtls1_retransm..., &found) <= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
953 &found) <= 0 && found) {
dtls1_retransm..., &found) <= 0Description
TRUEnever evaluated
FALSEnever evaluated
foundDescription
TRUEnever evaluated
FALSEnever evaluated
0
954#ifdef DEBUG-
955 fprintf(stderr, "dtls1_retransmit_message() failed\n");-
956#endif-
957 return -1;
never executed: return -1;
0
958 }-
959 }
never executed: end of block
0
960-
961 return 1;
never executed: return 1;
0
962}-
963-
964int-
965dtls1_buffer_message(SSL *s, int is_ccs)-
966{-
967 pitem *item;-
968 hm_fragment *frag;-
969 unsigned char seq64be[8];-
970-
971 /* Buffer the messsage in order to handle DTLS retransmissions. */-
972-
973 /*-
974 * This function is called immediately after a message has-
975 * been serialized-
976 */-
977 OPENSSL_assert(s->internal->init_off == 0);-
978-
979 frag = dtls1_hm_fragment_new(s->internal->init_num, 0);-
980 if (frag == NULL)
frag == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 121 times by 2 tests
Evaluated by:
  • clienttest
  • ssltest
0-121
981 return 0;
never executed: return 0;
0
982-
983 memcpy(frag->fragment, s->internal->init_buf->data, s->internal->init_num);-
984-
985 if (is_ccs) {
is_ccsDescription
TRUEevaluated 22 times by 1 test
Evaluated by:
  • ssltest
FALSEevaluated 99 times by 2 tests
Evaluated by:
  • clienttest
  • ssltest
22-99
986 OPENSSL_assert(D1I(s)->w_msg_hdr.msg_len +-
987 ((s->version == DTLS1_VERSION) ?-
988 DTLS1_CCS_HEADER_LENGTH : 3) == (unsigned int)s->internal->init_num);-
989 } else {
executed 22 times by 1 test: end of block
Executed by:
  • ssltest
22
990 OPENSSL_assert(D1I(s)->w_msg_hdr.msg_len +-
991 DTLS1_HM_HEADER_LENGTH == (unsigned int)s->internal->init_num);-
992 }
executed 99 times by 2 tests: end of block
Executed by:
  • clienttest
  • ssltest
99
993-
994 frag->msg_header.msg_len = D1I(s)->w_msg_hdr.msg_len;-
995 frag->msg_header.seq = D1I(s)->w_msg_hdr.seq;-
996 frag->msg_header.type = D1I(s)->w_msg_hdr.type;-
997 frag->msg_header.frag_off = 0;-
998 frag->msg_header.frag_len = D1I(s)->w_msg_hdr.msg_len;-
999 frag->msg_header.is_ccs = is_ccs;-
1000-
1001 /* save current state*/-
1002 frag->msg_header.saved_retransmit_state.enc_write_ctx = s->internal->enc_write_ctx;-
1003 frag->msg_header.saved_retransmit_state.write_hash = s->internal->write_hash;-
1004 frag->msg_header.saved_retransmit_state.session = s->session;-
1005 frag->msg_header.saved_retransmit_state.epoch = D1I(s)->w_epoch;-
1006-
1007 memset(seq64be, 0, sizeof(seq64be));-
1008 seq64be[6] = (unsigned char)(dtls1_get_queue_priority(-
1009 frag->msg_header.seq, frag->msg_header.is_ccs) >> 8);-
1010 seq64be[7] = (unsigned char)(dtls1_get_queue_priority(-
1011 frag->msg_header.seq, frag->msg_header.is_ccs));-
1012-
1013 item = pitem_new(seq64be, frag);-
1014 if (item == NULL) {
item == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 121 times by 2 tests
Evaluated by:
  • clienttest
  • ssltest
0-121
1015 dtls1_hm_fragment_free(frag);-
1016 return 0;
never executed: return 0;
0
1017 }-
1018-
1019 pqueue_insert(s->d1->sent_messages, item);-
1020 return 1;
executed 121 times by 2 tests: return 1;
Executed by:
  • clienttest
  • ssltest
121
1021}-
1022-
1023int-
1024dtls1_retransmit_message(SSL *s, unsigned short seq, unsigned long frag_off,-
1025 int *found)-
1026{-
1027 int ret;-
1028 /* XDTLS: for now assuming that read/writes are blocking */-
1029 pitem *item;-
1030 hm_fragment *frag;-
1031 unsigned long header_length;-
1032 unsigned char seq64be[8];-
1033 struct dtls1_retransmit_state saved_state;-
1034 unsigned char save_write_sequence[8];-
1035-
1036 /*-
1037 OPENSSL_assert(s->internal->init_num == 0);-
1038 OPENSSL_assert(s->internal->init_off == 0);-
1039 */-
1040-
1041 /* XDTLS: the requested message ought to be found, otherwise error */-
1042 memset(seq64be, 0, sizeof(seq64be));-
1043 seq64be[6] = (unsigned char)(seq >> 8);-
1044 seq64be[7] = (unsigned char)seq;-
1045-
1046 item = pqueue_find(s->d1->sent_messages, seq64be);-
1047 if (item == NULL) {
item == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
1048#ifdef DEBUG-
1049 fprintf(stderr, "retransmit: message %d non-existant\n", seq);-
1050#endif-
1051 *found = 0;-
1052 return 0;
never executed: return 0;
0
1053 }-
1054-
1055 *found = 1;-
1056 frag = (hm_fragment *)item->data;-
1057-
1058 if (frag->msg_header.is_ccs)
frag->msg_header.is_ccsDescription
TRUEnever evaluated
FALSEnever evaluated
0
1059 header_length = DTLS1_CCS_HEADER_LENGTH;
never executed: header_length = 1;
0
1060 else-
1061 header_length = DTLS1_HM_HEADER_LENGTH;
never executed: header_length = 12;
0
1062-
1063 memcpy(s->internal->init_buf->data, frag->fragment,-
1064 frag->msg_header.msg_len + header_length);-
1065 s->internal->init_num = frag->msg_header.msg_len + header_length;-
1066-
1067 dtls1_set_message_header_int(s, frag->msg_header.type,-
1068 frag->msg_header.msg_len, frag->msg_header.seq, 0,-
1069 frag->msg_header.frag_len);-
1070-
1071 /* save current state */-
1072 saved_state.enc_write_ctx = s->internal->enc_write_ctx;-
1073 saved_state.write_hash = s->internal->write_hash;-
1074 saved_state.session = s->session;-
1075 saved_state.epoch = D1I(s)->w_epoch;-
1076-
1077 D1I(s)->retransmitting = 1;-
1078-
1079 /* restore state in which the message was originally sent */-
1080 s->internal->enc_write_ctx = frag->msg_header.saved_retransmit_state.enc_write_ctx;-
1081 s->internal->write_hash = frag->msg_header.saved_retransmit_state.write_hash;-
1082 s->session = frag->msg_header.saved_retransmit_state.session;-
1083 D1I(s)->w_epoch = frag->msg_header.saved_retransmit_state.epoch;-
1084-
1085 if (frag->msg_header.saved_retransmit_state.epoch ==
frag->msg_head...tate.epoch - 1Description
TRUEnever evaluated
FALSEnever evaluated
0
1086 saved_state.epoch - 1) {
frag->msg_head...tate.epoch - 1Description
TRUEnever evaluated
FALSEnever evaluated
0
1087 memcpy(save_write_sequence, S3I(s)->write_sequence,-
1088 sizeof(S3I(s)->write_sequence));-
1089 memcpy(S3I(s)->write_sequence, D1I(s)->last_write_sequence,-
1090 sizeof(S3I(s)->write_sequence));-
1091 }
never executed: end of block
0
1092-
1093 ret = dtls1_do_write(s, frag->msg_header.is_ccs ?-
1094 SSL3_RT_CHANGE_CIPHER_SPEC : SSL3_RT_HANDSHAKE);-
1095-
1096 /* restore current state */-
1097 s->internal->enc_write_ctx = saved_state.enc_write_ctx;-
1098 s->internal->write_hash = saved_state.write_hash;-
1099 s->session = saved_state.session;-
1100 D1I(s)->w_epoch = saved_state.epoch;-
1101-
1102 if (frag->msg_header.saved_retransmit_state.epoch ==
frag->msg_head...tate.epoch - 1Description
TRUEnever evaluated
FALSEnever evaluated
0
1103 saved_state.epoch - 1) {
frag->msg_head...tate.epoch - 1Description
TRUEnever evaluated
FALSEnever evaluated
0
1104 memcpy(D1I(s)->last_write_sequence, S3I(s)->write_sequence,-
1105 sizeof(S3I(s)->write_sequence));-
1106 memcpy(S3I(s)->write_sequence, save_write_sequence,-
1107 sizeof(S3I(s)->write_sequence));-
1108 }
never executed: end of block
0
1109-
1110 D1I(s)->retransmitting = 0;-
1111-
1112 (void)BIO_flush(SSL_get_wbio(s));-
1113 return ret;
never executed: return ret;
0
1114}-
1115-
1116/* call this function when the buffered messages are no longer needed */-
1117void-
1118dtls1_clear_record_buffer(SSL *s)-
1119{-
1120 pitem *item;-
1121-
1122 for(item = pqueue_pop(s->d1->sent_messages); item != NULL;
item != ((void *)0)Description
TRUEevaluated 87 times by 1 test
Evaluated by:
  • ssltest
FALSEevaluated 55 times by 1 test
Evaluated by:
  • ssltest
55-87
1123 item = pqueue_pop(s->d1->sent_messages)) {-
1124 dtls1_hm_fragment_free((hm_fragment *)item->data);-
1125 pitem_free(item);-
1126 }
executed 87 times by 1 test: end of block
Executed by:
  • ssltest
87
1127}
executed 55 times by 1 test: end of block
Executed by:
  • ssltest
55
1128-
1129void-
1130dtls1_set_message_header(SSL *s, unsigned char mt, unsigned long len,-
1131 unsigned long frag_off, unsigned long frag_len)-
1132{-
1133 /* Don't change sequence numbers while listening */-
1134 if (frag_off == 0 && !D1I(s)->listen) {
frag_off == 0Description
TRUEevaluated 99 times by 2 tests
Evaluated by:
  • clienttest
  • ssltest
FALSEnever evaluated
!(s->d1->internal)->listenDescription
TRUEevaluated 99 times by 2 tests
Evaluated by:
  • clienttest
  • ssltest
FALSEnever evaluated
0-99
1135 D1I(s)->handshake_write_seq = D1I(s)->next_handshake_write_seq;-
1136 D1I(s)->next_handshake_write_seq++;-
1137 }
executed 99 times by 2 tests: end of block
Executed by:
  • clienttest
  • ssltest
99
1138-
1139 dtls1_set_message_header_int(s, mt, len, D1I(s)->handshake_write_seq,-
1140 frag_off, frag_len);-
1141}
executed 99 times by 2 tests: end of block
Executed by:
  • clienttest
  • ssltest
99
1142-
1143/* don't actually do the writing, wait till the MTU has been retrieved */-
1144void-
1145dtls1_set_message_header_int(SSL *s, unsigned char mt, unsigned long len,-
1146 unsigned short seq_num, unsigned long frag_off, unsigned long frag_len)-
1147{-
1148 struct hm_header_st *msg_hdr = &D1I(s)->w_msg_hdr;-
1149-
1150 msg_hdr->type = mt;-
1151 msg_hdr->msg_len = len;-
1152 msg_hdr->seq = seq_num;-
1153 msg_hdr->frag_off = frag_off;-
1154 msg_hdr->frag_len = frag_len;-
1155}
executed 121 times by 2 tests: end of block
Executed by:
  • clienttest
  • ssltest
121
1156-
1157static void-
1158dtls1_fix_message_header(SSL *s, unsigned long frag_off, unsigned long frag_len)-
1159{-
1160 struct hm_header_st *msg_hdr = &D1I(s)->w_msg_hdr;-
1161-
1162 msg_hdr->frag_off = frag_off;-
1163 msg_hdr->frag_len = frag_len;-
1164}
executed 110 times by 2 tests: end of block
Executed by:
  • clienttest
  • ssltest
110
1165-
1166static int-
1167dtls1_write_message_header(const struct hm_header_st *msg_hdr,-
1168 unsigned long frag_off, unsigned long frag_len, unsigned char *p)-
1169{-
1170 CBB cbb;-
1171-
1172 /* We assume DTLS1_HM_HEADER_LENGTH bytes are available for now... */-
1173 if (!CBB_init_fixed(&cbb, p, DTLS1_HM_HEADER_LENGTH))
!CBB_init_fixed(&cbb, p, 12)Description
TRUEnever evaluated
FALSEevaluated 307 times by 2 tests
Evaluated by:
  • clienttest
  • ssltest
0-307
1174 return 0;
never executed: return 0;
0
1175 if (!CBB_add_u8(&cbb, msg_hdr->type))
!CBB_add_u8(&c...msg_hdr->type)Description
TRUEnever evaluated
FALSEevaluated 307 times by 2 tests
Evaluated by:
  • clienttest
  • ssltest
0-307
1176 goto err;
never executed: goto err;
0
1177 if (!CBB_add_u24(&cbb, msg_hdr->msg_len))
!CBB_add_u24(&..._hdr->msg_len)Description
TRUEnever evaluated
FALSEevaluated 307 times by 2 tests
Evaluated by:
  • clienttest
  • ssltest
0-307
1178 goto err;
never executed: goto err;
0
1179 if (!CBB_add_u16(&cbb, msg_hdr->seq))
!CBB_add_u16(&... msg_hdr->seq)Description
TRUEnever evaluated
FALSEevaluated 307 times by 2 tests
Evaluated by:
  • clienttest
  • ssltest
0-307
1180 goto err;
never executed: goto err;
0
1181 if (!CBB_add_u24(&cbb, frag_off))
!CBB_add_u24(&cbb, frag_off)Description
TRUEnever evaluated
FALSEevaluated 307 times by 2 tests
Evaluated by:
  • clienttest
  • ssltest
0-307
1182 goto err;
never executed: goto err;
0
1183 if (!CBB_add_u24(&cbb, frag_len))
!CBB_add_u24(&cbb, frag_len)Description
TRUEnever evaluated
FALSEevaluated 307 times by 2 tests
Evaluated by:
  • clienttest
  • ssltest
0-307
1184 goto err;
never executed: goto err;
0
1185 if (!CBB_finish(&cbb, NULL, NULL))
!CBB_finish(&c... ((void *)0) )Description
TRUEnever evaluated
FALSEevaluated 307 times by 2 tests
Evaluated by:
  • clienttest
  • ssltest
0-307
1186 goto err;
never executed: goto err;
0
1187-
1188 return 1;
executed 307 times by 2 tests: return 1;
Executed by:
  • clienttest
  • ssltest
307
1189-
1190 err:-
1191 CBB_cleanup(&cbb);-
1192 return 0;
never executed: return 0;
0
1193}-
1194-
1195unsigned int-
1196dtls1_min_mtu(void)-
1197{-
1198 return (g_probable_mtu[(sizeof(g_probable_mtu) /
executed 265 times by 2 tests: return (g_probable_mtu[(sizeof(g_probable_mtu) / sizeof(g_probable_mtu[0])) - 1]);
Executed by:
  • clienttest
  • ssltest
265
1199 sizeof(g_probable_mtu[0])) - 1]);
executed 265 times by 2 tests: return (g_probable_mtu[(sizeof(g_probable_mtu) / sizeof(g_probable_mtu[0])) - 1]);
Executed by:
  • clienttest
  • ssltest
265
1200}-
1201-
1202static unsigned int-
1203dtls1_guess_mtu(unsigned int curr_mtu)-
1204{-
1205 unsigned int i;-
1206-
1207 if (curr_mtu == 0)
curr_mtu == 0Description
TRUEevaluated 23 times by 2 tests
Evaluated by:
  • clienttest
  • ssltest
FALSEnever evaluated
0-23
1208 return g_probable_mtu[0];
executed 23 times by 2 tests: return g_probable_mtu[0];
Executed by:
  • clienttest
  • ssltest
23
1209-
1210 for (i = 0; i < sizeof(g_probable_mtu) / sizeof(g_probable_mtu[0]); i++)
i < sizeof(g_p...obable_mtu[0])Description
TRUEnever evaluated
FALSEnever evaluated
0
1211 if (curr_mtu > g_probable_mtu[i])
curr_mtu > g_probable_mtu[i]Description
TRUEnever evaluated
FALSEnever evaluated
0
1212 return g_probable_mtu[i];
never executed: return g_probable_mtu[i];
0
1213-
1214 return curr_mtu;
never executed: return curr_mtu;
0
1215}-
1216-
1217int-
1218dtls1_get_message_header(unsigned char *data, struct hm_header_st *msg_hdr)-
1219{-
1220 CBS header;-
1221 uint32_t msg_len, frag_off, frag_len;-
1222 uint16_t seq;-
1223 uint8_t type;-
1224-
1225 CBS_init(&header, data, sizeof(*msg_hdr));-
1226-
1227 memset(msg_hdr, 0, sizeof(*msg_hdr));-
1228-
1229 if (!CBS_get_u8(&header, &type))
!CBS_get_u8(&header, &type)Description
TRUEnever evaluated
FALSEevaluated 109 times by 1 test
Evaluated by:
  • ssltest
0-109
1230 return 0;
never executed: return 0;
0
1231 if (!CBS_get_u24(&header, &msg_len))
!CBS_get_u24(&...der, &msg_len)Description
TRUEnever evaluated
FALSEevaluated 109 times by 1 test
Evaluated by:
  • ssltest
0-109
1232 return 0;
never executed: return 0;
0
1233 if (!CBS_get_u16(&header, &seq))
!CBS_get_u16(&header, &seq)Description
TRUEnever evaluated
FALSEevaluated 109 times by 1 test
Evaluated by:
  • ssltest
0-109
1234 return 0;
never executed: return 0;
0
1235 if (!CBS_get_u24(&header, &frag_off))
!CBS_get_u24(&...er, &frag_off)Description
TRUEnever evaluated
FALSEevaluated 109 times by 1 test
Evaluated by:
  • ssltest
0-109
1236 return 0;
never executed: return 0;
0
1237 if (!CBS_get_u24(&header, &frag_len))
!CBS_get_u24(&...er, &frag_len)Description
TRUEnever evaluated
FALSEevaluated 109 times by 1 test
Evaluated by:
  • ssltest
0-109
1238 return 0;
never executed: return 0;
0
1239-
1240 msg_hdr->type = type;-
1241 msg_hdr->msg_len = msg_len;-
1242 msg_hdr->seq = seq;-
1243 msg_hdr->frag_off = frag_off;-
1244 msg_hdr->frag_len = frag_len;-
1245-
1246 return 1;
executed 109 times by 1 test: return 1;
Executed by:
  • ssltest
109
1247}-
1248-
1249void-
1250dtls1_get_ccs_header(unsigned char *data, struct ccs_header_st *ccs_hdr)-
1251{-
1252 memset(ccs_hdr, 0x00, sizeof(struct ccs_header_st));-
1253-
1254 ccs_hdr->type = *(data++);-
1255}
executed 22 times by 1 test: end of block
Executed by:
  • ssltest
22
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.2