Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/libressl/src/ssl/ssl_srvr.c |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /* $OpenBSD: ssl_srvr.c,v 1.48 2018/08/27 17:04:34 jsing Exp $ */ | - | ||||||||||||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | - | ||||||||||||
3 | * All rights reserved. | - | ||||||||||||
4 | * | - | ||||||||||||
5 | * This package is an SSL implementation written | - | ||||||||||||
6 | * by Eric Young (eay@cryptsoft.com). | - | ||||||||||||
7 | * The implementation was written so as to conform with Netscapes SSL. | - | ||||||||||||
8 | * | - | ||||||||||||
9 | * This library is free for commercial and non-commercial use as long as | - | ||||||||||||
10 | * the following conditions are aheared to. The following conditions | - | ||||||||||||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | - | ||||||||||||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | - | ||||||||||||
13 | * included with this distribution is covered by the same copyright terms | - | ||||||||||||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | - | ||||||||||||
15 | * | - | ||||||||||||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | - | ||||||||||||
17 | * the code are not to be removed. | - | ||||||||||||
18 | * If this package is used in a product, Eric Young should be given attribution | - | ||||||||||||
19 | * as the author of the parts of the library used. | - | ||||||||||||
20 | * This can be in the form of a textual message at program startup or | - | ||||||||||||
21 | * in documentation (online or textual) provided with the package. | - | ||||||||||||
22 | * | - | ||||||||||||
23 | * Redistribution and use in source and binary forms, with or without | - | ||||||||||||
24 | * modification, are permitted provided that the following conditions | - | ||||||||||||
25 | * are met: | - | ||||||||||||
26 | * 1. Redistributions of source code must retain the copyright | - | ||||||||||||
27 | * notice, this list of conditions and the following disclaimer. | - | ||||||||||||
28 | * 2. Redistributions in binary form must reproduce the above copyright | - | ||||||||||||
29 | * notice, this list of conditions and the following disclaimer in the | - | ||||||||||||
30 | * documentation and/or other materials provided with the distribution. | - | ||||||||||||
31 | * 3. All advertising materials mentioning features or use of this software | - | ||||||||||||
32 | * must display the following acknowledgement: | - | ||||||||||||
33 | * "This product includes cryptographic software written by | - | ||||||||||||
34 | * Eric Young (eay@cryptsoft.com)" | - | ||||||||||||
35 | * The word 'cryptographic' can be left out if the rouines from the library | - | ||||||||||||
36 | * being used are not cryptographic related :-). | - | ||||||||||||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | - | ||||||||||||
38 | * the apps directory (application code) you must include an acknowledgement: | - | ||||||||||||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | - | ||||||||||||
40 | * | - | ||||||||||||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | - | ||||||||||||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | - | ||||||||||||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | - | ||||||||||||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | - | ||||||||||||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | - | ||||||||||||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | - | ||||||||||||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | - | ||||||||||||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | - | ||||||||||||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | - | ||||||||||||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | - | ||||||||||||
51 | * SUCH DAMAGE. | - | ||||||||||||
52 | * | - | ||||||||||||
53 | * The licence and distribution terms for any publically available version or | - | ||||||||||||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | - | ||||||||||||
55 | * copied and put under another distribution licence | - | ||||||||||||
56 | * [including the GNU Public Licence.] | - | ||||||||||||
57 | */ | - | ||||||||||||
58 | /* ==================================================================== | - | ||||||||||||
59 | * Copyright (c) 1998-2007 The OpenSSL Project. All rights reserved. | - | ||||||||||||
60 | * | - | ||||||||||||
61 | * Redistribution and use in source and binary forms, with or without | - | ||||||||||||
62 | * modification, are permitted provided that the following conditions | - | ||||||||||||
63 | * are met: | - | ||||||||||||
64 | * | - | ||||||||||||
65 | * 1. Redistributions of source code must retain the above copyright | - | ||||||||||||
66 | * notice, this list of conditions and the following disclaimer. | - | ||||||||||||
67 | * | - | ||||||||||||
68 | * 2. Redistributions in binary form must reproduce the above copyright | - | ||||||||||||
69 | * notice, this list of conditions and the following disclaimer in | - | ||||||||||||
70 | * the documentation and/or other materials provided with the | - | ||||||||||||
71 | * distribution. | - | ||||||||||||
72 | * | - | ||||||||||||
73 | * 3. All advertising materials mentioning features or use of this | - | ||||||||||||
74 | * software must display the following acknowledgment: | - | ||||||||||||
75 | * "This product includes software developed by the OpenSSL Project | - | ||||||||||||
76 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | - | ||||||||||||
77 | * | - | ||||||||||||
78 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | - | ||||||||||||
79 | * endorse or promote products derived from this software without | - | ||||||||||||
80 | * prior written permission. For written permission, please contact | - | ||||||||||||
81 | * openssl-core@openssl.org. | - | ||||||||||||
82 | * | - | ||||||||||||
83 | * 5. Products derived from this software may not be called "OpenSSL" | - | ||||||||||||
84 | * nor may "OpenSSL" appear in their names without prior written | - | ||||||||||||
85 | * permission of the OpenSSL Project. | - | ||||||||||||
86 | * | - | ||||||||||||
87 | * 6. Redistributions of any form whatsoever must retain the following | - | ||||||||||||
88 | * acknowledgment: | - | ||||||||||||
89 | * "This product includes software developed by the OpenSSL Project | - | ||||||||||||
90 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | - | ||||||||||||
91 | * | - | ||||||||||||
92 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | - | ||||||||||||
93 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | - | ||||||||||||
94 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | - | ||||||||||||
95 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | - | ||||||||||||
96 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | - | ||||||||||||
97 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | - | ||||||||||||
98 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | - | ||||||||||||
99 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | - | ||||||||||||
100 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | - | ||||||||||||
101 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | - | ||||||||||||
102 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | - | ||||||||||||
103 | * OF THE POSSIBILITY OF SUCH DAMAGE. | - | ||||||||||||
104 | * ==================================================================== | - | ||||||||||||
105 | * | - | ||||||||||||
106 | * This product includes cryptographic software written by Eric Young | - | ||||||||||||
107 | * (eay@cryptsoft.com). This product includes software written by Tim | - | ||||||||||||
108 | * Hudson (tjh@cryptsoft.com). | - | ||||||||||||
109 | * | - | ||||||||||||
110 | */ | - | ||||||||||||
111 | /* ==================================================================== | - | ||||||||||||
112 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. | - | ||||||||||||
113 | * | - | ||||||||||||
114 | * Portions of the attached software ("Contribution") are developed by | - | ||||||||||||
115 | * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project. | - | ||||||||||||
116 | * | - | ||||||||||||
117 | * The Contribution is licensed pursuant to the OpenSSL open source | - | ||||||||||||
118 | * license provided above. | - | ||||||||||||
119 | * | - | ||||||||||||
120 | * ECC cipher suite support in OpenSSL originally written by | - | ||||||||||||
121 | * Vipul Gupta and Sumit Gupta of Sun Microsystems Laboratories. | - | ||||||||||||
122 | * | - | ||||||||||||
123 | */ | - | ||||||||||||
124 | /* ==================================================================== | - | ||||||||||||
125 | * Copyright 2005 Nokia. All rights reserved. | - | ||||||||||||
126 | * | - | ||||||||||||
127 | * The portions of the attached software ("Contribution") is developed by | - | ||||||||||||
128 | * Nokia Corporation and is licensed pursuant to the OpenSSL open source | - | ||||||||||||
129 | * license. | - | ||||||||||||
130 | * | - | ||||||||||||
131 | * The Contribution, originally written by Mika Kousa and Pasi Eronen of | - | ||||||||||||
132 | * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites | - | ||||||||||||
133 | * support (see RFC 4279) to OpenSSL. | - | ||||||||||||
134 | * | - | ||||||||||||
135 | * No patent licenses or other rights except those expressly stated in | - | ||||||||||||
136 | * the OpenSSL open source license shall be deemed granted or received | - | ||||||||||||
137 | * expressly, by implication, estoppel, or otherwise. | - | ||||||||||||
138 | * | - | ||||||||||||
139 | * No assurances are provided by Nokia that the Contribution does not | - | ||||||||||||
140 | * infringe the patent or other intellectual property rights of any third | - | ||||||||||||
141 | * party or that the license provides you with all the necessary rights | - | ||||||||||||
142 | * to make use of the Contribution. | - | ||||||||||||
143 | * | - | ||||||||||||
144 | * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN | - | ||||||||||||
145 | * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA | - | ||||||||||||
146 | * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY | - | ||||||||||||
147 | * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR | - | ||||||||||||
148 | * OTHERWISE. | - | ||||||||||||
149 | */ | - | ||||||||||||
150 | - | |||||||||||||
151 | #include <stdio.h> | - | ||||||||||||
152 | - | |||||||||||||
153 | #include "ssl_locl.h" | - | ||||||||||||
154 | - | |||||||||||||
155 | #include <openssl/bn.h> | - | ||||||||||||
156 | #include <openssl/buffer.h> | - | ||||||||||||
157 | #include <openssl/curve25519.h> | - | ||||||||||||
158 | #include <openssl/evp.h> | - | ||||||||||||
159 | #include <openssl/dh.h> | - | ||||||||||||
160 | #ifndef OPENSSL_NO_GOST | - | ||||||||||||
161 | #include <openssl/gost.h> | - | ||||||||||||
162 | #endif | - | ||||||||||||
163 | #include <openssl/hmac.h> | - | ||||||||||||
164 | #include <openssl/md5.h> | - | ||||||||||||
165 | #include <openssl/objects.h> | - | ||||||||||||
166 | #include <openssl/x509.h> | - | ||||||||||||
167 | - | |||||||||||||
168 | #include "bytestring.h" | - | ||||||||||||
169 | #include "ssl_tlsext.h" | - | ||||||||||||
170 | - | |||||||||||||
171 | int | - | ||||||||||||
172 | ssl3_accept(SSL *s) | - | ||||||||||||
173 | { | - | ||||||||||||
174 | void (*cb)(const SSL *ssl, int type, int val) = NULL; | - | ||||||||||||
175 | unsigned long alg_k; | - | ||||||||||||
176 | int ret = -1; | - | ||||||||||||
177 | int new_state, state, skip = 0; | - | ||||||||||||
178 | int listen = 0; | - | ||||||||||||
179 | - | |||||||||||||
180 | ERR_clear_error(); | - | ||||||||||||
181 | errno = 0; | - | ||||||||||||
182 | - | |||||||||||||
183 | if (s->internal->info_callback != NULL)
| 0-1236 | ||||||||||||
184 | cb = s->internal->info_callback; never executed: cb = s->internal->info_callback; | 0 | ||||||||||||
185 | else if (s->ctx->internal->info_callback != NULL)
| 0-1236 | ||||||||||||
186 | cb = s->ctx->internal->info_callback; never executed: cb = s->ctx->internal->info_callback; | 0 | ||||||||||||
187 | - | |||||||||||||
188 | if (SSL_IS_DTLS(s))
| 22-1214 | ||||||||||||
189 | listen = D1I(s)->listen; executed 22 times by 1 test: listen = (s->d1->internal)->listen; Executed by:
| 22 | ||||||||||||
190 | - | |||||||||||||
191 | /* init things to blank */ | - | ||||||||||||
192 | s->internal->in_handshake++; | - | ||||||||||||
193 | if (!SSL_in_init(s) || SSL_in_before(s))
| 0-1236 | ||||||||||||
194 | SSL_clear(s); executed 65 times by 3 tests: SSL_clear(s); Executed by:
| 65 | ||||||||||||
195 | - | |||||||||||||
196 | if (SSL_IS_DTLS(s))
| 22-1214 | ||||||||||||
197 | D1I(s)->listen = listen; executed 22 times by 1 test: (s->d1->internal)->listen = listen; Executed by:
| 22 | ||||||||||||
198 | - | |||||||||||||
199 | if (s->cert == NULL) {
| 0-1236 | ||||||||||||
200 | SSLerror(s, SSL_R_NO_CERTIFICATE_SET); | - | ||||||||||||
201 | ret = -1; | - | ||||||||||||
202 | goto end; never executed: goto end; | 0 | ||||||||||||
203 | } | - | ||||||||||||
204 | - | |||||||||||||
205 | for (;;) { | - | ||||||||||||
206 | state = S3I(s)->hs.state; | - | ||||||||||||
207 | - | |||||||||||||
208 | switch (S3I(s)->hs.state) { | - | ||||||||||||
209 | case SSL_ST_RENEGOTIATE: never executed: case (0x04|(0x1000|0x2000)): | 0 | ||||||||||||
210 | s->internal->renegotiate = 1; | - | ||||||||||||
211 | /* S3I(s)->hs.state=SSL_ST_ACCEPT; */ | - | ||||||||||||
212 | - | |||||||||||||
213 | case SSL_ST_BEFORE: code before this statement never executed: case 0x4000: never executed: case 0x4000: | 0 | ||||||||||||
214 | case SSL_ST_ACCEPT: never executed: case 0x2000: | 0 | ||||||||||||
215 | case SSL_ST_BEFORE|SSL_ST_ACCEPT: executed 65 times by 3 tests: case 0x4000|0x2000: Executed by:
| 65 | ||||||||||||
216 | case SSL_ST_OK|SSL_ST_ACCEPT: never executed: case 0x03|0x2000: | 0 | ||||||||||||
217 | s->server = 1; | - | ||||||||||||
218 | if (cb != NULL)
| 0-65 | ||||||||||||
219 | cb(s, SSL_CB_HANDSHAKE_START, 1); never executed: cb(s, 0x10, 1); | 0 | ||||||||||||
220 | - | |||||||||||||
221 | if (SSL_IS_DTLS(s)) {
| 11-54 | ||||||||||||
222 | if ((s->version & 0xff00) != (DTLS1_VERSION & 0xff00)) {
| 0-11 | ||||||||||||
223 | SSLerror(s, ERR_R_INTERNAL_ERROR); | - | ||||||||||||
224 | ret = -1; | - | ||||||||||||
225 | goto end; never executed: goto end; | 0 | ||||||||||||
226 | } | - | ||||||||||||
227 | } else { executed 11 times by 1 test: end of block Executed by:
| 11 | ||||||||||||
228 | if ((s->version >> 8) != 3) {
| 0-54 | ||||||||||||
229 | SSLerror(s, ERR_R_INTERNAL_ERROR); | - | ||||||||||||
230 | ret = -1; | - | ||||||||||||
231 | goto end; never executed: goto end; | 0 | ||||||||||||
232 | } | - | ||||||||||||
233 | } executed 54 times by 3 tests: end of block Executed by:
| 54 | ||||||||||||
234 | s->internal->type = SSL_ST_ACCEPT; | - | ||||||||||||
235 | - | |||||||||||||
236 | if (!ssl3_setup_init_buffer(s)) {
| 0-65 | ||||||||||||
237 | ret = -1; | - | ||||||||||||
238 | goto end; never executed: goto end; | 0 | ||||||||||||
239 | } | - | ||||||||||||
240 | if (!ssl3_setup_buffers(s)) {
| 0-65 | ||||||||||||
241 | ret = -1; | - | ||||||||||||
242 | goto end; never executed: goto end; | 0 | ||||||||||||
243 | } | - | ||||||||||||
244 | - | |||||||||||||
245 | s->internal->init_num = 0; | - | ||||||||||||
246 | - | |||||||||||||
247 | if (S3I(s)->hs.state != SSL_ST_RENEGOTIATE) {
| 0-65 | ||||||||||||
248 | /* | - | ||||||||||||
249 | * Ok, we now need to push on a buffering BIO | - | ||||||||||||
250 | * so that the output is sent in a way that | - | ||||||||||||
251 | * TCP likes :-) | - | ||||||||||||
252 | */ | - | ||||||||||||
253 | if (!ssl_init_wbio_buffer(s, 1)) {
| 0-65 | ||||||||||||
254 | ret = -1; | - | ||||||||||||
255 | goto end; never executed: goto end; | 0 | ||||||||||||
256 | } | - | ||||||||||||
257 | if (!tls1_init_finished_mac(s)) {
| 0-65 | ||||||||||||
258 | ret = -1; | - | ||||||||||||
259 | goto end; never executed: goto end; | 0 | ||||||||||||
260 | } | - | ||||||||||||
261 | - | |||||||||||||
262 | S3I(s)->hs.state = SSL3_ST_SR_CLNT_HELLO_A; | - | ||||||||||||
263 | s->ctx->internal->stats.sess_accept++; | - | ||||||||||||
264 | } else if (!SSL_IS_DTLS(s) && !S3I(s)->send_connection_binding) { executed 65 times by 3 tests: end of block Executed by:
| 0-65 | ||||||||||||
265 | /* | - | ||||||||||||
266 | * Server attempting to renegotiate with | - | ||||||||||||
267 | * client that doesn't support secure | - | ||||||||||||
268 | * renegotiation. | - | ||||||||||||
269 | */ | - | ||||||||||||
270 | SSLerror(s, SSL_R_UNSAFE_LEGACY_RENEGOTIATION_DISABLED); | - | ||||||||||||
271 | ssl3_send_alert(s, SSL3_AL_FATAL, | - | ||||||||||||
272 | SSL_AD_HANDSHAKE_FAILURE); | - | ||||||||||||
273 | ret = -1; | - | ||||||||||||
274 | goto end; never executed: goto end; | 0 | ||||||||||||
275 | } else { | - | ||||||||||||
276 | /* | - | ||||||||||||
277 | * S3I(s)->hs.state == SSL_ST_RENEGOTIATE, | - | ||||||||||||
278 | * we will just send a HelloRequest. | - | ||||||||||||
279 | */ | - | ||||||||||||
280 | s->ctx->internal->stats.sess_accept_renegotiate++; | - | ||||||||||||
281 | S3I(s)->hs.state = SSL3_ST_SW_HELLO_REQ_A; | - | ||||||||||||
282 | } never executed: end of block | 0 | ||||||||||||
283 | break; executed 65 times by 3 tests: break; Executed by:
| 65 | ||||||||||||
284 | - | |||||||||||||
285 | case SSL3_ST_SW_HELLO_REQ_A: never executed: case (0x120|0x2000): | 0 | ||||||||||||
286 | case SSL3_ST_SW_HELLO_REQ_B: never executed: case (0x121|0x2000): | 0 | ||||||||||||
287 | s->internal->shutdown = 0; | - | ||||||||||||
288 | if (SSL_IS_DTLS(s)) {
| 0 | ||||||||||||
289 | dtls1_clear_record_buffer(s); | - | ||||||||||||
290 | dtls1_start_timer(s); | - | ||||||||||||
291 | } never executed: end of block | 0 | ||||||||||||
292 | ret = ssl3_send_hello_request(s); | - | ||||||||||||
293 | if (ret <= 0)
| 0 | ||||||||||||
294 | goto end; never executed: goto end; | 0 | ||||||||||||
295 | if (SSL_IS_DTLS(s))
| 0 | ||||||||||||
296 | S3I(s)->hs.next_state = SSL3_ST_SR_CLNT_HELLO_A; never executed: (s->s3->internal)->hs.next_state = (0x110|0x2000); | 0 | ||||||||||||
297 | else | - | ||||||||||||
298 | S3I(s)->hs.next_state = SSL3_ST_SW_HELLO_REQ_C; never executed: (s->s3->internal)->hs.next_state = (0x122|0x2000); | 0 | ||||||||||||
299 | S3I(s)->hs.state = SSL3_ST_SW_FLUSH; | - | ||||||||||||
300 | s->internal->init_num = 0; | - | ||||||||||||
301 | - | |||||||||||||
302 | if (!tls1_init_finished_mac(s)) {
| 0 | ||||||||||||
303 | ret = -1; | - | ||||||||||||
304 | goto end; never executed: goto end; | 0 | ||||||||||||
305 | } | - | ||||||||||||
306 | break; never executed: break; | 0 | ||||||||||||
307 | - | |||||||||||||
308 | case SSL3_ST_SW_HELLO_REQ_C: never executed: case (0x122|0x2000): | 0 | ||||||||||||
309 | S3I(s)->hs.state = SSL_ST_OK; | - | ||||||||||||
310 | break; never executed: break; | 0 | ||||||||||||
311 | - | |||||||||||||
312 | case SSL3_ST_SR_CLNT_HELLO_A: executed 65 times by 3 tests: case (0x110|0x2000): Executed by:
| 65 | ||||||||||||
313 | case SSL3_ST_SR_CLNT_HELLO_B: executed 192 times by 1 test: case (0x111|0x2000): Executed by:
| 192 | ||||||||||||
314 | case SSL3_ST_SR_CLNT_HELLO_C: never executed: case (0x112|0x2000): | 0 | ||||||||||||
315 | s->internal->shutdown = 0; | - | ||||||||||||
316 | if (SSL_IS_DTLS(s)) {
| 11-246 | ||||||||||||
317 | ret = ssl3_get_client_hello(s); | - | ||||||||||||
318 | if (ret <= 0)
| 0-11 | ||||||||||||
319 | goto end; never executed: goto end; | 0 | ||||||||||||
320 | dtls1_stop_timer(s); | - | ||||||||||||
321 | - | |||||||||||||
322 | if (ret == 1 &&
| 0-11 | ||||||||||||
323 | (SSL_get_options(s) & SSL_OP_COOKIE_EXCHANGE))
| 0-11 | ||||||||||||
324 | S3I(s)->hs.state = DTLS1_ST_SW_HELLO_VERIFY_REQUEST_A; never executed: (s->s3->internal)->hs.state = (0x113|0x2000); | 0 | ||||||||||||
325 | else | - | ||||||||||||
326 | S3I(s)->hs.state = SSL3_ST_SW_SRVR_HELLO_A; executed 11 times by 1 test: (s->s3->internal)->hs.state = (0x130|0x2000); Executed by:
| 11 | ||||||||||||
327 | - | |||||||||||||
328 | s->internal->init_num = 0; | - | ||||||||||||
329 | - | |||||||||||||
330 | /* | - | ||||||||||||
331 | * Reflect ClientHello sequence to remain | - | ||||||||||||
332 | * stateless while listening. | - | ||||||||||||
333 | */ | - | ||||||||||||
334 | if (listen) {
| 0-11 | ||||||||||||
335 | memcpy(S3I(s)->write_sequence, | - | ||||||||||||
336 | S3I(s)->read_sequence, | - | ||||||||||||
337 | sizeof(S3I(s)->write_sequence)); | - | ||||||||||||
338 | } never executed: end of block | 0 | ||||||||||||
339 | - | |||||||||||||
340 | /* If we're just listening, stop here */ | - | ||||||||||||
341 | if (listen && S3I(s)->hs.state == SSL3_ST_SW_SRVR_HELLO_A) {
| 0-11 | ||||||||||||
342 | ret = 2; | - | ||||||||||||
343 | D1I(s)->listen = 0; | - | ||||||||||||
344 | /* | - | ||||||||||||
345 | * Set expected sequence numbers to | - | ||||||||||||
346 | * continue the handshake. | - | ||||||||||||
347 | */ | - | ||||||||||||
348 | D1I(s)->handshake_read_seq = 2; | - | ||||||||||||
349 | D1I(s)->handshake_write_seq = 1; | - | ||||||||||||
350 | D1I(s)->next_handshake_write_seq = 1; | - | ||||||||||||
351 | goto end; never executed: goto end; | 0 | ||||||||||||
352 | } | - | ||||||||||||
353 | } else { executed 11 times by 1 test: end of block Executed by:
| 11 | ||||||||||||
354 | if (s->internal->rwstate != SSL_X509_LOOKUP) {
| 0-246 | ||||||||||||
355 | ret = ssl3_get_client_hello(s); | - | ||||||||||||
356 | if (ret <= 0)
| 54-192 | ||||||||||||
357 | goto end; executed 192 times by 1 test: goto end; Executed by:
| 192 | ||||||||||||
358 | } executed 54 times by 3 tests: end of block Executed by:
| 54 | ||||||||||||
359 | - | |||||||||||||
360 | s->internal->renegotiate = 2; | - | ||||||||||||
361 | S3I(s)->hs.state = SSL3_ST_SW_SRVR_HELLO_A; | - | ||||||||||||
362 | s->internal->init_num = 0; | - | ||||||||||||
363 | } executed 54 times by 3 tests: end of block Executed by:
| 54 | ||||||||||||
364 | break; executed 65 times by 3 tests: break; Executed by:
| 65 | ||||||||||||
365 | - | |||||||||||||
366 | case DTLS1_ST_SW_HELLO_VERIFY_REQUEST_A: never executed: case (0x113|0x2000): | 0 | ||||||||||||
367 | case DTLS1_ST_SW_HELLO_VERIFY_REQUEST_B: never executed: case (0x114|0x2000): | 0 | ||||||||||||
368 | ret = dtls1_send_hello_verify_request(s); | - | ||||||||||||
369 | if (ret <= 0)
| 0 | ||||||||||||
370 | goto end; never executed: goto end; | 0 | ||||||||||||
371 | S3I(s)->hs.state = SSL3_ST_SW_FLUSH; | - | ||||||||||||
372 | S3I(s)->hs.next_state = SSL3_ST_SR_CLNT_HELLO_A; | - | ||||||||||||
373 | - | |||||||||||||
374 | /* HelloVerifyRequest resets Finished MAC. */ | - | ||||||||||||
375 | if (!tls1_init_finished_mac(s)) {
| 0 | ||||||||||||
376 | ret = -1; | - | ||||||||||||
377 | goto end; never executed: goto end; | 0 | ||||||||||||
378 | } | - | ||||||||||||
379 | break; never executed: break; | 0 | ||||||||||||
380 | - | |||||||||||||
381 | case SSL3_ST_SW_SRVR_HELLO_A: executed 65 times by 3 tests: case (0x130|0x2000): Executed by:
| 65 | ||||||||||||
382 | case SSL3_ST_SW_SRVR_HELLO_B: never executed: case (0x131|0x2000): | 0 | ||||||||||||
383 | if (SSL_IS_DTLS(s)) {
| 11-54 | ||||||||||||
384 | s->internal->renegotiate = 2; | - | ||||||||||||
385 | dtls1_start_timer(s); | - | ||||||||||||
386 | } executed 11 times by 1 test: end of block Executed by:
| 11 | ||||||||||||
387 | ret = ssl3_send_server_hello(s); | - | ||||||||||||
388 | if (ret <= 0)
| 0-65 | ||||||||||||
389 | goto end; never executed: goto end; | 0 | ||||||||||||
390 | if (s->internal->hit) {
| 0-65 | ||||||||||||
391 | if (s->internal->tlsext_ticket_expected)
| 0 | ||||||||||||
392 | S3I(s)->hs.state = SSL3_ST_SW_SESSION_TICKET_A; never executed: (s->s3->internal)->hs.state = (0x1F0|0x2000); | 0 | ||||||||||||
393 | else | - | ||||||||||||
394 | S3I(s)->hs.state = SSL3_ST_SW_CHANGE_A; never executed: (s->s3->internal)->hs.state = (0x1D0|0x2000); | 0 | ||||||||||||
395 | } else { | - | ||||||||||||
396 | S3I(s)->hs.state = SSL3_ST_SW_CERT_A; | - | ||||||||||||
397 | } executed 65 times by 3 tests: end of block Executed by:
| 65 | ||||||||||||
398 | s->internal->init_num = 0; | - | ||||||||||||
399 | break; executed 65 times by 3 tests: break; Executed by:
| 65 | ||||||||||||
400 | - | |||||||||||||
401 | case SSL3_ST_SW_CERT_A: executed 65 times by 3 tests: case (0x140|0x2000): Executed by:
| 65 | ||||||||||||
402 | case SSL3_ST_SW_CERT_B: never executed: case (0x141|0x2000): | 0 | ||||||||||||
403 | /* Check if it is anon DH or anon ECDH. */ | - | ||||||||||||
404 | if (!(S3I(s)->hs.new_cipher->algorithm_auth &
| 10-55 | ||||||||||||
405 | SSL_aNULL)) {
| 10-55 | ||||||||||||
406 | if (SSL_IS_DTLS(s))
| 11-44 | ||||||||||||
407 | dtls1_start_timer(s); executed 11 times by 1 test: dtls1_start_timer(s); Executed by:
| 11 | ||||||||||||
408 | ret = ssl3_send_server_certificate(s); | - | ||||||||||||
409 | if (ret <= 0)
| 0-55 | ||||||||||||
410 | goto end; never executed: goto end; | 0 | ||||||||||||
411 | if (s->internal->tlsext_status_expected)
| 0-55 | ||||||||||||
412 | S3I(s)->hs.state = SSL3_ST_SW_CERT_STATUS_A; never executed: (s->s3->internal)->hs.state = (0x200|0x2000); | 0 | ||||||||||||
413 | else | - | ||||||||||||
414 | S3I(s)->hs.state = SSL3_ST_SW_KEY_EXCH_A; executed 55 times by 3 tests: (s->s3->internal)->hs.state = (0x150|0x2000); Executed by:
| 55 | ||||||||||||
415 | } else { | - | ||||||||||||
416 | skip = 1; | - | ||||||||||||
417 | S3I(s)->hs.state = SSL3_ST_SW_KEY_EXCH_A; | - | ||||||||||||
418 | } executed 10 times by 1 test: end of block Executed by:
| 10 | ||||||||||||
419 | s->internal->init_num = 0; | - | ||||||||||||
420 | break; executed 65 times by 3 tests: break; Executed by:
| 65 | ||||||||||||
421 | - | |||||||||||||
422 | case SSL3_ST_SW_KEY_EXCH_A: executed 65 times by 3 tests: case (0x150|0x2000): Executed by:
| 65 | ||||||||||||
423 | case SSL3_ST_SW_KEY_EXCH_B: never executed: case (0x151|0x2000): | 0 | ||||||||||||
424 | alg_k = S3I(s)->hs.new_cipher->algorithm_mkey; | - | ||||||||||||
425 | - | |||||||||||||
426 | /* | - | ||||||||||||
427 | * Only send if using a DH key exchange. | - | ||||||||||||
428 | * | - | ||||||||||||
429 | * For ECC ciphersuites, we send a ServerKeyExchange | - | ||||||||||||
430 | * message only if the cipher suite is ECDHE. In other | - | ||||||||||||
431 | * cases, the server certificate contains the server's | - | ||||||||||||
432 | * public key for key exchange. | - | ||||||||||||
433 | */ | - | ||||||||||||
434 | if (alg_k & (SSL_kDHE|SSL_kECDHE)) {
| 14-51 | ||||||||||||
435 | if (SSL_IS_DTLS(s))
| 4-47 | ||||||||||||
436 | dtls1_start_timer(s); executed 4 times by 1 test: dtls1_start_timer(s); Executed by:
| 4 | ||||||||||||
437 | ret = ssl3_send_server_key_exchange(s); | - | ||||||||||||
438 | if (ret <= 0)
| 0-51 | ||||||||||||
439 | goto end; never executed: goto end; | 0 | ||||||||||||
440 | } else executed 51 times by 3 tests: end of block Executed by:
| 51 | ||||||||||||
441 | skip = 1; executed 14 times by 1 test: skip = 1; Executed by:
| 14 | ||||||||||||
442 | - | |||||||||||||
443 | S3I(s)->hs.state = SSL3_ST_SW_CERT_REQ_A; | - | ||||||||||||
444 | s->internal->init_num = 0; | - | ||||||||||||
445 | break; executed 65 times by 3 tests: break; Executed by:
| 65 | ||||||||||||
446 | - | |||||||||||||
447 | case SSL3_ST_SW_CERT_REQ_A: executed 65 times by 3 tests: case (0x160|0x2000): Executed by:
| 65 | ||||||||||||
448 | case SSL3_ST_SW_CERT_REQ_B: never executed: case (0x161|0x2000): | 0 | ||||||||||||
449 | /* | - | ||||||||||||
450 | * Determine whether or not we need to request a | - | ||||||||||||
451 | * certificate. | - | ||||||||||||
452 | * | - | ||||||||||||
453 | * Do not request a certificate if: | - | ||||||||||||
454 | * | - | ||||||||||||
455 | * - We did not ask for it (SSL_VERIFY_PEER is unset). | - | ||||||||||||
456 | * | - | ||||||||||||
457 | * - SSL_VERIFY_CLIENT_ONCE is set and we are | - | ||||||||||||
458 | * renegotiating. | - | ||||||||||||
459 | * | - | ||||||||||||
460 | * - We are using an anonymous ciphersuites | - | ||||||||||||
461 | * (see section "Certificate request" in SSL 3 drafts | - | ||||||||||||
462 | * and in RFC 2246) ... except when the application | - | ||||||||||||
463 | * insists on verification (against the specs, but | - | ||||||||||||
464 | * s3_clnt.c accepts this for SSL 3). | - | ||||||||||||
465 | */ | - | ||||||||||||
466 | if (!(s->verify_mode & SSL_VERIFY_PEER) ||
| 7-58 | ||||||||||||
467 | ((s->session->peer != NULL) &&
| 0-7 | ||||||||||||
468 | (s->verify_mode & SSL_VERIFY_CLIENT_ONCE)) ||
| 0 | ||||||||||||
469 | ((S3I(s)->hs.new_cipher->algorithm_auth &
| 0-7 | ||||||||||||
470 | SSL_aNULL) && !(s->verify_mode &
| 0-7 | ||||||||||||
471 | SSL_VERIFY_FAIL_IF_NO_PEER_CERT))) {
| 0 | ||||||||||||
472 | /* No cert request. */ | - | ||||||||||||
473 | skip = 1; | - | ||||||||||||
474 | S3I(s)->tmp.cert_request = 0; | - | ||||||||||||
475 | S3I(s)->hs.state = SSL3_ST_SW_SRVR_DONE_A; | - | ||||||||||||
476 | if (!SSL_IS_DTLS(s) && S3I(s)->handshake_buffer) {
| 0-49 | ||||||||||||
477 | if (!tls1_digest_cached_records(s)) {
| 0 | ||||||||||||
478 | ret = -1; | - | ||||||||||||
479 | goto end; never executed: goto end; | 0 | ||||||||||||
480 | } | - | ||||||||||||
481 | } never executed: end of block | 0 | ||||||||||||
482 | } else { executed 58 times by 3 tests: end of block Executed by:
| 58 | ||||||||||||
483 | S3I(s)->tmp.cert_request = 1; | - | ||||||||||||
484 | if (SSL_IS_DTLS(s))
| 2-5 | ||||||||||||
485 | dtls1_start_timer(s); executed 2 times by 1 test: dtls1_start_timer(s); Executed by:
| 2 | ||||||||||||
486 | ret = ssl3_send_certificate_request(s); | - | ||||||||||||
487 | if (ret <= 0)
| 0-7 | ||||||||||||
488 | goto end; never executed: goto end; | 0 | ||||||||||||
489 | S3I(s)->hs.state = SSL3_ST_SW_SRVR_DONE_A; | - | ||||||||||||
490 | s->internal->init_num = 0; | - | ||||||||||||
491 | } executed 7 times by 1 test: end of block Executed by:
| 7 | ||||||||||||
492 | break; executed 65 times by 3 tests: break; Executed by:
| 65 | ||||||||||||
493 | - | |||||||||||||
494 | case SSL3_ST_SW_SRVR_DONE_A: executed 65 times by 3 tests: case (0x170|0x2000): Executed by:
| 65 | ||||||||||||
495 | case SSL3_ST_SW_SRVR_DONE_B: never executed: case (0x171|0x2000): | 0 | ||||||||||||
496 | if (SSL_IS_DTLS(s))
| 11-54 | ||||||||||||
497 | dtls1_start_timer(s); executed 11 times by 1 test: dtls1_start_timer(s); Executed by:
| 11 | ||||||||||||
498 | ret = ssl3_send_server_done(s); | - | ||||||||||||
499 | if (ret <= 0)
| 0-65 | ||||||||||||
500 | goto end; never executed: goto end; | 0 | ||||||||||||
501 | S3I(s)->hs.next_state = SSL3_ST_SR_CERT_A; | - | ||||||||||||
502 | S3I(s)->hs.state = SSL3_ST_SW_FLUSH; | - | ||||||||||||
503 | s->internal->init_num = 0; | - | ||||||||||||
504 | break; executed 65 times by 3 tests: break; Executed by:
| 65 | ||||||||||||
505 | - | |||||||||||||
506 | case SSL3_ST_SW_FLUSH: executed 372 times by 3 tests: case (0x100|0x2000): Executed by:
| 372 | ||||||||||||
507 | /* | - | ||||||||||||
508 | * This code originally checked to see if | - | ||||||||||||
509 | * any data was pending using BIO_CTRL_INFO | - | ||||||||||||
510 | * and then flushed. This caused problems | - | ||||||||||||
511 | * as documented in PR#1939. The proposed | - | ||||||||||||
512 | * fix doesn't completely resolve this issue | - | ||||||||||||
513 | * as buggy implementations of BIO_CTRL_PENDING | - | ||||||||||||
514 | * still exist. So instead we just flush | - | ||||||||||||
515 | * unconditionally. | - | ||||||||||||
516 | */ | - | ||||||||||||
517 | s->internal->rwstate = SSL_WRITING; | - | ||||||||||||
518 | if (BIO_flush(s->wbio) <= 0) {
| 128-244 | ||||||||||||
519 | if (SSL_IS_DTLS(s)) {
| 0-244 | ||||||||||||
520 | /* If the write error was fatal, stop trying. */ | - | ||||||||||||
521 | if (!BIO_should_retry(s->wbio)) {
| 0 | ||||||||||||
522 | s->internal->rwstate = SSL_NOTHING; | - | ||||||||||||
523 | S3I(s)->hs.state = S3I(s)->hs.next_state; | - | ||||||||||||
524 | } never executed: end of block | 0 | ||||||||||||
525 | } never executed: end of block | 0 | ||||||||||||
526 | ret = -1; | - | ||||||||||||
527 | goto end; executed 244 times by 2 tests: goto end; Executed by:
| 244 | ||||||||||||
528 | } | - | ||||||||||||
529 | s->internal->rwstate = SSL_NOTHING; | - | ||||||||||||
530 | S3I(s)->hs.state = S3I(s)->hs.next_state; | - | ||||||||||||
531 | break; executed 128 times by 3 tests: break; Executed by:
| 128 | ||||||||||||
532 | - | |||||||||||||
533 | case SSL3_ST_SR_CERT_A: executed 165 times by 3 tests: case (0x180|0x2000): Executed by:
| 165 | ||||||||||||
534 | case SSL3_ST_SR_CERT_B: never executed: case (0x181|0x2000): | 0 | ||||||||||||
535 | if (S3I(s)->tmp.cert_request) {
| 58-107 | ||||||||||||
536 | ret = ssl3_get_client_certificate(s); | - | ||||||||||||
537 | if (ret <= 0)
| 7-100 | ||||||||||||
538 | goto end; executed 100 times by 1 test: goto end; Executed by:
| 100 | ||||||||||||
539 | } executed 7 times by 1 test: end of block Executed by:
| 7 | ||||||||||||
540 | s->internal->init_num = 0; | - | ||||||||||||
541 | S3I(s)->hs.state = SSL3_ST_SR_KEY_EXCH_A; | - | ||||||||||||
542 | break; executed 65 times by 3 tests: break; Executed by:
| 65 | ||||||||||||
543 | - | |||||||||||||
544 | case SSL3_ST_SR_KEY_EXCH_A: executed 334 times by 3 tests: case (0x190|0x2000): Executed by:
| 334 | ||||||||||||
545 | case SSL3_ST_SR_KEY_EXCH_B: never executed: case (0x191|0x2000): | 0 | ||||||||||||
546 | ret = ssl3_get_client_key_exchange(s); | - | ||||||||||||
547 | if (ret <= 0)
| 63-271 | ||||||||||||
548 | goto end; executed 271 times by 3 tests: goto end; Executed by:
| 271 | ||||||||||||
549 | - | |||||||||||||
550 | if (SSL_IS_DTLS(s)) {
| 11-52 | ||||||||||||
551 | S3I(s)->hs.state = SSL3_ST_SR_CERT_VRFY_A; | - | ||||||||||||
552 | s->internal->init_num = 0; | - | ||||||||||||
553 | } executed 11 times by 1 test: end of block Executed by:
| 11 | ||||||||||||
554 | - | |||||||||||||
555 | alg_k = S3I(s)->hs.new_cipher->algorithm_mkey; | - | ||||||||||||
556 | if (ret == 2) {
| 0-63 | ||||||||||||
557 | /* | - | ||||||||||||
558 | * For the ECDH ciphersuites when | - | ||||||||||||
559 | * the client sends its ECDH pub key in | - | ||||||||||||
560 | * a certificate, the CertificateVerify | - | ||||||||||||
561 | * message is not sent. | - | ||||||||||||
562 | * Also for GOST ciphersuites when | - | ||||||||||||
563 | * the client uses its key from the certificate | - | ||||||||||||
564 | * for key exchange. | - | ||||||||||||
565 | */ | - | ||||||||||||
566 | S3I(s)->hs.state = SSL3_ST_SR_FINISHED_A; | - | ||||||||||||
567 | s->internal->init_num = 0; | - | ||||||||||||
568 | } else if (SSL_USE_SIGALGS(s) || (alg_k & SSL_kGOST)) { never executed: end of block
| 0-34 | ||||||||||||
569 | S3I(s)->hs.state = SSL3_ST_SR_CERT_VRFY_A; | - | ||||||||||||
570 | s->internal->init_num = 0; | - | ||||||||||||
571 | if (!s->session->peer)
| 5-29 | ||||||||||||
572 | break; executed 29 times by 2 tests: break; Executed by:
| 29 | ||||||||||||
573 | /* | - | ||||||||||||
574 | * For sigalgs freeze the handshake buffer | - | ||||||||||||
575 | * at this point and digest cached records. | - | ||||||||||||
576 | */ | - | ||||||||||||
577 | if (!S3I(s)->handshake_buffer) {
| 0-5 | ||||||||||||
578 | SSLerror(s, ERR_R_INTERNAL_ERROR); | - | ||||||||||||
579 | ret = -1; | - | ||||||||||||
580 | goto end; never executed: goto end; | 0 | ||||||||||||
581 | } | - | ||||||||||||
582 | s->s3->flags |= TLS1_FLAGS_KEEP_HANDSHAKE; | - | ||||||||||||
583 | if (!tls1_digest_cached_records(s)) {
| 0-5 | ||||||||||||
584 | ret = -1; | - | ||||||||||||
585 | goto end; never executed: goto end; | 0 | ||||||||||||
586 | } | - | ||||||||||||
587 | } else { executed 5 times by 1 test: end of block Executed by:
| 5 | ||||||||||||
588 | S3I(s)->hs.state = SSL3_ST_SR_CERT_VRFY_A; | - | ||||||||||||
589 | s->internal->init_num = 0; | - | ||||||||||||
590 | - | |||||||||||||
591 | /* | - | ||||||||||||
592 | * We need to get hashes here so if there is | - | ||||||||||||
593 | * a client cert, it can be verified. | - | ||||||||||||
594 | */ | - | ||||||||||||
595 | if (S3I(s)->handshake_buffer) {
| 0-29 | ||||||||||||
596 | if (!tls1_digest_cached_records(s)) {
| 0 | ||||||||||||
597 | ret = -1; | - | ||||||||||||
598 | goto end; never executed: goto end; | 0 | ||||||||||||
599 | } | - | ||||||||||||
600 | } never executed: end of block | 0 | ||||||||||||
601 | if (!tls1_handshake_hash_value(s,
| 0-29 | ||||||||||||
602 | S3I(s)->tmp.cert_verify_md,
| 0-29 | ||||||||||||
603 | sizeof(S3I(s)->tmp.cert_verify_md),
| 0-29 | ||||||||||||
604 | NULL)) {
| 0-29 | ||||||||||||
605 | ret = -1; | - | ||||||||||||
606 | goto end; never executed: goto end; | 0 | ||||||||||||
607 | } | - | ||||||||||||
608 | } executed 29 times by 1 test: end of block Executed by:
| 29 | ||||||||||||
609 | break; executed 34 times by 1 test: break; Executed by:
| 34 | ||||||||||||
610 | - | |||||||||||||
611 | case SSL3_ST_SR_CERT_VRFY_A: executed 387 times by 2 tests: case (0x1A0|0x2000): Executed by:
| 387 | ||||||||||||
612 | case SSL3_ST_SR_CERT_VRFY_B: never executed: case (0x1A1|0x2000): | 0 | ||||||||||||
613 | if (SSL_IS_DTLS(s))
| 11-376 | ||||||||||||
614 | D1I(s)->change_cipher_spec_ok = 1; executed 11 times by 1 test: (s->d1->internal)->change_cipher_spec_ok = 1; Executed by:
| 11 | ||||||||||||
615 | else | - | ||||||||||||
616 | s->s3->flags |= SSL3_FLAGS_CCS_OK; executed 376 times by 2 tests: s->s3->flags |= 0x0080; Executed by:
| 376 | ||||||||||||
617 | - | |||||||||||||
618 | /* we should decide if we expected this one */ | - | ||||||||||||
619 | ret = ssl3_get_cert_verify(s); | - | ||||||||||||
620 | if (ret <= 0)
| 63-324 | ||||||||||||
621 | goto end; executed 324 times by 1 test: goto end; Executed by:
| 324 | ||||||||||||
622 | S3I(s)->hs.state = SSL3_ST_SR_FINISHED_A; | - | ||||||||||||
623 | s->internal->init_num = 0; | - | ||||||||||||
624 | break; executed 63 times by 2 tests: break; Executed by:
| 63 | ||||||||||||
625 | - | |||||||||||||
626 | case SSL3_ST_SR_FINISHED_A: executed 105 times by 2 tests: case (0x1C0|0x2000): Executed by:
| 105 | ||||||||||||
627 | case SSL3_ST_SR_FINISHED_B: never executed: case (0x1C1|0x2000): | 0 | ||||||||||||
628 | if (SSL_IS_DTLS(s))
| 11-94 | ||||||||||||
629 | D1I(s)->change_cipher_spec_ok = 1; executed 11 times by 1 test: (s->d1->internal)->change_cipher_spec_ok = 1; Executed by:
| 11 | ||||||||||||
630 | else | - | ||||||||||||
631 | s->s3->flags |= SSL3_FLAGS_CCS_OK; executed 94 times by 2 tests: s->s3->flags |= 0x0080; Executed by:
| 94 | ||||||||||||
632 | ret = ssl3_get_finished(s, SSL3_ST_SR_FINISHED_A, | - | ||||||||||||
633 | SSL3_ST_SR_FINISHED_B); | - | ||||||||||||
634 | if (ret <= 0)
| 42-63 | ||||||||||||
635 | goto end; executed 42 times by 1 test: goto end; Executed by:
| 42 | ||||||||||||
636 | if (SSL_IS_DTLS(s))
| 11-52 | ||||||||||||
637 | dtls1_stop_timer(s); executed 11 times by 1 test: dtls1_stop_timer(s); Executed by:
| 11 | ||||||||||||
638 | if (s->internal->hit)
| 0-63 | ||||||||||||
639 | S3I(s)->hs.state = SSL_ST_OK; never executed: (s->s3->internal)->hs.state = 0x03; | 0 | ||||||||||||
640 | else if (s->internal->tlsext_ticket_expected)
| 4-59 | ||||||||||||
641 | S3I(s)->hs.state = SSL3_ST_SW_SESSION_TICKET_A; executed 59 times by 1 test: (s->s3->internal)->hs.state = (0x1F0|0x2000); Executed by:
| 59 | ||||||||||||
642 | else | - | ||||||||||||
643 | S3I(s)->hs.state = SSL3_ST_SW_CHANGE_A; executed 4 times by 1 test: (s->s3->internal)->hs.state = (0x1D0|0x2000); Executed by:
| 4 | ||||||||||||
644 | s->internal->init_num = 0; | - | ||||||||||||
645 | break; executed 63 times by 2 tests: break; Executed by:
| 63 | ||||||||||||
646 | - | |||||||||||||
647 | case SSL3_ST_SW_SESSION_TICKET_A: executed 59 times by 1 test: case (0x1F0|0x2000): Executed by:
| 59 | ||||||||||||
648 | case SSL3_ST_SW_SESSION_TICKET_B: never executed: case (0x1F1|0x2000): | 0 | ||||||||||||
649 | ret = ssl3_send_newsession_ticket(s); | - | ||||||||||||
650 | if (ret <= 0)
| 0-59 | ||||||||||||
651 | goto end; never executed: goto end; | 0 | ||||||||||||
652 | S3I(s)->hs.state = SSL3_ST_SW_CHANGE_A; | - | ||||||||||||
653 | s->internal->init_num = 0; | - | ||||||||||||
654 | break; executed 59 times by 1 test: break; Executed by:
| 59 | ||||||||||||
655 | - | |||||||||||||
656 | case SSL3_ST_SW_CERT_STATUS_A: never executed: case (0x200|0x2000): | 0 | ||||||||||||
657 | case SSL3_ST_SW_CERT_STATUS_B: never executed: case (0x201|0x2000): | 0 | ||||||||||||
658 | ret = ssl3_send_cert_status(s); | - | ||||||||||||
659 | if (ret <= 0)
| 0 | ||||||||||||
660 | goto end; never executed: goto end; | 0 | ||||||||||||
661 | S3I(s)->hs.state = SSL3_ST_SW_KEY_EXCH_A; | - | ||||||||||||
662 | s->internal->init_num = 0; | - | ||||||||||||
663 | break; never executed: break; | 0 | ||||||||||||
664 | - | |||||||||||||
665 | case SSL3_ST_SW_CHANGE_A: executed 63 times by 2 tests: case (0x1D0|0x2000): Executed by:
| 63 | ||||||||||||
666 | case SSL3_ST_SW_CHANGE_B: never executed: case (0x1D1|0x2000): | 0 | ||||||||||||
667 | s->session->cipher = S3I(s)->hs.new_cipher; | - | ||||||||||||
668 | if (!tls1_setup_key_block(s)) {
| 0-63 | ||||||||||||
669 | ret = -1; | - | ||||||||||||
670 | goto end; never executed: goto end; | 0 | ||||||||||||
671 | } | - | ||||||||||||
672 | - | |||||||||||||
673 | ret = ssl3_send_change_cipher_spec(s, | - | ||||||||||||
674 | SSL3_ST_SW_CHANGE_A, SSL3_ST_SW_CHANGE_B); | - | ||||||||||||
675 | if (ret <= 0)
| 0-63 | ||||||||||||
676 | goto end; never executed: goto end; | 0 | ||||||||||||
677 | S3I(s)->hs.state = SSL3_ST_SW_FINISHED_A; | - | ||||||||||||
678 | s->internal->init_num = 0; | - | ||||||||||||
679 | - | |||||||||||||
680 | if (!tls1_change_cipher_state(s,
| 0-63 | ||||||||||||
681 | SSL3_CHANGE_CIPHER_SERVER_WRITE)) {
| 0-63 | ||||||||||||
682 | ret = -1; | - | ||||||||||||
683 | goto end; never executed: goto end; | 0 | ||||||||||||
684 | } | - | ||||||||||||
685 | - | |||||||||||||
686 | if (SSL_IS_DTLS(s))
| 11-52 | ||||||||||||
687 | dtls1_reset_seq_numbers(s, SSL3_CC_WRITE); executed 11 times by 1 test: dtls1_reset_seq_numbers(s, 0x02); Executed by:
| 11 | ||||||||||||
688 | break; executed 63 times by 2 tests: break; Executed by:
| 63 | ||||||||||||
689 | - | |||||||||||||
690 | case SSL3_ST_SW_FINISHED_A: executed 63 times by 2 tests: case (0x1E0|0x2000): Executed by:
| 63 | ||||||||||||
691 | case SSL3_ST_SW_FINISHED_B: never executed: case (0x1E1|0x2000): | 0 | ||||||||||||
692 | ret = ssl3_send_finished(s, | - | ||||||||||||
693 | SSL3_ST_SW_FINISHED_A, SSL3_ST_SW_FINISHED_B, | - | ||||||||||||
694 | TLS_MD_SERVER_FINISH_CONST, | - | ||||||||||||
695 | TLS_MD_SERVER_FINISH_CONST_SIZE); | - | ||||||||||||
696 | if (ret <= 0)
| 0-63 | ||||||||||||
697 | goto end; never executed: goto end; | 0 | ||||||||||||
698 | S3I(s)->hs.state = SSL3_ST_SW_FLUSH; | - | ||||||||||||
699 | if (s->internal->hit)
| 0-63 | ||||||||||||
700 | S3I(s)->hs.next_state = SSL3_ST_SR_FINISHED_A; never executed: (s->s3->internal)->hs.next_state = (0x1C0|0x2000); | 0 | ||||||||||||
701 | else | - | ||||||||||||
702 | S3I(s)->hs.next_state = SSL_ST_OK; executed 63 times by 2 tests: (s->s3->internal)->hs.next_state = 0x03; Executed by:
| 63 | ||||||||||||
703 | s->internal->init_num = 0; | - | ||||||||||||
704 | break; executed 63 times by 2 tests: break; Executed by:
| 63 | ||||||||||||
705 | - | |||||||||||||
706 | case SSL_ST_OK: executed 63 times by 2 tests: case 0x03: Executed by:
| 63 | ||||||||||||
707 | /* clean a few things up */ | - | ||||||||||||
708 | tls1_cleanup_key_block(s); | - | ||||||||||||
709 | - | |||||||||||||
710 | if (!SSL_IS_DTLS(s)) {
| 11-52 | ||||||||||||
711 | BUF_MEM_free(s->internal->init_buf); | - | ||||||||||||
712 | s->internal->init_buf = NULL; | - | ||||||||||||
713 | } executed 52 times by 2 tests: end of block Executed by:
| 52 | ||||||||||||
714 | - | |||||||||||||
715 | /* remove buffering on output */ | - | ||||||||||||
716 | ssl_free_wbio_buffer(s); | - | ||||||||||||
717 | - | |||||||||||||
718 | s->internal->init_num = 0; | - | ||||||||||||
719 | - | |||||||||||||
720 | /* Skipped if we just sent a HelloRequest. */ | - | ||||||||||||
721 | if (s->internal->renegotiate == 2) {
| 0-63 | ||||||||||||
722 | s->internal->renegotiate = 0; | - | ||||||||||||
723 | s->internal->new_session = 0; | - | ||||||||||||
724 | - | |||||||||||||
725 | ssl_update_cache(s, SSL_SESS_CACHE_SERVER); | - | ||||||||||||
726 | - | |||||||||||||
727 | s->ctx->internal->stats.sess_accept_good++; | - | ||||||||||||
728 | /* s->server=1; */ | - | ||||||||||||
729 | s->internal->handshake_func = ssl3_accept; | - | ||||||||||||
730 | - | |||||||||||||
731 | if (cb != NULL)
| 0-63 | ||||||||||||
732 | cb(s, SSL_CB_HANDSHAKE_DONE, 1); never executed: cb(s, 0x20, 1); | 0 | ||||||||||||
733 | } executed 63 times by 2 tests: end of block Executed by:
| 63 | ||||||||||||
734 | - | |||||||||||||
735 | ret = 1; | - | ||||||||||||
736 | - | |||||||||||||
737 | if (SSL_IS_DTLS(s)) {
| 11-52 | ||||||||||||
738 | /* Done handshaking, next message is client hello. */ | - | ||||||||||||
739 | D1I(s)->handshake_read_seq = 0; | - | ||||||||||||
740 | /* Next message is server hello. */ | - | ||||||||||||
741 | D1I(s)->handshake_write_seq = 0; | - | ||||||||||||
742 | D1I(s)->next_handshake_write_seq = 0; | - | ||||||||||||
743 | } executed 11 times by 1 test: end of block Executed by:
| 11 | ||||||||||||
744 | goto end; executed 63 times by 2 tests: goto end; Executed by:
| 63 | ||||||||||||
745 | /* break; */ | - | ||||||||||||
746 | - | |||||||||||||
747 | default: never executed: default: | 0 | ||||||||||||
748 | SSLerror(s, SSL_R_UNKNOWN_STATE); | - | ||||||||||||
749 | ret = -1; | - | ||||||||||||
750 | goto end; never executed: goto end; | 0 | ||||||||||||
751 | /* break; */ | - | ||||||||||||
752 | } | - | ||||||||||||
753 | - | |||||||||||||
754 | if (!S3I(s)->tmp.reuse_message && !skip) {
| 56-966 | ||||||||||||
755 | if (s->internal->debug) {
| 0-884 | ||||||||||||
756 | if ((ret = BIO_flush(s->wbio)) <= 0)
| 0 | ||||||||||||
757 | goto end; never executed: goto end; | 0 | ||||||||||||
758 | } never executed: end of block | 0 | ||||||||||||
759 | - | |||||||||||||
760 | - | |||||||||||||
761 | if ((cb != NULL) && (S3I(s)->hs.state != state)) {
| 0-884 | ||||||||||||
762 | new_state = S3I(s)->hs.state; | - | ||||||||||||
763 | S3I(s)->hs.state = state; | - | ||||||||||||
764 | cb(s, SSL_CB_ACCEPT_LOOP, 1); | - | ||||||||||||
765 | S3I(s)->hs.state = new_state; | - | ||||||||||||
766 | } never executed: end of block | 0 | ||||||||||||
767 | } executed 884 times by 3 tests: end of block Executed by:
| 884 | ||||||||||||
768 | skip = 0; | - | ||||||||||||
769 | } executed 1022 times by 3 tests: end of block Executed by:
| 1022 | ||||||||||||
770 | end: code before this statement never executed: end: | 0 | ||||||||||||
771 | /* BIO_flush(s->wbio); */ | - | ||||||||||||
772 | s->internal->in_handshake--; | - | ||||||||||||
773 | if (cb != NULL)
| 0-1236 | ||||||||||||
774 | cb(s, SSL_CB_ACCEPT_EXIT, ret); never executed: cb(s, (0x2000|0x02), ret); | 0 | ||||||||||||
775 | - | |||||||||||||
776 | return (ret); executed 1236 times by 3 tests: return (ret); Executed by:
| 1236 | ||||||||||||
777 | } | - | ||||||||||||
778 | - | |||||||||||||
779 | int | - | ||||||||||||
780 | ssl3_send_hello_request(SSL *s) | - | ||||||||||||
781 | { | - | ||||||||||||
782 | CBB cbb, hello; | - | ||||||||||||
783 | - | |||||||||||||
784 | memset(&cbb, 0, sizeof(cbb)); | - | ||||||||||||
785 | - | |||||||||||||
786 | if (S3I(s)->hs.state == SSL3_ST_SW_HELLO_REQ_A) {
| 0 | ||||||||||||
787 | if (!ssl3_handshake_msg_start(s, &cbb, &hello,
| 0 | ||||||||||||
788 | SSL3_MT_HELLO_REQUEST))
| 0 | ||||||||||||
789 | goto err; never executed: goto err; | 0 | ||||||||||||
790 | if (!ssl3_handshake_msg_finish(s, &cbb))
| 0 | ||||||||||||
791 | goto err; never executed: goto err; | 0 | ||||||||||||
792 | - | |||||||||||||
793 | S3I(s)->hs.state = SSL3_ST_SW_HELLO_REQ_B; | - | ||||||||||||
794 | } never executed: end of block | 0 | ||||||||||||
795 | - | |||||||||||||
796 | /* SSL3_ST_SW_HELLO_REQ_B */ | - | ||||||||||||
797 | return (ssl3_handshake_write(s)); never executed: return (ssl3_handshake_write(s)); | 0 | ||||||||||||
798 | - | |||||||||||||
799 | err: | - | ||||||||||||
800 | CBB_cleanup(&cbb); | - | ||||||||||||
801 | - | |||||||||||||
802 | return (-1); never executed: return (-1); | 0 | ||||||||||||
803 | } | - | ||||||||||||
804 | - | |||||||||||||
805 | int | - | ||||||||||||
806 | ssl3_get_client_hello(SSL *s) | - | ||||||||||||
807 | { | - | ||||||||||||
808 | CBS cbs, client_random, session_id, cookie, cipher_suites; | - | ||||||||||||
809 | CBS compression_methods; | - | ||||||||||||
810 | uint16_t client_version; | - | ||||||||||||
811 | uint8_t comp_method; | - | ||||||||||||
812 | int comp_null; | - | ||||||||||||
813 | int i, j, ok, al, ret = -1, cookie_valid = 0; | - | ||||||||||||
814 | long n; | - | ||||||||||||
815 | unsigned long id; | - | ||||||||||||
816 | SSL_CIPHER *c; | - | ||||||||||||
817 | STACK_OF(SSL_CIPHER) *ciphers = NULL; | - | ||||||||||||
818 | unsigned long alg_k; | - | ||||||||||||
819 | const SSL_METHOD *method; | - | ||||||||||||
820 | uint16_t shared_version; | - | ||||||||||||
821 | - | |||||||||||||
822 | /* | - | ||||||||||||
823 | * We do this so that we will respond with our native type. | - | ||||||||||||
824 | * If we are TLSv1 and we get SSLv3, we will respond with TLSv1, | - | ||||||||||||
825 | * This down switching should be handled by a different method. | - | ||||||||||||
826 | * If we are SSLv3, we will respond with SSLv3, even if prompted with | - | ||||||||||||
827 | * TLSv1. | - | ||||||||||||
828 | */ | - | ||||||||||||
829 | if (S3I(s)->hs.state == SSL3_ST_SR_CLNT_HELLO_A) {
| 65-192 | ||||||||||||
830 | S3I(s)->hs.state = SSL3_ST_SR_CLNT_HELLO_B; | - | ||||||||||||
831 | } executed 65 times by 3 tests: end of block Executed by:
| 65 | ||||||||||||
832 | - | |||||||||||||
833 | s->internal->first_packet = 1; | - | ||||||||||||
834 | n = s->method->internal->ssl_get_message(s, SSL3_ST_SR_CLNT_HELLO_B, | - | ||||||||||||
835 | SSL3_ST_SR_CLNT_HELLO_C, SSL3_MT_CLIENT_HELLO, | - | ||||||||||||
836 | SSL3_RT_MAX_PLAIN_LENGTH, &ok); | - | ||||||||||||
837 | if (!ok)
| 65-192 | ||||||||||||
838 | return ((int)n); executed 192 times by 1 test: return ((int)n); Executed by:
| 192 | ||||||||||||
839 | s->internal->first_packet = 0; | - | ||||||||||||
840 | - | |||||||||||||
841 | if (n < 0)
| 0-65 | ||||||||||||
842 | goto err; never executed: goto err; | 0 | ||||||||||||
843 | - | |||||||||||||
844 | CBS_init(&cbs, s->internal->init_msg, n); | - | ||||||||||||
845 | - | |||||||||||||
846 | /* Parse client hello up until the extensions (if any). */ | - | ||||||||||||
847 | if (!CBS_get_u16(&cbs, &client_version))
| 0-65 | ||||||||||||
848 | goto truncated; never executed: goto truncated; | 0 | ||||||||||||
849 | if (!CBS_get_bytes(&cbs, &client_random, SSL3_RANDOM_SIZE))
| 0-65 | ||||||||||||
850 | goto truncated; never executed: goto truncated; | 0 | ||||||||||||
851 | if (!CBS_get_u8_length_prefixed(&cbs, &session_id))
| 0-65 | ||||||||||||
852 | goto truncated; never executed: goto truncated; | 0 | ||||||||||||
853 | if (SSL_IS_DTLS(s)) {
| 11-54 | ||||||||||||
854 | if (!CBS_get_u8_length_prefixed(&cbs, &cookie))
| 0-11 | ||||||||||||
855 | goto truncated; never executed: goto truncated; | 0 | ||||||||||||
856 | } executed 11 times by 1 test: end of block Executed by:
| 11 | ||||||||||||
857 | if (!CBS_get_u16_length_prefixed(&cbs, &cipher_suites))
| 0-65 | ||||||||||||
858 | goto truncated; never executed: goto truncated; | 0 | ||||||||||||
859 | if (!CBS_get_u8_length_prefixed(&cbs, &compression_methods))
| 0-65 | ||||||||||||
860 | goto truncated; never executed: goto truncated; | 0 | ||||||||||||
861 | - | |||||||||||||
862 | /* | - | ||||||||||||
863 | * Use version from inside client hello, not from record header. | - | ||||||||||||
864 | * (may differ: see RFC 2246, Appendix E, second paragraph) | - | ||||||||||||
865 | */ | - | ||||||||||||
866 | if (ssl_max_shared_version(s, client_version, &shared_version) != 1) {
| 0-65 | ||||||||||||
867 | SSLerror(s, SSL_R_WRONG_VERSION_NUMBER); | - | ||||||||||||
868 | if ((s->client_version >> 8) == SSL3_VERSION_MAJOR &&
| 0 | ||||||||||||
869 | !s->internal->enc_write_ctx && !s->internal->write_hash) {
| 0 | ||||||||||||
870 | /* | - | ||||||||||||
871 | * Similar to ssl3_get_record, send alert using remote | - | ||||||||||||
872 | * version number. | - | ||||||||||||
873 | */ | - | ||||||||||||
874 | s->version = s->client_version; | - | ||||||||||||
875 | } never executed: end of block | 0 | ||||||||||||
876 | al = SSL_AD_PROTOCOL_VERSION; | - | ||||||||||||
877 | goto f_err; never executed: goto f_err; | 0 | ||||||||||||
878 | } | - | ||||||||||||
879 | s->client_version = client_version; | - | ||||||||||||
880 | s->version = shared_version; | - | ||||||||||||
881 | - | |||||||||||||
882 | if ((method = tls1_get_server_method(shared_version)) == NULL)
| 11-54 | ||||||||||||
883 | method = dtls1_get_server_method(shared_version); executed 11 times by 1 test: method = dtls1_get_server_method(shared_version); Executed by:
| 11 | ||||||||||||
884 | if (method == NULL) {
| 0-65 | ||||||||||||
885 | SSLerror(s, ERR_R_INTERNAL_ERROR); | - | ||||||||||||
886 | goto err; never executed: goto err; | 0 | ||||||||||||
887 | } | - | ||||||||||||
888 | s->method = method; | - | ||||||||||||
889 | - | |||||||||||||
890 | /* | - | ||||||||||||
891 | * If we require cookies (DTLS) and this ClientHello does not contain | - | ||||||||||||
892 | * one, just return since we do not want to allocate any memory yet. | - | ||||||||||||
893 | * So check cookie length... | - | ||||||||||||
894 | */ | - | ||||||||||||
895 | if (SSL_IS_DTLS(s)) {
| 11-54 | ||||||||||||
896 | if (SSL_get_options(s) & SSL_OP_COOKIE_EXCHANGE) {
| 0-11 | ||||||||||||
897 | if (CBS_len(&cookie) == 0)
| 0 | ||||||||||||
898 | return (1); never executed: return (1); | 0 | ||||||||||||
899 | } never executed: end of block | 0 | ||||||||||||
900 | } executed 11 times by 1 test: end of block Executed by:
| 11 | ||||||||||||
901 | - | |||||||||||||
902 | if (!CBS_write_bytes(&client_random, s->s3->client_random,
| 0-65 | ||||||||||||
903 | sizeof(s->s3->client_random), NULL))
| 0-65 | ||||||||||||
904 | goto err; never executed: goto err; | 0 | ||||||||||||
905 | - | |||||||||||||
906 | s->internal->hit = 0; | - | ||||||||||||
907 | - | |||||||||||||
908 | /* | - | ||||||||||||
909 | * Versions before 0.9.7 always allow clients to resume sessions in | - | ||||||||||||
910 | * renegotiation. 0.9.7 and later allow this by default, but optionally | - | ||||||||||||
911 | * ignore resumption requests with flag | - | ||||||||||||
912 | * SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION (it's a new flag | - | ||||||||||||
913 | * rather than a change to default behavior so that applications | - | ||||||||||||
914 | * relying on this for security won't even compile against older | - | ||||||||||||
915 | * library versions). | - | ||||||||||||
916 | * | - | ||||||||||||
917 | * 1.0.1 and later also have a function SSL_renegotiate_abbreviated() | - | ||||||||||||
918 | * to request renegotiation but not a new session (s->internal->new_session | - | ||||||||||||
919 | * remains unset): for servers, this essentially just means that the | - | ||||||||||||
920 | * SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION setting will be | - | ||||||||||||
921 | * ignored. | - | ||||||||||||
922 | */ | - | ||||||||||||
923 | if ((s->internal->new_session && (s->internal->options &
| 0-65 | ||||||||||||
924 | SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION))) {
| 0 | ||||||||||||
925 | if (!ssl_get_new_session(s, 1))
| 0 | ||||||||||||
926 | goto err; never executed: goto err; | 0 | ||||||||||||
927 | } else { never executed: end of block | 0 | ||||||||||||
928 | CBS ext_block; | - | ||||||||||||
929 | - | |||||||||||||
930 | CBS_dup(&cbs, &ext_block); | - | ||||||||||||
931 | - | |||||||||||||
932 | i = ssl_get_prev_session(s, CBS_data(&session_id), | - | ||||||||||||
933 | CBS_len(&session_id), &ext_block); | - | ||||||||||||
934 | if (i == 1) { /* previous session */
| 0-65 | ||||||||||||
935 | s->internal->hit = 1; | - | ||||||||||||
936 | } else if (i == -1) never executed: end of block
| 0-65 | ||||||||||||
937 | goto err; never executed: goto err; | 0 | ||||||||||||
938 | else { | - | ||||||||||||
939 | /* i == 0 */ | - | ||||||||||||
940 | if (!ssl_get_new_session(s, 1))
| 0-65 | ||||||||||||
941 | goto err; never executed: goto err; | 0 | ||||||||||||
942 | } executed 65 times by 3 tests: end of block Executed by:
| 65 | ||||||||||||
943 | } | - | ||||||||||||
944 | - | |||||||||||||
945 | if (SSL_IS_DTLS(s)) {
| 11-54 | ||||||||||||
946 | /* | - | ||||||||||||
947 | * The ClientHello may contain a cookie even if the HelloVerify | - | ||||||||||||
948 | * message has not been sent - make sure that it does not cause | - | ||||||||||||
949 | * an overflow. | - | ||||||||||||
950 | */ | - | ||||||||||||
951 | if (CBS_len(&cookie) > sizeof(D1I(s)->rcvd_cookie)) {
| 0-11 | ||||||||||||
952 | al = SSL_AD_DECODE_ERROR; | - | ||||||||||||
953 | SSLerror(s, SSL_R_COOKIE_MISMATCH); | - | ||||||||||||
954 | goto f_err; never executed: goto f_err; | 0 | ||||||||||||
955 | } | - | ||||||||||||
956 | - | |||||||||||||
957 | /* Verify the cookie if appropriate option is set. */ | - | ||||||||||||
958 | if ((SSL_get_options(s) & SSL_OP_COOKIE_EXCHANGE) &&
| 0-11 | ||||||||||||
959 | CBS_len(&cookie) > 0) {
| 0 | ||||||||||||
960 | size_t cookie_len; | - | ||||||||||||
961 | - | |||||||||||||
962 | /* XXX - rcvd_cookie seems to only be used here... */ | - | ||||||||||||
963 | if (!CBS_write_bytes(&cookie, D1I(s)->rcvd_cookie,
| 0 | ||||||||||||
964 | sizeof(D1I(s)->rcvd_cookie), &cookie_len))
| 0 | ||||||||||||
965 | goto err; never executed: goto err; | 0 | ||||||||||||
966 | - | |||||||||||||
967 | if (s->ctx->internal->app_verify_cookie_cb != NULL) {
| 0 | ||||||||||||
968 | if (s->ctx->internal->app_verify_cookie_cb(s,
| 0 | ||||||||||||
969 | D1I(s)->rcvd_cookie, cookie_len) == 0) {
| 0 | ||||||||||||
970 | al = SSL_AD_HANDSHAKE_FAILURE; | - | ||||||||||||
971 | SSLerror(s, SSL_R_COOKIE_MISMATCH); | - | ||||||||||||
972 | goto f_err; never executed: goto f_err; | 0 | ||||||||||||
973 | } | - | ||||||||||||
974 | /* else cookie verification succeeded */ | - | ||||||||||||
975 | /* XXX - can d1->cookie_len > sizeof(rcvd_cookie) ? */ | - | ||||||||||||
976 | } else if (timingsafe_memcmp(D1I(s)->rcvd_cookie, never executed: end of block
| 0 | ||||||||||||
977 | D1I(s)->cookie, D1I(s)->cookie_len) != 0) {
| 0 | ||||||||||||
978 | /* default verification */ | - | ||||||||||||
979 | al = SSL_AD_HANDSHAKE_FAILURE; | - | ||||||||||||
980 | SSLerror(s, SSL_R_COOKIE_MISMATCH); | - | ||||||||||||
981 | goto f_err; never executed: goto f_err; | 0 | ||||||||||||
982 | } | - | ||||||||||||
983 | cookie_valid = 1; | - | ||||||||||||
984 | } never executed: end of block | 0 | ||||||||||||
985 | } executed 11 times by 1 test: end of block Executed by:
| 11 | ||||||||||||
986 | - | |||||||||||||
987 | /* XXX - This logic seems wrong... */ | - | ||||||||||||
988 | if (CBS_len(&cipher_suites) == 0 && CBS_len(&session_id) != 0) {
| 0-65 | ||||||||||||
989 | /* we need a cipher if we are not resuming a session */ | - | ||||||||||||
990 | al = SSL_AD_ILLEGAL_PARAMETER; | - | ||||||||||||
991 | SSLerror(s, SSL_R_NO_CIPHERS_SPECIFIED); | - | ||||||||||||
992 | goto f_err; never executed: goto f_err; | 0 | ||||||||||||
993 | } | - | ||||||||||||
994 | - | |||||||||||||
995 | if (CBS_len(&cipher_suites) > 0) {
| 0-65 | ||||||||||||
996 | if ((ciphers = ssl_bytes_to_cipher_list(s,
| 0-65 | ||||||||||||
997 | &cipher_suites)) == NULL)
| 0-65 | ||||||||||||
998 | goto err; never executed: goto err; | 0 | ||||||||||||
999 | } executed 65 times by 3 tests: end of block Executed by:
| 65 | ||||||||||||
1000 | - | |||||||||||||
1001 | /* If it is a hit, check that the cipher is in the list */ | - | ||||||||||||
1002 | /* XXX - CBS_len(&cipher_suites) will always be zero here... */ | - | ||||||||||||
1003 | if (s->internal->hit && CBS_len(&cipher_suites) > 0) {
| 0-65 | ||||||||||||
1004 | j = 0; | - | ||||||||||||
1005 | id = s->session->cipher->id; | - | ||||||||||||
1006 | - | |||||||||||||
1007 | for (i = 0; i < sk_SSL_CIPHER_num(ciphers); i++) {
| 0 | ||||||||||||
1008 | c = sk_SSL_CIPHER_value(ciphers, i); | - | ||||||||||||
1009 | if (c->id == id) {
| 0 | ||||||||||||
1010 | j = 1; | - | ||||||||||||
1011 | break; never executed: break; | 0 | ||||||||||||
1012 | } | - | ||||||||||||
1013 | } never executed: end of block | 0 | ||||||||||||
1014 | if (j == 0) {
| 0 | ||||||||||||
1015 | /* | - | ||||||||||||
1016 | * We need to have the cipher in the cipher | - | ||||||||||||
1017 | * list if we are asked to reuse it | - | ||||||||||||
1018 | */ | - | ||||||||||||
1019 | al = SSL_AD_ILLEGAL_PARAMETER; | - | ||||||||||||
1020 | SSLerror(s, SSL_R_REQUIRED_CIPHER_MISSING); | - | ||||||||||||
1021 | goto f_err; never executed: goto f_err; | 0 | ||||||||||||
1022 | } | - | ||||||||||||
1023 | } never executed: end of block | 0 | ||||||||||||
1024 | - | |||||||||||||
1025 | comp_null = 0; | - | ||||||||||||
1026 | while (CBS_len(&compression_methods) > 0) {
| 65 | ||||||||||||
1027 | if (!CBS_get_u8(&compression_methods, &comp_method))
| 0-65 | ||||||||||||
1028 | goto truncated; never executed: goto truncated; | 0 | ||||||||||||
1029 | if (comp_method == 0)
| 0-65 | ||||||||||||
1030 | comp_null = 1; executed 65 times by 3 tests: comp_null = 1; Executed by:
| 65 | ||||||||||||
1031 | } executed 65 times by 3 tests: end of block Executed by:
| 65 | ||||||||||||
1032 | if (comp_null == 0) {
| 0-65 | ||||||||||||
1033 | al = SSL_AD_DECODE_ERROR; | - | ||||||||||||
1034 | SSLerror(s, SSL_R_NO_COMPRESSION_SPECIFIED); | - | ||||||||||||
1035 | goto f_err; never executed: goto f_err; | 0 | ||||||||||||
1036 | } | - | ||||||||||||
1037 | - | |||||||||||||
1038 | if (!tlsext_clienthello_parse(s, &cbs, &al)) {
| 0-65 | ||||||||||||
1039 | SSLerror(s, SSL_R_PARSE_TLSEXT); | - | ||||||||||||
1040 | goto f_err; never executed: goto f_err; | 0 | ||||||||||||
1041 | } | - | ||||||||||||
1042 | - | |||||||||||||
1043 | if (!S3I(s)->renegotiate_seen && s->internal->renegotiate) {
| 0-65 | ||||||||||||
1044 | al = SSL_AD_HANDSHAKE_FAILURE; | - | ||||||||||||
1045 | SSLerror(s, SSL_R_UNSAFE_LEGACY_RENEGOTIATION_DISABLED); | - | ||||||||||||
1046 | goto f_err; never executed: goto f_err; | 0 | ||||||||||||
1047 | } | - | ||||||||||||
1048 | - | |||||||||||||
1049 | if (ssl_check_clienthello_tlsext_early(s) <= 0) {
| 0-65 | ||||||||||||
1050 | SSLerror(s, SSL_R_CLIENTHELLO_TLSEXT); | - | ||||||||||||
1051 | goto err; never executed: goto err; | 0 | ||||||||||||
1052 | } | - | ||||||||||||
1053 | - | |||||||||||||
1054 | /* | - | ||||||||||||
1055 | * Check if we want to use external pre-shared secret for this | - | ||||||||||||
1056 | * handshake for not reused session only. We need to generate | - | ||||||||||||
1057 | * server_random before calling tls_session_secret_cb in order to allow | - | ||||||||||||
1058 | * SessionTicket processing to use it in key derivation. | - | ||||||||||||
1059 | */ | - | ||||||||||||
1060 | arc4random_buf(s->s3->server_random, SSL3_RANDOM_SIZE); | - | ||||||||||||
1061 | - | |||||||||||||
1062 | if (!s->internal->hit && s->internal->tls_session_secret_cb) {
| 0-65 | ||||||||||||
1063 | SSL_CIPHER *pref_cipher = NULL; | - | ||||||||||||
1064 | - | |||||||||||||
1065 | s->session->master_key_length = sizeof(s->session->master_key); | - | ||||||||||||
1066 | if (s->internal->tls_session_secret_cb(s, s->session->master_key,
| 0 | ||||||||||||
1067 | &s->session->master_key_length, ciphers, &pref_cipher,
| 0 | ||||||||||||
1068 | s->internal->tls_session_secret_cb_arg)) {
| 0 | ||||||||||||
1069 | s->internal->hit = 1; | - | ||||||||||||
1070 | s->session->ciphers = ciphers; | - | ||||||||||||
1071 | s->session->verify_result = X509_V_OK; | - | ||||||||||||
1072 | - | |||||||||||||
1073 | ciphers = NULL; | - | ||||||||||||
1074 | - | |||||||||||||
1075 | /* check if some cipher was preferred by call back */ | - | ||||||||||||
1076 | pref_cipher = pref_cipher ? pref_cipher :
| 0 | ||||||||||||
1077 | ssl3_choose_cipher(s, s->session->ciphers, | - | ||||||||||||
1078 | SSL_get_ciphers(s)); | - | ||||||||||||
1079 | if (pref_cipher == NULL) {
| 0 | ||||||||||||
1080 | al = SSL_AD_HANDSHAKE_FAILURE; | - | ||||||||||||
1081 | SSLerror(s, SSL_R_NO_SHARED_CIPHER); | - | ||||||||||||
1082 | goto f_err; never executed: goto f_err; | 0 | ||||||||||||
1083 | } | - | ||||||||||||
1084 | - | |||||||||||||
1085 | s->session->cipher = pref_cipher; | - | ||||||||||||
1086 | - | |||||||||||||
1087 | sk_SSL_CIPHER_free(s->cipher_list); | - | ||||||||||||
1088 | sk_SSL_CIPHER_free(s->internal->cipher_list_by_id); | - | ||||||||||||
1089 | - | |||||||||||||
1090 | s->cipher_list = sk_SSL_CIPHER_dup(s->session->ciphers); | - | ||||||||||||
1091 | s->internal->cipher_list_by_id = | - | ||||||||||||
1092 | sk_SSL_CIPHER_dup(s->session->ciphers); | - | ||||||||||||
1093 | } never executed: end of block | 0 | ||||||||||||
1094 | } never executed: end of block | 0 | ||||||||||||
1095 | - | |||||||||||||
1096 | /* | - | ||||||||||||
1097 | * Given s->session->ciphers and SSL_get_ciphers, we must | - | ||||||||||||
1098 | * pick a cipher | - | ||||||||||||
1099 | */ | - | ||||||||||||
1100 | - | |||||||||||||
1101 | if (!s->internal->hit) {
| 0-65 | ||||||||||||
1102 | sk_SSL_CIPHER_free(s->session->ciphers); | - | ||||||||||||
1103 | s->session->ciphers = ciphers; | - | ||||||||||||
1104 | if (ciphers == NULL) {
| 0-65 | ||||||||||||
1105 | al = SSL_AD_ILLEGAL_PARAMETER; | - | ||||||||||||
1106 | SSLerror(s, SSL_R_NO_CIPHERS_PASSED); | - | ||||||||||||
1107 | goto f_err; never executed: goto f_err; | 0 | ||||||||||||
1108 | } | - | ||||||||||||
1109 | ciphers = NULL; | - | ||||||||||||
1110 | c = ssl3_choose_cipher(s, s->session->ciphers, | - | ||||||||||||
1111 | SSL_get_ciphers(s)); | - | ||||||||||||
1112 | - | |||||||||||||
1113 | if (c == NULL) {
| 0-65 | ||||||||||||
1114 | al = SSL_AD_HANDSHAKE_FAILURE; | - | ||||||||||||
1115 | SSLerror(s, SSL_R_NO_SHARED_CIPHER); | - | ||||||||||||
1116 | goto f_err; never executed: goto f_err; | 0 | ||||||||||||
1117 | } | - | ||||||||||||
1118 | S3I(s)->hs.new_cipher = c; | - | ||||||||||||
1119 | } else { executed 65 times by 3 tests: end of block Executed by:
| 65 | ||||||||||||
1120 | S3I(s)->hs.new_cipher = s->session->cipher; | - | ||||||||||||
1121 | } never executed: end of block | 0 | ||||||||||||
1122 | - | |||||||||||||
1123 | if (!tls1_handshake_hash_init(s))
| 0-65 | ||||||||||||
1124 | goto err; never executed: goto err; | 0 | ||||||||||||
1125 | - | |||||||||||||
1126 | alg_k = S3I(s)->hs.new_cipher->algorithm_mkey; | - | ||||||||||||
1127 | if (!(SSL_USE_SIGALGS(s) || (alg_k & SSL_kGOST)) ||
| 0-35 | ||||||||||||
1128 | !(s->verify_mode & SSL_VERIFY_PEER)) {
| 5-30 | ||||||||||||
1129 | if (!tls1_digest_cached_records(s)) {
| 0-60 | ||||||||||||
1130 | al = SSL_AD_INTERNAL_ERROR; | - | ||||||||||||
1131 | goto f_err; never executed: goto f_err; | 0 | ||||||||||||
1132 | } | - | ||||||||||||
1133 | } executed 60 times by 3 tests: end of block Executed by:
| 60 | ||||||||||||
1134 | - | |||||||||||||
1135 | /* | - | ||||||||||||
1136 | * We now have the following setup. | - | ||||||||||||
1137 | * client_random | - | ||||||||||||
1138 | * cipher_list - our prefered list of ciphers | - | ||||||||||||
1139 | * ciphers - the clients prefered list of ciphers | - | ||||||||||||
1140 | * compression - basically ignored right now | - | ||||||||||||
1141 | * ssl version is set - sslv3 | - | ||||||||||||
1142 | * s->session - The ssl session has been setup. | - | ||||||||||||
1143 | * s->internal->hit - session reuse flag | - | ||||||||||||
1144 | * s->hs.new_cipher - the new cipher to use. | - | ||||||||||||
1145 | */ | - | ||||||||||||
1146 | - | |||||||||||||
1147 | /* Handles TLS extensions that we couldn't check earlier */ | - | ||||||||||||
1148 | if (ssl_check_clienthello_tlsext_late(s) <= 0) {
| 0-65 | ||||||||||||
1149 | SSLerror(s, SSL_R_CLIENTHELLO_TLSEXT); | - | ||||||||||||
1150 | goto err; never executed: goto err; | 0 | ||||||||||||
1151 | } | - | ||||||||||||
1152 | - | |||||||||||||
1153 | ret = cookie_valid ? 2 : 1;
| 0-65 | ||||||||||||
1154 | - | |||||||||||||
1155 | if (0) { | - | ||||||||||||
1156 | truncated: | - | ||||||||||||
1157 | al = SSL_AD_DECODE_ERROR; | - | ||||||||||||
1158 | SSLerror(s, SSL_R_BAD_PACKET_LENGTH); | - | ||||||||||||
1159 | f_err: code before this statement never executed: f_err: | 0 | ||||||||||||
1160 | ssl3_send_alert(s, SSL3_AL_FATAL, al); | - | ||||||||||||
1161 | } never executed: end of block | 0 | ||||||||||||
1162 | err: code before this statement executed 65 times by 3 tests: err: Executed by:
| 65 | ||||||||||||
1163 | sk_SSL_CIPHER_free(ciphers); | - | ||||||||||||
1164 | - | |||||||||||||
1165 | return (ret); executed 65 times by 3 tests: return (ret); Executed by:
| 65 | ||||||||||||
1166 | } | - | ||||||||||||
1167 | - | |||||||||||||
1168 | int | - | ||||||||||||
1169 | ssl3_send_server_hello(SSL *s) | - | ||||||||||||
1170 | { | - | ||||||||||||
1171 | CBB cbb, server_hello, session_id; | - | ||||||||||||
1172 | size_t sl; | - | ||||||||||||
1173 | - | |||||||||||||
1174 | memset(&cbb, 0, sizeof(cbb)); | - | ||||||||||||
1175 | - | |||||||||||||
1176 | if (S3I(s)->hs.state == SSL3_ST_SW_SRVR_HELLO_A) {
| 0-65 | ||||||||||||
1177 | if (!ssl3_handshake_msg_start(s, &cbb, &server_hello,
| 0-65 | ||||||||||||
1178 | SSL3_MT_SERVER_HELLO))
| 0-65 | ||||||||||||
1179 | goto err; never executed: goto err; | 0 | ||||||||||||
1180 | - | |||||||||||||
1181 | if (!CBB_add_u16(&server_hello, s->version))
| 0-65 | ||||||||||||
1182 | goto err; never executed: goto err; | 0 | ||||||||||||
1183 | if (!CBB_add_bytes(&server_hello, s->s3->server_random,
| 0-65 | ||||||||||||
1184 | sizeof(s->s3->server_random)))
| 0-65 | ||||||||||||
1185 | goto err; never executed: goto err; | 0 | ||||||||||||
1186 | - | |||||||||||||
1187 | /* | - | ||||||||||||
1188 | * There are several cases for the session ID to send | - | ||||||||||||
1189 | * back in the server hello: | - | ||||||||||||
1190 | * | - | ||||||||||||
1191 | * - For session reuse from the session cache, | - | ||||||||||||
1192 | * we send back the old session ID. | - | ||||||||||||
1193 | * - If stateless session reuse (using a session ticket) | - | ||||||||||||
1194 | * is successful, we send back the client's "session ID" | - | ||||||||||||
1195 | * (which doesn't actually identify the session). | - | ||||||||||||
1196 | * - If it is a new session, we send back the new | - | ||||||||||||
1197 | * session ID. | - | ||||||||||||
1198 | * - However, if we want the new session to be single-use, | - | ||||||||||||
1199 | * we send back a 0-length session ID. | - | ||||||||||||
1200 | * | - | ||||||||||||
1201 | * s->internal->hit is non-zero in either case of session reuse, | - | ||||||||||||
1202 | * so the following won't overwrite an ID that we're supposed | - | ||||||||||||
1203 | * to send back. | - | ||||||||||||
1204 | */ | - | ||||||||||||
1205 | if (!(s->ctx->internal->session_cache_mode & SSL_SESS_CACHE_SERVER)
| 4-61 | ||||||||||||
1206 | && !s->internal->hit)
| 0-4 | ||||||||||||
1207 | s->session->session_id_length = 0; executed 4 times by 1 test: s->session->session_id_length = 0; Executed by:
| 4 | ||||||||||||
1208 | - | |||||||||||||
1209 | sl = s->session->session_id_length; | - | ||||||||||||
1210 | if (sl > sizeof(s->session->session_id)) {
| 0-65 | ||||||||||||
1211 | SSLerror(s, ERR_R_INTERNAL_ERROR); | - | ||||||||||||
1212 | goto err; never executed: goto err; | 0 | ||||||||||||
1213 | } | - | ||||||||||||
1214 | if (!CBB_add_u8_length_prefixed(&server_hello, &session_id))
| 0-65 | ||||||||||||
1215 | goto err; never executed: goto err; | 0 | ||||||||||||
1216 | if (!CBB_add_bytes(&session_id, s->session->session_id, sl))
| 0-65 | ||||||||||||
1217 | goto err; never executed: goto err; | 0 | ||||||||||||
1218 | - | |||||||||||||
1219 | /* Cipher suite. */ | - | ||||||||||||
1220 | if (!CBB_add_u16(&server_hello,
| 0-65 | ||||||||||||
1221 | ssl3_cipher_get_value(S3I(s)->hs.new_cipher)))
| 0-65 | ||||||||||||
1222 | goto err; never executed: goto err; | 0 | ||||||||||||
1223 | - | |||||||||||||
1224 | /* Compression method (null). */ | - | ||||||||||||
1225 | if (!CBB_add_u8(&server_hello, 0))
| 0-65 | ||||||||||||
1226 | goto err; never executed: goto err; | 0 | ||||||||||||
1227 | - | |||||||||||||
1228 | /* TLS extensions */ | - | ||||||||||||
1229 | if (!tlsext_serverhello_build(s, &server_hello)) {
| 0-65 | ||||||||||||
1230 | SSLerror(s, ERR_R_INTERNAL_ERROR); | - | ||||||||||||
1231 | goto err; never executed: goto err; | 0 | ||||||||||||
1232 | } | - | ||||||||||||
1233 | - | |||||||||||||
1234 | if (!ssl3_handshake_msg_finish(s, &cbb))
| 0-65 | ||||||||||||
1235 | goto err; never executed: goto err; | 0 | ||||||||||||
1236 | } executed 65 times by 3 tests: end of block Executed by:
| 65 | ||||||||||||
1237 | - | |||||||||||||
1238 | /* SSL3_ST_SW_SRVR_HELLO_B */ | - | ||||||||||||
1239 | return (ssl3_handshake_write(s)); executed 65 times by 3 tests: return (ssl3_handshake_write(s)); Executed by:
| 65 | ||||||||||||
1240 | - | |||||||||||||
1241 | err: | - | ||||||||||||
1242 | CBB_cleanup(&cbb); | - | ||||||||||||
1243 | - | |||||||||||||
1244 | return (-1); never executed: return (-1); | 0 | ||||||||||||
1245 | } | - | ||||||||||||
1246 | - | |||||||||||||
1247 | int | - | ||||||||||||
1248 | ssl3_send_server_done(SSL *s) | - | ||||||||||||
1249 | { | - | ||||||||||||
1250 | CBB cbb, done; | - | ||||||||||||
1251 | - | |||||||||||||
1252 | memset(&cbb, 0, sizeof(cbb)); | - | ||||||||||||
1253 | - | |||||||||||||
1254 | if (S3I(s)->hs.state == SSL3_ST_SW_SRVR_DONE_A) {
| 0-65 | ||||||||||||
1255 | if (!ssl3_handshake_msg_start(s, &cbb, &done,
| 0-65 | ||||||||||||
1256 | SSL3_MT_SERVER_DONE))
| 0-65 | ||||||||||||
1257 | goto err; never executed: goto err; | 0 | ||||||||||||
1258 | if (!ssl3_handshake_msg_finish(s, &cbb))
| 0-65 | ||||||||||||
1259 | goto err; never executed: goto err; | 0 | ||||||||||||
1260 | - | |||||||||||||
1261 | S3I(s)->hs.state = SSL3_ST_SW_SRVR_DONE_B; | - | ||||||||||||
1262 | } executed 65 times by 3 tests: end of block Executed by:
| 65 | ||||||||||||
1263 | - | |||||||||||||
1264 | /* SSL3_ST_SW_SRVR_DONE_B */ | - | ||||||||||||
1265 | return (ssl3_handshake_write(s)); executed 65 times by 3 tests: return (ssl3_handshake_write(s)); Executed by:
| 65 | ||||||||||||
1266 | - | |||||||||||||
1267 | err: | - | ||||||||||||
1268 | CBB_cleanup(&cbb); | - | ||||||||||||
1269 | - | |||||||||||||
1270 | return (-1); never executed: return (-1); | 0 | ||||||||||||
1271 | } | - | ||||||||||||
1272 | - | |||||||||||||
1273 | static int | - | ||||||||||||
1274 | ssl3_send_server_kex_dhe(SSL *s, CBB *cbb) | - | ||||||||||||
1275 | { | - | ||||||||||||
1276 | CBB dh_p, dh_g, dh_Ys; | - | ||||||||||||
1277 | DH *dh = NULL, *dhp; | - | ||||||||||||
1278 | unsigned char *data; | - | ||||||||||||
1279 | int al; | - | ||||||||||||
1280 | - | |||||||||||||
1281 | if (s->cert->dh_tmp_auto != 0) {
| 2-21 | ||||||||||||
1282 | if ((dhp = ssl_get_auto_dh(s)) == NULL) {
| 0-2 | ||||||||||||
1283 | al = SSL_AD_INTERNAL_ERROR; | - | ||||||||||||
1284 | SSLerror(s, ERR_R_INTERNAL_ERROR); | - | ||||||||||||
1285 | goto f_err; never executed: goto f_err; | 0 | ||||||||||||
1286 | } | - | ||||||||||||
1287 | } else executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||
1288 | dhp = s->cert->dh_tmp; executed 21 times by 1 test: dhp = s->cert->dh_tmp; Executed by:
| 21 | ||||||||||||
1289 | - | |||||||||||||
1290 | if (dhp == NULL && s->cert->dh_tmp_cb != NULL)
| 0-23 | ||||||||||||
1291 | dhp = s->cert->dh_tmp_cb(s, 0, never executed: dhp = s->cert->dh_tmp_cb(s, 0, 1024); | 0 | ||||||||||||
1292 | SSL_C_PKEYLENGTH(S3I(s)->hs.new_cipher)); never executed: dhp = s->cert->dh_tmp_cb(s, 0, 1024); | 0 | ||||||||||||
1293 | - | |||||||||||||
1294 | if (dhp == NULL) {
| 0-23 | ||||||||||||
1295 | al = SSL_AD_HANDSHAKE_FAILURE; | - | ||||||||||||
1296 | SSLerror(s, SSL_R_MISSING_TMP_DH_KEY); | - | ||||||||||||
1297 | goto f_err; never executed: goto f_err; | 0 | ||||||||||||
1298 | } | - | ||||||||||||
1299 | - | |||||||||||||
1300 | if (S3I(s)->tmp.dh != NULL) {
| 0-23 | ||||||||||||
1301 | SSLerror(s, ERR_R_INTERNAL_ERROR); | - | ||||||||||||
1302 | goto err; never executed: goto err; | 0 | ||||||||||||
1303 | } | - | ||||||||||||
1304 | - | |||||||||||||
1305 | if (s->cert->dh_tmp_auto != 0) {
| 2-21 | ||||||||||||
1306 | dh = dhp; | - | ||||||||||||
1307 | } else if ((dh = DHparams_dup(dhp)) == NULL) { executed 2 times by 1 test: end of block Executed by:
| 0-21 | ||||||||||||
1308 | SSLerror(s, ERR_R_DH_LIB); | - | ||||||||||||
1309 | goto err; never executed: goto err; | 0 | ||||||||||||
1310 | } | - | ||||||||||||
1311 | S3I(s)->tmp.dh = dh; | - | ||||||||||||
1312 | if (!DH_generate_key(dh)) {
| 0-23 | ||||||||||||
1313 | SSLerror(s, ERR_R_DH_LIB); | - | ||||||||||||
1314 | goto err; never executed: goto err; | 0 | ||||||||||||
1315 | } | - | ||||||||||||
1316 | - | |||||||||||||
1317 | /* | - | ||||||||||||
1318 | * Serialize the DH parameters and public key. | - | ||||||||||||
1319 | */ | - | ||||||||||||
1320 | if (!CBB_add_u16_length_prefixed(cbb, &dh_p))
| 0-23 | ||||||||||||
1321 | goto err; never executed: goto err; | 0 | ||||||||||||
1322 | if (!CBB_add_space(&dh_p, &data, BN_num_bytes(dh->p)))
| 0-23 | ||||||||||||
1323 | goto err; never executed: goto err; | 0 | ||||||||||||
1324 | BN_bn2bin(dh->p, data); | - | ||||||||||||
1325 | - | |||||||||||||
1326 | if (!CBB_add_u16_length_prefixed(cbb, &dh_g))
| 0-23 | ||||||||||||
1327 | goto err; never executed: goto err; | 0 | ||||||||||||
1328 | if (!CBB_add_space(&dh_g, &data, BN_num_bytes(dh->g)))
| 0-23 | ||||||||||||
1329 | goto err; never executed: goto err; | 0 | ||||||||||||
1330 | BN_bn2bin(dh->g, data); | - | ||||||||||||
1331 | - | |||||||||||||
1332 | if (!CBB_add_u16_length_prefixed(cbb, &dh_Ys))
| 0-23 | ||||||||||||
1333 | goto err; never executed: goto err; | 0 | ||||||||||||
1334 | if (!CBB_add_space(&dh_Ys, &data, BN_num_bytes(dh->pub_key)))
| 0-23 | ||||||||||||
1335 | goto err; never executed: goto err; | 0 | ||||||||||||
1336 | BN_bn2bin(dh->pub_key, data); | - | ||||||||||||
1337 | - | |||||||||||||
1338 | if (!CBB_flush(cbb))
| 0-23 | ||||||||||||
1339 | goto err; never executed: goto err; | 0 | ||||||||||||
1340 | - | |||||||||||||
1341 | return (1); executed 23 times by 2 tests: return (1); Executed by:
| 23 | ||||||||||||
1342 | - | |||||||||||||
1343 | f_err: | - | ||||||||||||
1344 | ssl3_send_alert(s, SSL3_AL_FATAL, al); | - | ||||||||||||
1345 | err: code before this statement never executed: err: | 0 | ||||||||||||
1346 | return (-1); never executed: return (-1); | 0 | ||||||||||||
1347 | } | - | ||||||||||||
1348 | - | |||||||||||||
1349 | static int | - | ||||||||||||
1350 | ssl3_send_server_kex_ecdhe_ecp(SSL *s, int nid, CBB *cbb) | - | ||||||||||||
1351 | { | - | ||||||||||||
1352 | const EC_GROUP *group; | - | ||||||||||||
1353 | const EC_POINT *pubkey; | - | ||||||||||||
1354 | unsigned char *data; | - | ||||||||||||
1355 | int encoded_len = 0; | - | ||||||||||||
1356 | int curve_id = 0; | - | ||||||||||||
1357 | BN_CTX *bn_ctx = NULL; | - | ||||||||||||
1358 | EC_KEY *ecdh; | - | ||||||||||||
1359 | CBB ecpoint; | - | ||||||||||||
1360 | int al; | - | ||||||||||||
1361 | - | |||||||||||||
1362 | /* | - | ||||||||||||
1363 | * Only named curves are supported in ECDH ephemeral key exchanges. | - | ||||||||||||
1364 | * For supported named curves, curve_id is non-zero. | - | ||||||||||||
1365 | */ | - | ||||||||||||
1366 | if ((curve_id = tls1_ec_nid2curve_id(nid)) == 0) {
| 0-23 | ||||||||||||
1367 | SSLerror(s, SSL_R_UNSUPPORTED_ELLIPTIC_CURVE); | - | ||||||||||||
1368 | goto err; never executed: goto err; | 0 | ||||||||||||
1369 | } | - | ||||||||||||
1370 | - | |||||||||||||
1371 | if (S3I(s)->tmp.ecdh != NULL) {
| 0-23 | ||||||||||||
1372 | SSLerror(s, ERR_R_INTERNAL_ERROR); | - | ||||||||||||
1373 | goto err; never executed: goto err; | 0 | ||||||||||||
1374 | } | - | ||||||||||||
1375 | - | |||||||||||||
1376 | if ((S3I(s)->tmp.ecdh = EC_KEY_new_by_curve_name(nid)) == NULL) {
| 0-23 | ||||||||||||
1377 | al = SSL_AD_HANDSHAKE_FAILURE; | - | ||||||||||||
1378 | SSLerror(s, SSL_R_MISSING_TMP_ECDH_KEY); | - | ||||||||||||
1379 | goto f_err; never executed: goto f_err; | 0 | ||||||||||||
1380 | } | - | ||||||||||||
1381 | ecdh = S3I(s)->tmp.ecdh; | - | ||||||||||||
1382 | - | |||||||||||||
1383 | if (!EC_KEY_generate_key(ecdh)) {
| 0-23 | ||||||||||||
1384 | SSLerror(s, ERR_R_ECDH_LIB); | - | ||||||||||||
1385 | goto err; never executed: goto err; | 0 | ||||||||||||
1386 | } | - | ||||||||||||
1387 | if ((group = EC_KEY_get0_group(ecdh)) == NULL ||
| 0-23 | ||||||||||||
1388 | (pubkey = EC_KEY_get0_public_key(ecdh)) == NULL ||
| 0-23 | ||||||||||||
1389 | EC_KEY_get0_private_key(ecdh) == NULL) {
| 0-23 | ||||||||||||
1390 | SSLerror(s, ERR_R_ECDH_LIB); | - | ||||||||||||
1391 | goto err; never executed: goto err; | 0 | ||||||||||||
1392 | } | - | ||||||||||||
1393 | - | |||||||||||||
1394 | /* | - | ||||||||||||
1395 | * Encode the public key. | - | ||||||||||||
1396 | */ | - | ||||||||||||
1397 | encoded_len = EC_POINT_point2oct(group, pubkey, | - | ||||||||||||
1398 | POINT_CONVERSION_UNCOMPRESSED, NULL, 0, NULL); | - | ||||||||||||
1399 | if (encoded_len == 0) {
| 0-23 | ||||||||||||
1400 | SSLerror(s, ERR_R_ECDH_LIB); | - | ||||||||||||
1401 | goto err; never executed: goto err; | 0 | ||||||||||||
1402 | } | - | ||||||||||||
1403 | if ((bn_ctx = BN_CTX_new()) == NULL) {
| 0-23 | ||||||||||||
1404 | SSLerror(s, ERR_R_MALLOC_FAILURE); | - | ||||||||||||
1405 | goto err; never executed: goto err; | 0 | ||||||||||||
1406 | } | - | ||||||||||||
1407 | - | |||||||||||||
1408 | /* | - | ||||||||||||
1409 | * Only named curves are supported in ECDH ephemeral key exchanges. | - | ||||||||||||
1410 | * In this case the ServerKeyExchange message has: | - | ||||||||||||
1411 | * [1 byte CurveType], [2 byte CurveName] | - | ||||||||||||
1412 | * [1 byte length of encoded point], followed by | - | ||||||||||||
1413 | * the actual encoded point itself. | - | ||||||||||||
1414 | */ | - | ||||||||||||
1415 | if (!CBB_add_u8(cbb, NAMED_CURVE_TYPE))
| 0-23 | ||||||||||||
1416 | goto err; never executed: goto err; | 0 | ||||||||||||
1417 | if (!CBB_add_u16(cbb, curve_id))
| 0-23 | ||||||||||||
1418 | goto err; never executed: goto err; | 0 | ||||||||||||
1419 | if (!CBB_add_u8_length_prefixed(cbb, &ecpoint))
| 0-23 | ||||||||||||
1420 | goto err; never executed: goto err; | 0 | ||||||||||||
1421 | if (!CBB_add_space(&ecpoint, &data, encoded_len))
| 0-23 | ||||||||||||
1422 | goto err; never executed: goto err; | 0 | ||||||||||||
1423 | if (EC_POINT_point2oct(group, pubkey, POINT_CONVERSION_UNCOMPRESSED,
| 0-23 | ||||||||||||
1424 | data, encoded_len, bn_ctx) == 0) {
| 0-23 | ||||||||||||
1425 | SSLerror(s, ERR_R_ECDH_LIB); | - | ||||||||||||
1426 | goto err; never executed: goto err; | 0 | ||||||||||||
1427 | } | - | ||||||||||||
1428 | if (!CBB_flush(cbb))
| 0-23 | ||||||||||||
1429 | goto err; never executed: goto err; | 0 | ||||||||||||
1430 | - | |||||||||||||
1431 | BN_CTX_free(bn_ctx); | - | ||||||||||||
1432 | - | |||||||||||||
1433 | return (1); executed 23 times by 1 test: return (1); Executed by:
| 23 | ||||||||||||
1434 | - | |||||||||||||
1435 | f_err: | - | ||||||||||||
1436 | ssl3_send_alert(s, SSL3_AL_FATAL, al); | - | ||||||||||||
1437 | err: code before this statement never executed: err: | 0 | ||||||||||||
1438 | BN_CTX_free(bn_ctx); | - | ||||||||||||
1439 | - | |||||||||||||
1440 | return (-1); never executed: return (-1); | 0 | ||||||||||||
1441 | } | - | ||||||||||||
1442 | - | |||||||||||||
1443 | static int | - | ||||||||||||
1444 | ssl3_send_server_kex_ecdhe_ecx(SSL *s, int nid, CBB *cbb) | - | ||||||||||||
1445 | { | - | ||||||||||||
1446 | uint8_t *public_key = NULL; | - | ||||||||||||
1447 | int curve_id; | - | ||||||||||||
1448 | CBB ecpoint; | - | ||||||||||||
1449 | int ret = -1; | - | ||||||||||||
1450 | - | |||||||||||||
1451 | /* Generate an X25519 key pair. */ | - | ||||||||||||
1452 | if (S3I(s)->tmp.x25519 != NULL) {
| 0-5 | ||||||||||||
1453 | SSLerror(s, ERR_R_INTERNAL_ERROR); | - | ||||||||||||
1454 | goto err; never executed: goto err; | 0 | ||||||||||||
1455 | } | - | ||||||||||||
1456 | if ((S3I(s)->tmp.x25519 = malloc(X25519_KEY_LENGTH)) == NULL)
| 0-5 | ||||||||||||
1457 | goto err; never executed: goto err; | 0 | ||||||||||||
1458 | if ((public_key = malloc(X25519_KEY_LENGTH)) == NULL)
| 0-5 | ||||||||||||
1459 | goto err; never executed: goto err; | 0 | ||||||||||||
1460 | X25519_keypair(public_key, S3I(s)->tmp.x25519); | - | ||||||||||||
1461 | - | |||||||||||||
1462 | /* Serialize public key. */ | - | ||||||||||||
1463 | if ((curve_id = tls1_ec_nid2curve_id(nid)) == 0) {
| 0-5 | ||||||||||||
1464 | SSLerror(s, SSL_R_UNSUPPORTED_ELLIPTIC_CURVE); | - | ||||||||||||
1465 | goto err; never executed: goto err; | 0 | ||||||||||||
1466 | } | - | ||||||||||||
1467 | - | |||||||||||||
1468 | if (!CBB_add_u8(cbb, NAMED_CURVE_TYPE))
| 0-5 | ||||||||||||
1469 | goto err; never executed: goto err; | 0 | ||||||||||||
1470 | if (!CBB_add_u16(cbb, curve_id))
| 0-5 | ||||||||||||
1471 | goto err; never executed: goto err; | 0 | ||||||||||||
1472 | if (!CBB_add_u8_length_prefixed(cbb, &ecpoint))
| 0-5 | ||||||||||||
1473 | goto err; never executed: goto err; | 0 | ||||||||||||
1474 | if (!CBB_add_bytes(&ecpoint, public_key, X25519_KEY_LENGTH))
| 0-5 | ||||||||||||
1475 | goto err; never executed: goto err; | 0 | ||||||||||||
1476 | if (!CBB_flush(cbb))
| 0-5 | ||||||||||||
1477 | goto err; never executed: goto err; | 0 | ||||||||||||
1478 | - | |||||||||||||
1479 | ret = 1; | - | ||||||||||||
1480 | - | |||||||||||||
1481 | err: code before this statement executed 5 times by 2 tests: err: Executed by:
| 5 | ||||||||||||
1482 | free(public_key); | - | ||||||||||||
1483 | - | |||||||||||||
1484 | return (ret); executed 5 times by 2 tests: return (ret); Executed by:
| 5 | ||||||||||||
1485 | } | - | ||||||||||||
1486 | - | |||||||||||||
1487 | static int | - | ||||||||||||
1488 | ssl3_send_server_kex_ecdhe(SSL *s, CBB *cbb) | - | ||||||||||||
1489 | { | - | ||||||||||||
1490 | int nid; | - | ||||||||||||
1491 | - | |||||||||||||
1492 | nid = tls1_get_shared_curve(s); | - | ||||||||||||
1493 | - | |||||||||||||
1494 | if (nid == NID_X25519)
| 5-23 | ||||||||||||
1495 | return ssl3_send_server_kex_ecdhe_ecx(s, nid, cbb); executed 5 times by 2 tests: return ssl3_send_server_kex_ecdhe_ecx(s, nid, cbb); Executed by:
| 5 | ||||||||||||
1496 | - | |||||||||||||
1497 | return ssl3_send_server_kex_ecdhe_ecp(s, nid, cbb); executed 23 times by 1 test: return ssl3_send_server_kex_ecdhe_ecp(s, nid, cbb); Executed by:
| 23 | ||||||||||||
1498 | } | - | ||||||||||||
1499 | - | |||||||||||||
1500 | int | - | ||||||||||||
1501 | ssl3_send_server_key_exchange(SSL *s) | - | ||||||||||||
1502 | { | - | ||||||||||||
1503 | CBB cbb, cbb_params, cbb_signature, server_kex; | - | ||||||||||||
1504 | unsigned char *signature = NULL; | - | ||||||||||||
1505 | unsigned int signature_len; | - | ||||||||||||
1506 | unsigned char *params = NULL; | - | ||||||||||||
1507 | size_t params_len; | - | ||||||||||||
1508 | const EVP_MD *md = NULL; | - | ||||||||||||
1509 | unsigned long type; | - | ||||||||||||
1510 | EVP_MD_CTX md_ctx; | - | ||||||||||||
1511 | EVP_PKEY *pkey; | - | ||||||||||||
1512 | int al; | - | ||||||||||||
1513 | - | |||||||||||||
1514 | memset(&cbb, 0, sizeof(cbb)); | - | ||||||||||||
1515 | memset(&cbb_params, 0, sizeof(cbb_params)); | - | ||||||||||||
1516 | - | |||||||||||||
1517 | EVP_MD_CTX_init(&md_ctx); | - | ||||||||||||
1518 | - | |||||||||||||
1519 | if (S3I(s)->hs.state == SSL3_ST_SW_KEY_EXCH_A) {
| 0-51 | ||||||||||||
1520 | - | |||||||||||||
1521 | if (!ssl3_handshake_msg_start(s, &cbb, &server_kex,
| 0-51 | ||||||||||||
1522 | SSL3_MT_SERVER_KEY_EXCHANGE))
| 0-51 | ||||||||||||
1523 | goto err; never executed: goto err; | 0 | ||||||||||||
1524 | - | |||||||||||||
1525 | if (!CBB_init(&cbb_params, 0))
| 0-51 | ||||||||||||
1526 | goto err; never executed: goto err; | 0 | ||||||||||||
1527 | - | |||||||||||||
1528 | type = S3I(s)->hs.new_cipher->algorithm_mkey; | - | ||||||||||||
1529 | if (type & SSL_kDHE) {
| 23-28 | ||||||||||||
1530 | if (ssl3_send_server_kex_dhe(s, &cbb_params) != 1)
| 0-23 | ||||||||||||
1531 | goto err; never executed: goto err; | 0 | ||||||||||||
1532 | } else if (type & SSL_kECDHE) { executed 23 times by 2 tests: end of block Executed by:
| 0-28 | ||||||||||||
1533 | if (ssl3_send_server_kex_ecdhe(s, &cbb_params) != 1)
| 0-28 | ||||||||||||
1534 | goto err; never executed: goto err; | 0 | ||||||||||||
1535 | } else { executed 28 times by 2 tests: end of block Executed by:
| 28 | ||||||||||||
1536 | al = SSL_AD_HANDSHAKE_FAILURE; | - | ||||||||||||
1537 | SSLerror(s, SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE); | - | ||||||||||||
1538 | goto f_err; never executed: goto f_err; | 0 | ||||||||||||
1539 | } | - | ||||||||||||
1540 | - | |||||||||||||
1541 | if (!CBB_finish(&cbb_params, ¶ms, ¶ms_len))
| 0-51 | ||||||||||||
1542 | goto err; never executed: goto err; | 0 | ||||||||||||
1543 | - | |||||||||||||
1544 | if (!CBB_add_bytes(&server_kex, params, params_len))
| 0-51 | ||||||||||||
1545 | goto err; never executed: goto err; | 0 | ||||||||||||
1546 | - | |||||||||||||
1547 | /* Add signature unless anonymous. */ | - | ||||||||||||
1548 | if (!(S3I(s)->hs.new_cipher->algorithm_auth & SSL_aNULL)) {
| 10-41 | ||||||||||||
1549 | if ((pkey = ssl_get_sign_pkey(s, S3I(s)->hs.new_cipher,
| 0-41 | ||||||||||||
1550 | &md)) == NULL) {
| 0-41 | ||||||||||||
1551 | al = SSL_AD_DECODE_ERROR; | - | ||||||||||||
1552 | goto f_err; never executed: goto f_err; | 0 | ||||||||||||
1553 | } | - | ||||||||||||
1554 | - | |||||||||||||
1555 | if (pkey->type == EVP_PKEY_RSA && !SSL_USE_SIGALGS(s))
| 0-41 | ||||||||||||
1556 | md = EVP_md5_sha1(); executed 13 times by 2 tests: md = EVP_md5_sha1(); Executed by:
| 13 | ||||||||||||
1557 | - | |||||||||||||
1558 | if (md == NULL) {
| 0-41 | ||||||||||||
1559 | /* Is this error check actually needed? */ | - | ||||||||||||
1560 | al = SSL_AD_HANDSHAKE_FAILURE; | - | ||||||||||||
1561 | SSLerror(s, SSL_R_UNKNOWN_PKEY_TYPE); | - | ||||||||||||
1562 | goto f_err; never executed: goto f_err; | 0 | ||||||||||||
1563 | } | - | ||||||||||||
1564 | - | |||||||||||||
1565 | /* Send signature algorithm. */ | - | ||||||||||||
1566 | if (SSL_USE_SIGALGS(s)) {
| 13-28 | ||||||||||||
1567 | if (!tls12_get_hashandsig(&server_kex, pkey, md)) {
| 0-28 | ||||||||||||
1568 | /* Should never happen */ | - | ||||||||||||
1569 | al = SSL_AD_INTERNAL_ERROR; | - | ||||||||||||
1570 | SSLerror(s, ERR_R_INTERNAL_ERROR); | - | ||||||||||||
1571 | goto f_err; never executed: goto f_err; | 0 | ||||||||||||
1572 | } | - | ||||||||||||
1573 | } executed 28 times by 3 tests: end of block Executed by:
| 28 | ||||||||||||
1574 | - | |||||||||||||
1575 | if ((signature = calloc(1, EVP_PKEY_size(pkey))) == NULL)
| 0-41 | ||||||||||||
1576 | goto err; never executed: goto err; | 0 | ||||||||||||
1577 | - | |||||||||||||
1578 | if (!EVP_SignInit_ex(&md_ctx, md, NULL))
| 0-41 | ||||||||||||
1579 | goto err; never executed: goto err; | 0 | ||||||||||||
1580 | if (!EVP_SignUpdate(&md_ctx, s->s3->client_random,
| 0-41 | ||||||||||||
1581 | SSL3_RANDOM_SIZE)) | - | ||||||||||||
1582 | goto err; never executed: goto err; | 0 | ||||||||||||
1583 | if (!EVP_SignUpdate(&md_ctx, s->s3->server_random,
| 0-41 | ||||||||||||
1584 | SSL3_RANDOM_SIZE)) | - | ||||||||||||
1585 | goto err; never executed: goto err; | 0 | ||||||||||||
1586 | if (!EVP_SignUpdate(&md_ctx, params, params_len))
| 0-41 | ||||||||||||
1587 | goto err; never executed: goto err; | 0 | ||||||||||||
1588 | if (!EVP_SignFinal(&md_ctx, signature, &signature_len,
| 0-41 | ||||||||||||
1589 | pkey)) {
| 0-41 | ||||||||||||
1590 | SSLerror(s, ERR_R_EVP_LIB); | - | ||||||||||||
1591 | goto err; never executed: goto err; | 0 | ||||||||||||
1592 | } | - | ||||||||||||
1593 | - | |||||||||||||
1594 | if (!CBB_add_u16_length_prefixed(&server_kex,
| 0-41 | ||||||||||||
1595 | &cbb_signature))
| 0-41 | ||||||||||||
1596 | goto err; never executed: goto err; | 0 | ||||||||||||
1597 | if (!CBB_add_bytes(&cbb_signature, signature,
| 0-41 | ||||||||||||
1598 | signature_len))
| 0-41 | ||||||||||||
1599 | goto err; never executed: goto err; | 0 | ||||||||||||
1600 | } executed 41 times by 3 tests: end of block Executed by:
| 41 | ||||||||||||
1601 | - | |||||||||||||
1602 | if (!ssl3_handshake_msg_finish(s, &cbb))
| 0-51 | ||||||||||||
1603 | goto err; never executed: goto err; | 0 | ||||||||||||
1604 | - | |||||||||||||
1605 | S3I(s)->hs.state = SSL3_ST_SW_KEY_EXCH_B; | - | ||||||||||||
1606 | } executed 51 times by 3 tests: end of block Executed by:
| 51 | ||||||||||||
1607 | - | |||||||||||||
1608 | EVP_MD_CTX_cleanup(&md_ctx); | - | ||||||||||||
1609 | free(params); | - | ||||||||||||
1610 | free(signature); | - | ||||||||||||
1611 | - | |||||||||||||
1612 | return (ssl3_handshake_write(s)); executed 51 times by 3 tests: return (ssl3_handshake_write(s)); Executed by:
| 51 | ||||||||||||
1613 | - | |||||||||||||
1614 | f_err: | - | ||||||||||||
1615 | ssl3_send_alert(s, SSL3_AL_FATAL, al); | - | ||||||||||||
1616 | err: code before this statement never executed: err: | 0 | ||||||||||||
1617 | CBB_cleanup(&cbb_params); | - | ||||||||||||
1618 | CBB_cleanup(&cbb); | - | ||||||||||||
1619 | EVP_MD_CTX_cleanup(&md_ctx); | - | ||||||||||||
1620 | free(params); | - | ||||||||||||
1621 | free(signature); | - | ||||||||||||
1622 | - | |||||||||||||
1623 | return (-1); never executed: return (-1); | 0 | ||||||||||||
1624 | } | - | ||||||||||||
1625 | - | |||||||||||||
1626 | int | - | ||||||||||||
1627 | ssl3_send_certificate_request(SSL *s) | - | ||||||||||||
1628 | { | - | ||||||||||||
1629 | CBB cbb, cert_request, cert_types, sigalgs, cert_auth, dn; | - | ||||||||||||
1630 | STACK_OF(X509_NAME) *sk = NULL; | - | ||||||||||||
1631 | X509_NAME *name; | - | ||||||||||||
1632 | int i; | - | ||||||||||||
1633 | - | |||||||||||||
1634 | /* | - | ||||||||||||
1635 | * Certificate Request - RFC 5246 section 7.4.4. | - | ||||||||||||
1636 | */ | - | ||||||||||||
1637 | - | |||||||||||||
1638 | memset(&cbb, 0, sizeof(cbb)); | - | ||||||||||||
1639 | - | |||||||||||||
1640 | if (S3I(s)->hs.state == SSL3_ST_SW_CERT_REQ_A) {
| 0-7 | ||||||||||||
1641 | if (!ssl3_handshake_msg_start(s, &cbb, &cert_request,
| 0-7 | ||||||||||||
1642 | SSL3_MT_CERTIFICATE_REQUEST))
| 0-7 | ||||||||||||
1643 | goto err; never executed: goto err; | 0 | ||||||||||||
1644 | - | |||||||||||||
1645 | if (!CBB_add_u8_length_prefixed(&cert_request, &cert_types))
| 0-7 | ||||||||||||
1646 | goto err; never executed: goto err; | 0 | ||||||||||||
1647 | if (!ssl3_get_req_cert_types(s, &cert_types))
| 0-7 | ||||||||||||
1648 | goto err; never executed: goto err; | 0 | ||||||||||||
1649 | - | |||||||||||||
1650 | if (SSL_USE_SIGALGS(s)) {
| 2-5 | ||||||||||||
1651 | unsigned char *sigalgs_data; | - | ||||||||||||
1652 | size_t sigalgs_len; | - | ||||||||||||
1653 | - | |||||||||||||
1654 | tls12_get_req_sig_algs(s, &sigalgs_data, &sigalgs_len); | - | ||||||||||||
1655 | - | |||||||||||||
1656 | if (!CBB_add_u16_length_prefixed(&cert_request, &sigalgs))
| 0-5 | ||||||||||||
1657 | goto err; never executed: goto err; | 0 | ||||||||||||
1658 | if (!CBB_add_bytes(&sigalgs, sigalgs_data, sigalgs_len))
| 0-5 | ||||||||||||
1659 | goto err; never executed: goto err; | 0 | ||||||||||||
1660 | } executed 5 times by 1 test: end of block Executed by:
| 5 | ||||||||||||
1661 | - | |||||||||||||
1662 | if (!CBB_add_u16_length_prefixed(&cert_request, &cert_auth))
| 0-7 | ||||||||||||
1663 | goto err; never executed: goto err; | 0 | ||||||||||||
1664 | - | |||||||||||||
1665 | sk = SSL_get_client_CA_list(s); | - | ||||||||||||
1666 | for (i = 0; i < sk_X509_NAME_num(sk); i++) {
| 0-7 | ||||||||||||
1667 | unsigned char *name_data; | - | ||||||||||||
1668 | size_t name_len; | - | ||||||||||||
1669 | - | |||||||||||||
1670 | name = sk_X509_NAME_value(sk, i); | - | ||||||||||||
1671 | name_len = i2d_X509_NAME(name, NULL); | - | ||||||||||||
1672 | - | |||||||||||||
1673 | if (!CBB_add_u16_length_prefixed(&cert_auth, &dn))
| 0 | ||||||||||||
1674 | goto err; never executed: goto err; | 0 | ||||||||||||
1675 | if (!CBB_add_space(&dn, &name_data, name_len))
| 0 | ||||||||||||
1676 | goto err; never executed: goto err; | 0 | ||||||||||||
1677 | if (i2d_X509_NAME(name, &name_data) != name_len)
| 0 | ||||||||||||
1678 | goto err; never executed: goto err; | 0 | ||||||||||||
1679 | } never executed: end of block | 0 | ||||||||||||
1680 | - | |||||||||||||
1681 | if (!ssl3_handshake_msg_finish(s, &cbb))
| 0-7 | ||||||||||||
1682 | goto err; never executed: goto err; | 0 | ||||||||||||
1683 | - | |||||||||||||
1684 | S3I(s)->hs.state = SSL3_ST_SW_CERT_REQ_B; | - | ||||||||||||
1685 | } executed 7 times by 1 test: end of block Executed by:
| 7 | ||||||||||||
1686 | - | |||||||||||||
1687 | /* SSL3_ST_SW_CERT_REQ_B */ | - | ||||||||||||
1688 | return (ssl3_handshake_write(s)); executed 7 times by 1 test: return (ssl3_handshake_write(s)); Executed by:
| 7 | ||||||||||||
1689 | - | |||||||||||||
1690 | err: | - | ||||||||||||
1691 | CBB_cleanup(&cbb); | - | ||||||||||||
1692 | - | |||||||||||||
1693 | return (-1); never executed: return (-1); | 0 | ||||||||||||
1694 | } | - | ||||||||||||
1695 | - | |||||||||||||
1696 | static int | - | ||||||||||||
1697 | ssl3_get_client_kex_rsa(SSL *s, CBS *cbs) | - | ||||||||||||
1698 | { | - | ||||||||||||
1699 | unsigned char fakekey[SSL_MAX_MASTER_KEY_LENGTH]; | - | ||||||||||||
1700 | unsigned char *pms = NULL; | - | ||||||||||||
1701 | unsigned char *p; | - | ||||||||||||
1702 | size_t pms_len = 0; | - | ||||||||||||
1703 | EVP_PKEY *pkey = NULL; | - | ||||||||||||
1704 | RSA *rsa = NULL; | - | ||||||||||||
1705 | CBS enc_pms; | - | ||||||||||||
1706 | int decrypt_len; | - | ||||||||||||
1707 | int al = -1; | - | ||||||||||||
1708 | - | |||||||||||||
1709 | arc4random_buf(fakekey, sizeof(fakekey)); | - | ||||||||||||
1710 | fakekey[0] = s->client_version >> 8; | - | ||||||||||||
1711 | fakekey[1] = s->client_version & 0xff; | - | ||||||||||||
1712 | - | |||||||||||||
1713 | pkey = s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey; | - | ||||||||||||
1714 | if ((pkey == NULL) || (pkey->type != EVP_PKEY_RSA) ||
| 0-14 | ||||||||||||
1715 | (pkey->pkey.rsa == NULL)) {
| 0-14 | ||||||||||||
1716 | al = SSL_AD_HANDSHAKE_FAILURE; | - | ||||||||||||
1717 | SSLerror(s, SSL_R_MISSING_RSA_CERTIFICATE); | - | ||||||||||||
1718 | goto f_err; never executed: goto f_err; | 0 | ||||||||||||
1719 | } | - | ||||||||||||
1720 | rsa = pkey->pkey.rsa; | - | ||||||||||||
1721 | - | |||||||||||||
1722 | pms_len = RSA_size(rsa); | - | ||||||||||||
1723 | if (pms_len < SSL_MAX_MASTER_KEY_LENGTH)
| 0-14 | ||||||||||||
1724 | goto err; never executed: goto err; | 0 | ||||||||||||
1725 | if ((pms = malloc(pms_len)) == NULL)
| 0-14 | ||||||||||||
1726 | goto err; never executed: goto err; | 0 | ||||||||||||
1727 | p = pms; | - | ||||||||||||
1728 | - | |||||||||||||
1729 | if (!CBS_get_u16_length_prefixed(cbs, &enc_pms))
| 0-14 | ||||||||||||
1730 | goto truncated; never executed: goto truncated; | 0 | ||||||||||||
1731 | if (CBS_len(cbs) != 0 || CBS_len(&enc_pms) != RSA_size(rsa)) {
| 0-14 | ||||||||||||
1732 | SSLerror(s, SSL_R_TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG); | - | ||||||||||||
1733 | goto err; never executed: goto err; | 0 | ||||||||||||
1734 | } | - | ||||||||||||
1735 | - | |||||||||||||
1736 | decrypt_len = RSA_private_decrypt(CBS_len(&enc_pms), CBS_data(&enc_pms), | - | ||||||||||||
1737 | pms, rsa, RSA_PKCS1_PADDING); | - | ||||||||||||
1738 | - | |||||||||||||
1739 | ERR_clear_error(); | - | ||||||||||||
1740 | - | |||||||||||||
1741 | if (decrypt_len != SSL_MAX_MASTER_KEY_LENGTH) {
| 0-14 | ||||||||||||
1742 | al = SSL_AD_DECODE_ERROR; | - | ||||||||||||
1743 | /* SSLerror(s, SSL_R_BAD_RSA_DECRYPT); */ | - | ||||||||||||
1744 | } never executed: end of block | 0 | ||||||||||||
1745 | - | |||||||||||||
1746 | if ((al == -1) && !((pms[0] == (s->client_version >> 8)) &&
| 0-14 | ||||||||||||
1747 | (pms[1] == (s->client_version & 0xff)))) {
| 0-14 | ||||||||||||
1748 | /* | - | ||||||||||||
1749 | * The premaster secret must contain the same version number | - | ||||||||||||
1750 | * as the ClientHello to detect version rollback attacks | - | ||||||||||||
1751 | * (strangely, the protocol does not offer such protection for | - | ||||||||||||
1752 | * DH ciphersuites). | - | ||||||||||||
1753 | * | - | ||||||||||||
1754 | * The Klima-Pokorny-Rosa extension of Bleichenbacher's attack | - | ||||||||||||
1755 | * (http://eprint.iacr.org/2003/052/) exploits the version | - | ||||||||||||
1756 | * number check as a "bad version oracle" -- an alert would | - | ||||||||||||
1757 | * reveal that the plaintext corresponding to some ciphertext | - | ||||||||||||
1758 | * made up by the adversary is properly formatted except that | - | ||||||||||||
1759 | * the version number is wrong. To avoid such attacks, we should | - | ||||||||||||
1760 | * treat this just like any other decryption error. | - | ||||||||||||
1761 | */ | - | ||||||||||||
1762 | al = SSL_AD_DECODE_ERROR; | - | ||||||||||||
1763 | /* SSLerror(s, SSL_R_BAD_PROTOCOL_VERSION_NUMBER); */ | - | ||||||||||||
1764 | } never executed: end of block | 0 | ||||||||||||
1765 | - | |||||||||||||
1766 | if (al != -1) {
| 0-14 | ||||||||||||
1767 | /* | - | ||||||||||||
1768 | * Some decryption failure -- use random value instead | - | ||||||||||||
1769 | * as countermeasure against Bleichenbacher's attack | - | ||||||||||||
1770 | * on PKCS #1 v1.5 RSA padding (see RFC 2246, | - | ||||||||||||
1771 | * section 7.4.7.1). | - | ||||||||||||
1772 | */ | - | ||||||||||||
1773 | p = fakekey; | - | ||||||||||||
1774 | } never executed: end of block | 0 | ||||||||||||
1775 | - | |||||||||||||
1776 | s->session->master_key_length = | - | ||||||||||||
1777 | tls1_generate_master_secret(s, | - | ||||||||||||
1778 | s->session->master_key, p, SSL_MAX_MASTER_KEY_LENGTH); | - | ||||||||||||
1779 | - | |||||||||||||
1780 | freezero(pms, pms_len); | - | ||||||||||||
1781 | - | |||||||||||||
1782 | return (1); executed 14 times by 1 test: return (1); Executed by:
| 14 | ||||||||||||
1783 | - | |||||||||||||
1784 | truncated: | - | ||||||||||||
1785 | al = SSL_AD_DECODE_ERROR; | - | ||||||||||||
1786 | SSLerror(s, SSL_R_BAD_PACKET_LENGTH); | - | ||||||||||||
1787 | f_err: code before this statement never executed: f_err: | 0 | ||||||||||||
1788 | ssl3_send_alert(s, SSL3_AL_FATAL, al); | - | ||||||||||||
1789 | err: code before this statement never executed: err: | 0 | ||||||||||||
1790 | freezero(pms, pms_len); | - | ||||||||||||
1791 | - | |||||||||||||
1792 | return (-1); never executed: return (-1); | 0 | ||||||||||||
1793 | } | - | ||||||||||||
1794 | - | |||||||||||||
1795 | static int | - | ||||||||||||
1796 | ssl3_get_client_kex_dhe(SSL *s, CBS *cbs) | - | ||||||||||||
1797 | { | - | ||||||||||||
1798 | int key_size = 0, key_len, al; | - | ||||||||||||
1799 | unsigned char *key = NULL; | - | ||||||||||||
1800 | BIGNUM *bn = NULL; | - | ||||||||||||
1801 | CBS dh_Yc; | - | ||||||||||||
1802 | DH *dh; | - | ||||||||||||
1803 | - | |||||||||||||
1804 | if (!CBS_get_u16_length_prefixed(cbs, &dh_Yc))
| 0-21 | ||||||||||||
1805 | goto truncated; never executed: goto truncated; | 0 | ||||||||||||
1806 | if (CBS_len(cbs) != 0)
| 0-21 | ||||||||||||
1807 | goto truncated; never executed: goto truncated; | 0 | ||||||||||||
1808 | - | |||||||||||||
1809 | if (S3I(s)->tmp.dh == NULL) {
| 0-21 | ||||||||||||
1810 | al = SSL_AD_HANDSHAKE_FAILURE; | - | ||||||||||||
1811 | SSLerror(s, SSL_R_MISSING_TMP_DH_KEY); | - | ||||||||||||
1812 | goto f_err; never executed: goto f_err; | 0 | ||||||||||||
1813 | } | - | ||||||||||||
1814 | dh = S3I(s)->tmp.dh; | - | ||||||||||||
1815 | - | |||||||||||||
1816 | if ((bn = BN_bin2bn(CBS_data(&dh_Yc), CBS_len(&dh_Yc), NULL)) == NULL) {
| 0-21 | ||||||||||||
1817 | SSLerror(s, SSL_R_BN_LIB); | - | ||||||||||||
1818 | goto err; never executed: goto err; | 0 | ||||||||||||
1819 | } | - | ||||||||||||
1820 | - | |||||||||||||
1821 | if ((key_size = DH_size(dh)) <= 0) {
| 0-21 | ||||||||||||
1822 | SSLerror(s, ERR_R_DH_LIB); | - | ||||||||||||
1823 | goto err; never executed: goto err; | 0 | ||||||||||||
1824 | } | - | ||||||||||||
1825 | if ((key = malloc(key_size)) == NULL) {
| 0-21 | ||||||||||||
1826 | SSLerror(s, ERR_R_MALLOC_FAILURE); | - | ||||||||||||
1827 | goto err; never executed: goto err; | 0 | ||||||||||||
1828 | } | - | ||||||||||||
1829 | if ((key_len = DH_compute_key(key, bn, dh)) <= 0) {
| 0-21 | ||||||||||||
1830 | SSLerror(s, ERR_R_DH_LIB); | - | ||||||||||||
1831 | goto err; never executed: goto err; | 0 | ||||||||||||
1832 | } | - | ||||||||||||
1833 | - | |||||||||||||
1834 | s->session->master_key_length = tls1_generate_master_secret(s, | - | ||||||||||||
1835 | s->session->master_key, key, key_len); | - | ||||||||||||
1836 | - | |||||||||||||
1837 | DH_free(S3I(s)->tmp.dh); | - | ||||||||||||
1838 | S3I(s)->tmp.dh = NULL; | - | ||||||||||||
1839 | - | |||||||||||||
1840 | freezero(key, key_size); | - | ||||||||||||
1841 | BN_clear_free(bn); | - | ||||||||||||
1842 | - | |||||||||||||
1843 | return (1); executed 21 times by 1 test: return (1); Executed by:
| 21 | ||||||||||||
1844 | - | |||||||||||||
1845 | truncated: | - | ||||||||||||
1846 | al = SSL_AD_DECODE_ERROR; | - | ||||||||||||
1847 | SSLerror(s, SSL_R_BAD_PACKET_LENGTH); | - | ||||||||||||
1848 | f_err: code before this statement never executed: f_err: | 0 | ||||||||||||
1849 | ssl3_send_alert(s, SSL3_AL_FATAL, al); | - | ||||||||||||
1850 | err: code before this statement never executed: err: | 0 | ||||||||||||
1851 | freezero(key, key_size); | - | ||||||||||||
1852 | BN_clear_free(bn); | - | ||||||||||||
1853 | - | |||||||||||||
1854 | return (-1); never executed: return (-1); | 0 | ||||||||||||
1855 | } | - | ||||||||||||
1856 | - | |||||||||||||
1857 | static int | - | ||||||||||||
1858 | ssl3_get_client_kex_ecdhe_ecp(SSL *s, CBS *cbs) | - | ||||||||||||
1859 | { | - | ||||||||||||
1860 | unsigned char *key = NULL; | - | ||||||||||||
1861 | int key_size = 0, key_len; | - | ||||||||||||
1862 | EC_POINT *point = NULL; | - | ||||||||||||
1863 | BN_CTX *bn_ctx = NULL; | - | ||||||||||||
1864 | const EC_GROUP *group; | - | ||||||||||||
1865 | EC_KEY *ecdh; | - | ||||||||||||
1866 | CBS public; | - | ||||||||||||
1867 | int ret = -1; | - | ||||||||||||
1868 | - | |||||||||||||
1869 | if (!CBS_get_u8_length_prefixed(cbs, &public))
| 0-23 | ||||||||||||
1870 | goto err; never executed: goto err; | 0 | ||||||||||||
1871 | if (CBS_len(cbs) != 0)
| 0-23 | ||||||||||||
1872 | goto err; never executed: goto err; | 0 | ||||||||||||
1873 | - | |||||||||||||
1874 | /* | - | ||||||||||||
1875 | * Use the ephemeral values we saved when generating the | - | ||||||||||||
1876 | * ServerKeyExchange message. | - | ||||||||||||
1877 | */ | - | ||||||||||||
1878 | if ((ecdh = S3I(s)->tmp.ecdh) == NULL) {
| 0-23 | ||||||||||||
1879 | SSLerror(s, ERR_R_INTERNAL_ERROR); | - | ||||||||||||
1880 | goto err; never executed: goto err; | 0 | ||||||||||||
1881 | } | - | ||||||||||||
1882 | group = EC_KEY_get0_group(ecdh); | - | ||||||||||||
1883 | - | |||||||||||||
1884 | /* | - | ||||||||||||
1885 | * Get client's public key from encoded point in the ClientKeyExchange | - | ||||||||||||
1886 | * message. | - | ||||||||||||
1887 | */ | - | ||||||||||||
1888 | if ((bn_ctx = BN_CTX_new()) == NULL) {
| 0-23 | ||||||||||||
1889 | SSLerror(s, ERR_R_MALLOC_FAILURE); | - | ||||||||||||
1890 | goto err; never executed: goto err; | 0 | ||||||||||||
1891 | } | - | ||||||||||||
1892 | if ((point = EC_POINT_new(group)) == NULL) {
| 0-23 | ||||||||||||
1893 | SSLerror(s, ERR_R_MALLOC_FAILURE); | - | ||||||||||||
1894 | goto err; never executed: goto err; | 0 | ||||||||||||
1895 | } | - | ||||||||||||
1896 | if (EC_POINT_oct2point(group, point, CBS_data(&public),
| 0-23 | ||||||||||||
1897 | CBS_len(&public), bn_ctx) == 0) {
| 0-23 | ||||||||||||
1898 | SSLerror(s, ERR_R_EC_LIB); | - | ||||||||||||
1899 | goto err; never executed: goto err; | 0 | ||||||||||||
1900 | } | - | ||||||||||||
1901 | - | |||||||||||||
1902 | /* Compute the shared pre-master secret */ | - | ||||||||||||
1903 | if ((key_size = ECDH_size(ecdh)) <= 0) {
| 0-23 | ||||||||||||
1904 | SSLerror(s, ERR_R_ECDH_LIB); | - | ||||||||||||
1905 | goto err; never executed: goto err; | 0 | ||||||||||||
1906 | } | - | ||||||||||||
1907 | if ((key = malloc(key_size)) == NULL) {
| 0-23 | ||||||||||||
1908 | SSLerror(s, ERR_R_MALLOC_FAILURE); | - | ||||||||||||
1909 | goto err; never executed: goto err; | 0 | ||||||||||||
1910 | } | - | ||||||||||||
1911 | if ((key_len = ECDH_compute_key(key, key_size, point, ecdh,
| 0-23 | ||||||||||||
1912 | NULL)) <= 0) {
| 0-23 | ||||||||||||
1913 | SSLerror(s, ERR_R_ECDH_LIB); | - | ||||||||||||
1914 | goto err; never executed: goto err; | 0 | ||||||||||||
1915 | } | - | ||||||||||||
1916 | - | |||||||||||||
1917 | /* Compute the master secret */ | - | ||||||||||||
1918 | s->session->master_key_length = tls1_generate_master_secret(s, | - | ||||||||||||
1919 | s->session->master_key, key, key_len); | - | ||||||||||||
1920 | - | |||||||||||||
1921 | EC_KEY_free(S3I(s)->tmp.ecdh); | - | ||||||||||||
1922 | S3I(s)->tmp.ecdh = NULL; | - | ||||||||||||
1923 | - | |||||||||||||
1924 | ret = 1; | - | ||||||||||||
1925 | - | |||||||||||||
1926 | err: code before this statement executed 23 times by 1 test: err: Executed by:
| 23 | ||||||||||||
1927 | freezero(key, key_size); | - | ||||||||||||
1928 | EC_POINT_free(point); | - | ||||||||||||
1929 | BN_CTX_free(bn_ctx); | - | ||||||||||||
1930 | - | |||||||||||||
1931 | return (ret); executed 23 times by 1 test: return (ret); Executed by:
| 23 | ||||||||||||
1932 | } | - | ||||||||||||
1933 | - | |||||||||||||
1934 | static int | - | ||||||||||||
1935 | ssl3_get_client_kex_ecdhe_ecx(SSL *s, CBS *cbs) | - | ||||||||||||
1936 | { | - | ||||||||||||
1937 | uint8_t *shared_key = NULL; | - | ||||||||||||
1938 | CBS ecpoint; | - | ||||||||||||
1939 | int ret = -1; | - | ||||||||||||
1940 | - | |||||||||||||
1941 | if (!CBS_get_u8_length_prefixed(cbs, &ecpoint))
| 0-5 | ||||||||||||
1942 | goto err; never executed: goto err; | 0 | ||||||||||||
1943 | if (CBS_len(cbs) != 0)
| 0-5 | ||||||||||||
1944 | goto err; never executed: goto err; | 0 | ||||||||||||
1945 | if (CBS_len(&ecpoint) != X25519_KEY_LENGTH)
| 0-5 | ||||||||||||
1946 | goto err; never executed: goto err; | 0 | ||||||||||||
1947 | - | |||||||||||||
1948 | if ((shared_key = malloc(X25519_KEY_LENGTH)) == NULL)
| 0-5 | ||||||||||||
1949 | goto err; never executed: goto err; | 0 | ||||||||||||
1950 | if (!X25519(shared_key, S3I(s)->tmp.x25519, CBS_data(&ecpoint)))
| 0-5 | ||||||||||||
1951 | goto err; never executed: goto err; | 0 | ||||||||||||
1952 | - | |||||||||||||
1953 | freezero(S3I(s)->tmp.x25519, X25519_KEY_LENGTH); | - | ||||||||||||
1954 | S3I(s)->tmp.x25519 = NULL; | - | ||||||||||||
1955 | - | |||||||||||||
1956 | s->session->master_key_length = | - | ||||||||||||
1957 | tls1_generate_master_secret( | - | ||||||||||||
1958 | s, s->session->master_key, shared_key, X25519_KEY_LENGTH); | - | ||||||||||||
1959 | - | |||||||||||||
1960 | ret = 1; | - | ||||||||||||
1961 | - | |||||||||||||
1962 | err: code before this statement executed 5 times by 2 tests: err: Executed by:
| 5 | ||||||||||||
1963 | freezero(shared_key, X25519_KEY_LENGTH); | - | ||||||||||||
1964 | - | |||||||||||||
1965 | return (ret); executed 5 times by 2 tests: return (ret); Executed by:
| 5 | ||||||||||||
1966 | } | - | ||||||||||||
1967 | - | |||||||||||||
1968 | static int | - | ||||||||||||
1969 | ssl3_get_client_kex_ecdhe(SSL *s, CBS *cbs) | - | ||||||||||||
1970 | { | - | ||||||||||||
1971 | if (S3I(s)->tmp.x25519 != NULL)
| 5-23 | ||||||||||||
1972 | return ssl3_get_client_kex_ecdhe_ecx(s, cbs); executed 5 times by 2 tests: return ssl3_get_client_kex_ecdhe_ecx(s, cbs); Executed by:
| 5 | ||||||||||||
1973 | - | |||||||||||||
1974 | return ssl3_get_client_kex_ecdhe_ecp(s, cbs); executed 23 times by 1 test: return ssl3_get_client_kex_ecdhe_ecp(s, cbs); Executed by:
| 23 | ||||||||||||
1975 | } | - | ||||||||||||
1976 | - | |||||||||||||
1977 | static int | - | ||||||||||||
1978 | ssl3_get_client_kex_gost(SSL *s, CBS *cbs) | - | ||||||||||||
1979 | { | - | ||||||||||||
1980 | EVP_PKEY_CTX *pkey_ctx; | - | ||||||||||||
1981 | EVP_PKEY *client_pub_pkey = NULL, *pk = NULL; | - | ||||||||||||
1982 | unsigned char premaster_secret[32]; | - | ||||||||||||
1983 | unsigned long alg_a; | - | ||||||||||||
1984 | size_t outlen = 32; | - | ||||||||||||
1985 | CBS gostblob; | - | ||||||||||||
1986 | int al; | - | ||||||||||||
1987 | int ret = 0; | - | ||||||||||||
1988 | - | |||||||||||||
1989 | /* Get our certificate private key*/ | - | ||||||||||||
1990 | alg_a = S3I(s)->hs.new_cipher->algorithm_auth; | - | ||||||||||||
1991 | if (alg_a & SSL_aGOST01)
| 0 | ||||||||||||
1992 | pk = s->cert->pkeys[SSL_PKEY_GOST01].privatekey; never executed: pk = s->cert->pkeys[4].privatekey; | 0 | ||||||||||||
1993 | - | |||||||||||||
1994 | if ((pkey_ctx = EVP_PKEY_CTX_new(pk, NULL)) == NULL)
| 0 | ||||||||||||
1995 | goto err; never executed: goto err; | 0 | ||||||||||||
1996 | if (EVP_PKEY_decrypt_init(pkey_ctx) <= 0)
| 0 | ||||||||||||
1997 | goto gerr; never executed: goto gerr; | 0 | ||||||||||||
1998 | - | |||||||||||||
1999 | /* | - | ||||||||||||
2000 | * If client certificate is present and is of the same type, | - | ||||||||||||
2001 | * maybe use it for key exchange. | - | ||||||||||||
2002 | * Don't mind errors from EVP_PKEY_derive_set_peer, because | - | ||||||||||||
2003 | * it is completely valid to use a client certificate for | - | ||||||||||||
2004 | * authorization only. | - | ||||||||||||
2005 | */ | - | ||||||||||||
2006 | if ((client_pub_pkey = X509_get_pubkey(s->session->peer)) != NULL) {
| 0 | ||||||||||||
2007 | if (EVP_PKEY_derive_set_peer(pkey_ctx,
| 0 | ||||||||||||
2008 | client_pub_pkey) <= 0)
| 0 | ||||||||||||
2009 | ERR_clear_error(); never executed: ERR_clear_error(); | 0 | ||||||||||||
2010 | } never executed: end of block | 0 | ||||||||||||
2011 | - | |||||||||||||
2012 | /* Decrypt session key */ | - | ||||||||||||
2013 | if (!CBS_get_asn1(cbs, &gostblob, CBS_ASN1_SEQUENCE))
| 0 | ||||||||||||
2014 | goto truncated; never executed: goto truncated; | 0 | ||||||||||||
2015 | if (CBS_len(cbs) != 0)
| 0 | ||||||||||||
2016 | goto truncated; never executed: goto truncated; | 0 | ||||||||||||
2017 | if (EVP_PKEY_decrypt(pkey_ctx, premaster_secret, &outlen,
| 0 | ||||||||||||
2018 | CBS_data(&gostblob), CBS_len(&gostblob)) <= 0) {
| 0 | ||||||||||||
2019 | SSLerror(s, SSL_R_DECRYPTION_FAILED); | - | ||||||||||||
2020 | goto gerr; never executed: goto gerr; | 0 | ||||||||||||
2021 | } | - | ||||||||||||
2022 | - | |||||||||||||
2023 | /* Generate master secret */ | - | ||||||||||||
2024 | s->session->master_key_length = | - | ||||||||||||
2025 | tls1_generate_master_secret( | - | ||||||||||||
2026 | s, s->session->master_key, premaster_secret, 32); | - | ||||||||||||
2027 | - | |||||||||||||
2028 | /* Check if pubkey from client certificate was used */ | - | ||||||||||||
2029 | if (EVP_PKEY_CTX_ctrl(pkey_ctx, -1, -1,
| 0 | ||||||||||||
2030 | EVP_PKEY_CTRL_PEER_KEY, 2, NULL) > 0)
| 0 | ||||||||||||
2031 | ret = 2; never executed: ret = 2; | 0 | ||||||||||||
2032 | else | - | ||||||||||||
2033 | ret = 1; never executed: ret = 1; | 0 | ||||||||||||
2034 | gerr: code before this statement never executed: gerr: | 0 | ||||||||||||
2035 | EVP_PKEY_free(client_pub_pkey); | - | ||||||||||||
2036 | EVP_PKEY_CTX_free(pkey_ctx); | - | ||||||||||||
2037 | if (ret)
| 0 | ||||||||||||
2038 | return (ret); never executed: return (ret); | 0 | ||||||||||||
2039 | else | - | ||||||||||||
2040 | goto err; never executed: goto err; | 0 | ||||||||||||
2041 | - | |||||||||||||
2042 | truncated: | - | ||||||||||||
2043 | al = SSL_AD_DECODE_ERROR; | - | ||||||||||||
2044 | SSLerror(s, SSL_R_BAD_PACKET_LENGTH); | - | ||||||||||||
2045 | ssl3_send_alert(s, SSL3_AL_FATAL, al); | - | ||||||||||||
2046 | err: code before this statement never executed: err: | 0 | ||||||||||||
2047 | return (-1); never executed: return (-1); | 0 | ||||||||||||
2048 | } | - | ||||||||||||
2049 | - | |||||||||||||
2050 | int | - | ||||||||||||
2051 | ssl3_get_client_key_exchange(SSL *s) | - | ||||||||||||
2052 | { | - | ||||||||||||
2053 | unsigned long alg_k; | - | ||||||||||||
2054 | int al, ok; | - | ||||||||||||
2055 | CBS cbs; | - | ||||||||||||
2056 | long n; | - | ||||||||||||
2057 | - | |||||||||||||
2058 | /* 2048 maxlen is a guess. How long a key does that permit? */ | - | ||||||||||||
2059 | n = s->method->internal->ssl_get_message(s, SSL3_ST_SR_KEY_EXCH_A, | - | ||||||||||||
2060 | SSL3_ST_SR_KEY_EXCH_B, SSL3_MT_CLIENT_KEY_EXCHANGE, 2048, &ok); | - | ||||||||||||
2061 | if (!ok)
| 63-271 | ||||||||||||
2062 | return ((int)n); executed 271 times by 3 tests: return ((int)n); Executed by:
| 271 | ||||||||||||
2063 | - | |||||||||||||
2064 | if (n < 0)
| 0-63 | ||||||||||||
2065 | goto err; never executed: goto err; | 0 | ||||||||||||
2066 | - | |||||||||||||
2067 | CBS_init(&cbs, s->internal->init_msg, n); | - | ||||||||||||
2068 | - | |||||||||||||
2069 | alg_k = S3I(s)->hs.new_cipher->algorithm_mkey; | - | ||||||||||||
2070 | - | |||||||||||||
2071 | if (alg_k & SSL_kRSA) {
| 14-49 | ||||||||||||
2072 | if (ssl3_get_client_kex_rsa(s, &cbs) != 1)
| 0-14 | ||||||||||||
2073 | goto err; never executed: goto err; | 0 | ||||||||||||
2074 | } else if (alg_k & SSL_kDHE) { executed 14 times by 1 test: end of block Executed by:
| 14-28 | ||||||||||||
2075 | if (ssl3_get_client_kex_dhe(s, &cbs) != 1)
| 0-21 | ||||||||||||
2076 | goto err; never executed: goto err; | 0 | ||||||||||||
2077 | } else if (alg_k & SSL_kECDHE) { executed 21 times by 1 test: end of block Executed by:
| 0-28 | ||||||||||||
2078 | if (ssl3_get_client_kex_ecdhe(s, &cbs) != 1)
| 0-28 | ||||||||||||
2079 | goto err; never executed: goto err; | 0 | ||||||||||||
2080 | } else if (alg_k & SSL_kGOST) { executed 28 times by 2 tests: end of block Executed by:
| 0-28 | ||||||||||||
2081 | if (ssl3_get_client_kex_gost(s, &cbs) != 1)
| 0 | ||||||||||||
2082 | goto err; never executed: goto err; | 0 | ||||||||||||
2083 | } else { never executed: end of block | 0 | ||||||||||||
2084 | al = SSL_AD_HANDSHAKE_FAILURE; | - | ||||||||||||
2085 | SSLerror(s, SSL_R_UNKNOWN_CIPHER_TYPE); | - | ||||||||||||
2086 | goto f_err; never executed: goto f_err; | 0 | ||||||||||||
2087 | } | - | ||||||||||||
2088 | - | |||||||||||||
2089 | if (CBS_len(&cbs) != 0) {
| 0-63 | ||||||||||||
2090 | al = SSL_AD_DECODE_ERROR; | - | ||||||||||||
2091 | SSLerror(s, SSL_R_BAD_PACKET_LENGTH); | - | ||||||||||||
2092 | goto f_err; never executed: goto f_err; | 0 | ||||||||||||
2093 | } | - | ||||||||||||
2094 | - | |||||||||||||
2095 | return (1); executed 63 times by 2 tests: return (1); Executed by:
| 63 | ||||||||||||
2096 | - | |||||||||||||
2097 | f_err: | - | ||||||||||||
2098 | ssl3_send_alert(s, SSL3_AL_FATAL, al); | - | ||||||||||||
2099 | err: code before this statement never executed: err: | 0 | ||||||||||||
2100 | return (-1); never executed: return (-1); | 0 | ||||||||||||
2101 | } | - | ||||||||||||
2102 | - | |||||||||||||
2103 | int | - | ||||||||||||
2104 | ssl3_get_cert_verify(SSL *s) | - | ||||||||||||
2105 | { | - | ||||||||||||
2106 | CBS cbs, signature; | - | ||||||||||||
2107 | const EVP_MD *md = NULL; | - | ||||||||||||
2108 | EVP_PKEY *pkey = NULL; | - | ||||||||||||
2109 | X509 *peer = NULL; | - | ||||||||||||
2110 | EVP_MD_CTX mctx; | - | ||||||||||||
2111 | uint8_t hash_id, sig_id; | - | ||||||||||||
2112 | int al, ok, sigalg, verify; | - | ||||||||||||
2113 | int type = 0; | - | ||||||||||||
2114 | int ret = 0; | - | ||||||||||||
2115 | long hdatalen; | - | ||||||||||||
2116 | void *hdata; | - | ||||||||||||
2117 | long n; | - | ||||||||||||
2118 | - | |||||||||||||
2119 | EVP_MD_CTX_init(&mctx); | - | ||||||||||||
2120 | - | |||||||||||||
2121 | n = s->method->internal->ssl_get_message(s, SSL3_ST_SR_CERT_VRFY_A, | - | ||||||||||||
2122 | SSL3_ST_SR_CERT_VRFY_B, -1, SSL3_RT_MAX_PLAIN_LENGTH, &ok); | - | ||||||||||||
2123 | if (!ok)
| 63-324 | ||||||||||||
2124 | return ((int)n); executed 324 times by 1 test: return ((int)n); Executed by:
| 324 | ||||||||||||
2125 | - | |||||||||||||
2126 | if (n < 0)
| 0-63 | ||||||||||||
2127 | goto err; never executed: goto err; | 0 | ||||||||||||
2128 | - | |||||||||||||
2129 | CBS_init(&cbs, s->internal->init_msg, n); | - | ||||||||||||
2130 | - | |||||||||||||
2131 | if (s->session->peer != NULL) {
| 7-56 | ||||||||||||
2132 | peer = s->session->peer; | - | ||||||||||||
2133 | pkey = X509_get_pubkey(peer); | - | ||||||||||||
2134 | type = X509_certificate_type(peer, pkey); | - | ||||||||||||
2135 | } executed 7 times by 1 test: end of block Executed by:
| 7 | ||||||||||||
2136 | - | |||||||||||||
2137 | if (S3I(s)->tmp.message_type != SSL3_MT_CERTIFICATE_VERIFY) {
| 7-56 | ||||||||||||
2138 | S3I(s)->tmp.reuse_message = 1; | - | ||||||||||||
2139 | if (peer != NULL) {
| 0-56 | ||||||||||||
2140 | al = SSL_AD_UNEXPECTED_MESSAGE; | - | ||||||||||||
2141 | SSLerror(s, SSL_R_MISSING_VERIFY_MESSAGE); | - | ||||||||||||
2142 | goto f_err; never executed: goto f_err; | 0 | ||||||||||||
2143 | } | - | ||||||||||||
2144 | ret = 1; | - | ||||||||||||
2145 | goto end; executed 56 times by 2 tests: goto end; Executed by:
| 56 | ||||||||||||
2146 | } | - | ||||||||||||
2147 | - | |||||||||||||
2148 | if (peer == NULL) {
| 0-7 | ||||||||||||
2149 | SSLerror(s, SSL_R_NO_CLIENT_CERT_RECEIVED); | - | ||||||||||||
2150 | al = SSL_AD_UNEXPECTED_MESSAGE; | - | ||||||||||||
2151 | goto f_err; never executed: goto f_err; | 0 | ||||||||||||
2152 | } | - | ||||||||||||
2153 | - | |||||||||||||
2154 | if (!(type & EVP_PKT_SIGN)) {
| 0-7 | ||||||||||||
2155 | SSLerror(s, SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE); | - | ||||||||||||
2156 | al = SSL_AD_ILLEGAL_PARAMETER; | - | ||||||||||||
2157 | goto f_err; never executed: goto f_err; | 0 | ||||||||||||
2158 | } | - | ||||||||||||
2159 | - | |||||||||||||
2160 | if (S3I(s)->change_cipher_spec) {
| 0-7 | ||||||||||||
2161 | SSLerror(s, SSL_R_CCS_RECEIVED_EARLY); | - | ||||||||||||
2162 | al = SSL_AD_UNEXPECTED_MESSAGE; | - | ||||||||||||
2163 | goto f_err; never executed: goto f_err; | 0 | ||||||||||||
2164 | } | - | ||||||||||||
2165 | - | |||||||||||||
2166 | /* | - | ||||||||||||
2167 | * Check for broken implementations of GOST ciphersuites. | - | ||||||||||||
2168 | * | - | ||||||||||||
2169 | * If key is GOST and n is exactly 64, it is a bare | - | ||||||||||||
2170 | * signature without length field. | - | ||||||||||||
2171 | */ | - | ||||||||||||
2172 | if ((pkey->type == NID_id_GostR3410_94 ||
| 0-7 | ||||||||||||
2173 | pkey->type == NID_id_GostR3410_2001) && CBS_len(&cbs) == 64) {
| 0-7 | ||||||||||||
2174 | CBS_dup(&cbs, &signature); | - | ||||||||||||
2175 | if (!CBS_skip(&cbs, CBS_len(&cbs)))
| 0 | ||||||||||||
2176 | goto err; never executed: goto err; | 0 | ||||||||||||
2177 | } else { never executed: end of block | 0 | ||||||||||||
2178 | if (SSL_USE_SIGALGS(s)) {
| 2-5 | ||||||||||||
2179 | if (!CBS_get_u8(&cbs, &hash_id))
| 0-5 | ||||||||||||
2180 | goto truncated; never executed: goto truncated; | 0 | ||||||||||||
2181 | if (!CBS_get_u8(&cbs, &sig_id))
| 0-5 | ||||||||||||
2182 | goto truncated; never executed: goto truncated; | 0 | ||||||||||||
2183 | - | |||||||||||||
2184 | if ((md = tls12_get_hash(hash_id)) == NULL) {
| 0-5 | ||||||||||||
2185 | SSLerror(s, SSL_R_UNKNOWN_DIGEST); | - | ||||||||||||
2186 | al = SSL_AD_DECODE_ERROR; | - | ||||||||||||
2187 | goto f_err; never executed: goto f_err; | 0 | ||||||||||||
2188 | } | - | ||||||||||||
2189 | - | |||||||||||||
2190 | /* Check key type is consistent with signature. */ | - | ||||||||||||
2191 | if ((sigalg = tls12_get_sigid(pkey)) == -1) {
| 0-5 | ||||||||||||
2192 | /* Should never happen */ | - | ||||||||||||
2193 | SSLerror(s, ERR_R_INTERNAL_ERROR); | - | ||||||||||||
2194 | goto err; never executed: goto err; | 0 | ||||||||||||
2195 | } | - | ||||||||||||
2196 | if (sigalg != sig_id) {
| 0-5 | ||||||||||||
2197 | SSLerror(s, SSL_R_WRONG_SIGNATURE_TYPE); | - | ||||||||||||
2198 | al = SSL_AD_DECODE_ERROR; | - | ||||||||||||
2199 | goto f_err; never executed: goto f_err; | 0 | ||||||||||||
2200 | } | - | ||||||||||||
2201 | } executed 5 times by 1 test: end of block Executed by:
| 5 | ||||||||||||
2202 | if (!CBS_get_u16_length_prefixed(&cbs, &signature))
| 0-7 | ||||||||||||
2203 | goto err; never executed: goto err; | 0 | ||||||||||||
2204 | } executed 7 times by 1 test: end of block Executed by:
| 7 | ||||||||||||
2205 | if (CBS_len(&signature) > EVP_PKEY_size(pkey)) {
| 0-7 | ||||||||||||
2206 | SSLerror(s, SSL_R_WRONG_SIGNATURE_SIZE); | - | ||||||||||||
2207 | al = SSL_AD_DECODE_ERROR; | - | ||||||||||||
2208 | goto f_err; never executed: goto f_err; | 0 | ||||||||||||
2209 | } | - | ||||||||||||
2210 | if (CBS_len(&cbs) != 0) {
| 0-7 | ||||||||||||
2211 | al = SSL_AD_DECODE_ERROR; | - | ||||||||||||
2212 | SSLerror(s, SSL_R_EXTRA_DATA_IN_MESSAGE); | - | ||||||||||||
2213 | goto f_err; never executed: goto f_err; | 0 | ||||||||||||
2214 | } | - | ||||||||||||
2215 | - | |||||||||||||
2216 | if (SSL_USE_SIGALGS(s)) {
| 2-5 | ||||||||||||
2217 | hdatalen = BIO_get_mem_data(S3I(s)->handshake_buffer, &hdata); | - | ||||||||||||
2218 | if (hdatalen <= 0) {
| 0-5 | ||||||||||||
2219 | SSLerror(s, ERR_R_INTERNAL_ERROR); | - | ||||||||||||
2220 | al = SSL_AD_INTERNAL_ERROR; | - | ||||||||||||
2221 | goto f_err; never executed: goto f_err; | 0 | ||||||||||||
2222 | } | - | ||||||||||||
2223 | if (!EVP_VerifyInit_ex(&mctx, md, NULL) ||
| 0-5 | ||||||||||||
2224 | !EVP_VerifyUpdate(&mctx, hdata, hdatalen)) {
| 0-5 | ||||||||||||
2225 | SSLerror(s, ERR_R_EVP_LIB); | - | ||||||||||||
2226 | al = SSL_AD_INTERNAL_ERROR; | - | ||||||||||||
2227 | goto f_err; never executed: goto f_err; | 0 | ||||||||||||
2228 | } | - | ||||||||||||
2229 | if (EVP_VerifyFinal(&mctx, CBS_data(&signature),
| 0-5 | ||||||||||||
2230 | CBS_len(&signature), pkey) <= 0) {
| 0-5 | ||||||||||||
2231 | al = SSL_AD_DECRYPT_ERROR; | - | ||||||||||||
2232 | SSLerror(s, SSL_R_BAD_SIGNATURE); | - | ||||||||||||
2233 | goto f_err; never executed: goto f_err; | 0 | ||||||||||||
2234 | } | - | ||||||||||||
2235 | } else if (pkey->type == EVP_PKEY_RSA) { executed 5 times by 1 test: end of block Executed by:
| 0-5 | ||||||||||||
2236 | verify = RSA_verify(NID_md5_sha1, S3I(s)->tmp.cert_verify_md, | - | ||||||||||||
2237 | MD5_DIGEST_LENGTH + SHA_DIGEST_LENGTH, CBS_data(&signature), | - | ||||||||||||
2238 | CBS_len(&signature), pkey->pkey.rsa); | - | ||||||||||||
2239 | if (verify < 0) {
| 0-2 | ||||||||||||
2240 | al = SSL_AD_DECRYPT_ERROR; | - | ||||||||||||
2241 | SSLerror(s, SSL_R_BAD_RSA_DECRYPT); | - | ||||||||||||
2242 | goto f_err; never executed: goto f_err; | 0 | ||||||||||||
2243 | } | - | ||||||||||||
2244 | if (verify == 0) {
| 0-2 | ||||||||||||
2245 | al = SSL_AD_DECRYPT_ERROR; | - | ||||||||||||
2246 | SSLerror(s, SSL_R_BAD_RSA_SIGNATURE); | - | ||||||||||||
2247 | goto f_err; never executed: goto f_err; | 0 | ||||||||||||
2248 | } | - | ||||||||||||
2249 | } else if (pkey->type == EVP_PKEY_EC) { executed 2 times by 1 test: end of block Executed by:
| 0-2 | ||||||||||||
2250 | verify = ECDSA_verify(pkey->save_type, | - | ||||||||||||
2251 | &(S3I(s)->tmp.cert_verify_md[MD5_DIGEST_LENGTH]), | - | ||||||||||||
2252 | SHA_DIGEST_LENGTH, CBS_data(&signature), | - | ||||||||||||
2253 | CBS_len(&signature), pkey->pkey.ec); | - | ||||||||||||
2254 | if (verify <= 0) {
| 0 | ||||||||||||
2255 | al = SSL_AD_DECRYPT_ERROR; | - | ||||||||||||
2256 | SSLerror(s, SSL_R_BAD_ECDSA_SIGNATURE); | - | ||||||||||||
2257 | goto f_err; never executed: goto f_err; | 0 | ||||||||||||
2258 | } | - | ||||||||||||
2259 | } else never executed: end of block | 0 | ||||||||||||
2260 | #ifndef OPENSSL_NO_GOST | - | ||||||||||||
2261 | if (pkey->type == NID_id_GostR3410_94 ||
| 0 | ||||||||||||
2262 | pkey->type == NID_id_GostR3410_2001) {
| 0 | ||||||||||||
2263 | unsigned char sigbuf[128]; | - | ||||||||||||
2264 | unsigned int siglen = sizeof(sigbuf); | - | ||||||||||||
2265 | EVP_PKEY_CTX *pctx; | - | ||||||||||||
2266 | int nid; | - | ||||||||||||
2267 | - | |||||||||||||
2268 | hdatalen = BIO_get_mem_data(S3I(s)->handshake_buffer, &hdata); | - | ||||||||||||
2269 | if (hdatalen <= 0) {
| 0 | ||||||||||||
2270 | SSLerror(s, ERR_R_INTERNAL_ERROR); | - | ||||||||||||
2271 | al = SSL_AD_INTERNAL_ERROR; | - | ||||||||||||
2272 | goto f_err; never executed: goto f_err; | 0 | ||||||||||||
2273 | } | - | ||||||||||||
2274 | if (!EVP_PKEY_get_default_digest_nid(pkey, &nid) ||
| 0 | ||||||||||||
2275 | !(md = EVP_get_digestbynid(nid))) {
| 0 | ||||||||||||
2276 | SSLerror(s, ERR_R_EVP_LIB); | - | ||||||||||||
2277 | al = SSL_AD_INTERNAL_ERROR; | - | ||||||||||||
2278 | goto f_err; never executed: goto f_err; | 0 | ||||||||||||
2279 | } | - | ||||||||||||
2280 | if ((pctx = EVP_PKEY_CTX_new(pkey, NULL)) == NULL) {
| 0 | ||||||||||||
2281 | SSLerror(s, ERR_R_EVP_LIB); | - | ||||||||||||
2282 | al = SSL_AD_INTERNAL_ERROR; | - | ||||||||||||
2283 | goto f_err; never executed: goto f_err; | 0 | ||||||||||||
2284 | } | - | ||||||||||||
2285 | if (!EVP_DigestInit_ex(&mctx, md, NULL) ||
| 0 | ||||||||||||
2286 | !EVP_DigestUpdate(&mctx, hdata, hdatalen) ||
| 0 | ||||||||||||
2287 | !EVP_DigestFinal(&mctx, sigbuf, &siglen) ||
| 0 | ||||||||||||
2288 | (EVP_PKEY_verify_init(pctx) <= 0) ||
| 0 | ||||||||||||
2289 | (EVP_PKEY_CTX_set_signature_md(pctx, md) <= 0) ||
| 0 | ||||||||||||
2290 | (EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_VERIFY,
| 0 | ||||||||||||
2291 | EVP_PKEY_CTRL_GOST_SIG_FORMAT,
| 0 | ||||||||||||
2292 | GOST_SIG_FORMAT_RS_LE, NULL) <= 0)) {
| 0 | ||||||||||||
2293 | SSLerror(s, ERR_R_EVP_LIB); | - | ||||||||||||
2294 | al = SSL_AD_INTERNAL_ERROR; | - | ||||||||||||
2295 | EVP_PKEY_CTX_free(pctx); | - | ||||||||||||
2296 | goto f_err; never executed: goto f_err; | 0 | ||||||||||||
2297 | } | - | ||||||||||||
2298 | if (EVP_PKEY_verify(pctx, CBS_data(&signature),
| 0 | ||||||||||||
2299 | CBS_len(&signature), sigbuf, siglen) <= 0) {
| 0 | ||||||||||||
2300 | al = SSL_AD_DECRYPT_ERROR; | - | ||||||||||||
2301 | SSLerror(s, SSL_R_BAD_SIGNATURE); | - | ||||||||||||
2302 | EVP_PKEY_CTX_free(pctx); | - | ||||||||||||
2303 | goto f_err; never executed: goto f_err; | 0 | ||||||||||||
2304 | } | - | ||||||||||||
2305 | - | |||||||||||||
2306 | EVP_PKEY_CTX_free(pctx); | - | ||||||||||||
2307 | } else never executed: end of block | 0 | ||||||||||||
2308 | #endif | - | ||||||||||||
2309 | { | - | ||||||||||||
2310 | SSLerror(s, ERR_R_INTERNAL_ERROR); | - | ||||||||||||
2311 | al = SSL_AD_UNSUPPORTED_CERTIFICATE; | - | ||||||||||||
2312 | goto f_err; never executed: goto f_err; | 0 | ||||||||||||
2313 | } | - | ||||||||||||
2314 | - | |||||||||||||
2315 | ret = 1; | - | ||||||||||||
2316 | if (0) { | - | ||||||||||||
2317 | truncated: | - | ||||||||||||
2318 | al = SSL_AD_DECODE_ERROR; | - | ||||||||||||
2319 | SSLerror(s, SSL_R_BAD_PACKET_LENGTH); | - | ||||||||||||
2320 | f_err: code before this statement never executed: f_err: | 0 | ||||||||||||
2321 | ssl3_send_alert(s, SSL3_AL_FATAL, al); | - | ||||||||||||
2322 | } never executed: end of block | 0 | ||||||||||||
2323 | end: code before this statement executed 7 times by 1 test: end: Executed by:
| 7 | ||||||||||||
2324 | if (S3I(s)->handshake_buffer) {
| 5-58 | ||||||||||||
2325 | BIO_free(S3I(s)->handshake_buffer); | - | ||||||||||||
2326 | S3I(s)->handshake_buffer = NULL; | - | ||||||||||||
2327 | s->s3->flags &= ~TLS1_FLAGS_KEEP_HANDSHAKE; | - | ||||||||||||
2328 | } executed 5 times by 1 test: end of block Executed by:
| 5 | ||||||||||||
2329 | err: code before this statement executed 63 times by 2 tests: err: Executed by:
| 63 | ||||||||||||
2330 | EVP_MD_CTX_cleanup(&mctx); | - | ||||||||||||
2331 | EVP_PKEY_free(pkey); | - | ||||||||||||
2332 | return (ret); executed 63 times by 2 tests: return (ret); Executed by:
| 63 | ||||||||||||
2333 | } | - | ||||||||||||
2334 | - | |||||||||||||
2335 | int | - | ||||||||||||
2336 | ssl3_get_client_certificate(SSL *s) | - | ||||||||||||
2337 | { | - | ||||||||||||
2338 | CBS cbs, client_certs; | - | ||||||||||||
2339 | int i, ok, al, ret = -1; | - | ||||||||||||
2340 | X509 *x = NULL; | - | ||||||||||||
2341 | long n; | - | ||||||||||||
2342 | const unsigned char *q; | - | ||||||||||||
2343 | STACK_OF(X509) *sk = NULL; | - | ||||||||||||
2344 | - | |||||||||||||
2345 | n = s->method->internal->ssl_get_message(s, SSL3_ST_SR_CERT_A, SSL3_ST_SR_CERT_B, | - | ||||||||||||
2346 | -1, s->internal->max_cert_list, &ok); | - | ||||||||||||
2347 | - | |||||||||||||
2348 | if (!ok)
| 7-100 | ||||||||||||
2349 | return ((int)n); executed 100 times by 1 test: return ((int)n); Executed by:
| 100 | ||||||||||||
2350 | - | |||||||||||||
2351 | if (S3I(s)->tmp.message_type == SSL3_MT_CLIENT_KEY_EXCHANGE) {
| 0-7 | ||||||||||||
2352 | if ((s->verify_mode & SSL_VERIFY_PEER) &&
| 0 | ||||||||||||
2353 | (s->verify_mode & SSL_VERIFY_FAIL_IF_NO_PEER_CERT)) {
| 0 | ||||||||||||
2354 | SSLerror(s, SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE); | - | ||||||||||||
2355 | al = SSL_AD_HANDSHAKE_FAILURE; | - | ||||||||||||
2356 | goto f_err; never executed: goto f_err; | 0 | ||||||||||||
2357 | } | - | ||||||||||||
2358 | /* | - | ||||||||||||
2359 | * If tls asked for a client cert, | - | ||||||||||||
2360 | * the client must return a 0 list. | - | ||||||||||||
2361 | */ | - | ||||||||||||
2362 | if (S3I(s)->tmp.cert_request) {
| 0 | ||||||||||||
2363 | SSLerror(s, SSL_R_TLS_PEER_DID_NOT_RESPOND_WITH_CERTIFICATE_LIST | - | ||||||||||||
2364 | ); | - | ||||||||||||
2365 | al = SSL_AD_UNEXPECTED_MESSAGE; | - | ||||||||||||
2366 | goto f_err; never executed: goto f_err; | 0 | ||||||||||||
2367 | } | - | ||||||||||||
2368 | S3I(s)->tmp.reuse_message = 1; | - | ||||||||||||
2369 | return (1); never executed: return (1); | 0 | ||||||||||||
2370 | } | - | ||||||||||||
2371 | - | |||||||||||||
2372 | if (S3I(s)->tmp.message_type != SSL3_MT_CERTIFICATE) {
| 0-7 | ||||||||||||
2373 | al = SSL_AD_UNEXPECTED_MESSAGE; | - | ||||||||||||
2374 | SSLerror(s, SSL_R_WRONG_MESSAGE_TYPE); | - | ||||||||||||
2375 | goto f_err; never executed: goto f_err; | 0 | ||||||||||||
2376 | } | - | ||||||||||||
2377 | - | |||||||||||||
2378 | if (n < 0)
| 0-7 | ||||||||||||
2379 | goto truncated; never executed: goto truncated; | 0 | ||||||||||||
2380 | - | |||||||||||||
2381 | CBS_init(&cbs, s->internal->init_msg, n); | - | ||||||||||||
2382 | - | |||||||||||||
2383 | if ((sk = sk_X509_new_null()) == NULL) {
| 0-7 | ||||||||||||
2384 | SSLerror(s, ERR_R_MALLOC_FAILURE); | - | ||||||||||||
2385 | goto err; never executed: goto err; | 0 | ||||||||||||
2386 | } | - | ||||||||||||
2387 | - | |||||||||||||
2388 | if (!CBS_get_u24_length_prefixed(&cbs, &client_certs) ||
| 0-7 | ||||||||||||
2389 | CBS_len(&cbs) != 0)
| 0-7 | ||||||||||||
2390 | goto truncated; never executed: goto truncated; | 0 | ||||||||||||
2391 | - | |||||||||||||
2392 | while (CBS_len(&client_certs) > 0) {
| 7-21 | ||||||||||||
2393 | CBS cert; | - | ||||||||||||
2394 | - | |||||||||||||
2395 | if (!CBS_get_u24_length_prefixed(&client_certs, &cert)) {
| 0-21 | ||||||||||||
2396 | al = SSL_AD_DECODE_ERROR; | - | ||||||||||||
2397 | SSLerror(s, SSL_R_CERT_LENGTH_MISMATCH); | - | ||||||||||||
2398 | goto f_err; never executed: goto f_err; | 0 | ||||||||||||
2399 | } | - | ||||||||||||
2400 | - | |||||||||||||
2401 | q = CBS_data(&cert); | - | ||||||||||||
2402 | x = d2i_X509(NULL, &q, CBS_len(&cert)); | - | ||||||||||||
2403 | if (x == NULL) {
| 0-21 | ||||||||||||
2404 | SSLerror(s, ERR_R_ASN1_LIB); | - | ||||||||||||
2405 | goto err; never executed: goto err; | 0 | ||||||||||||
2406 | } | - | ||||||||||||
2407 | if (q != CBS_data(&cert) + CBS_len(&cert)) {
| 0-21 | ||||||||||||
2408 | al = SSL_AD_DECODE_ERROR; | - | ||||||||||||
2409 | SSLerror(s, SSL_R_CERT_LENGTH_MISMATCH); | - | ||||||||||||
2410 | goto f_err; never executed: goto f_err; | 0 | ||||||||||||
2411 | } | - | ||||||||||||
2412 | if (!sk_X509_push(sk, x)) {
| 0-21 | ||||||||||||
2413 | SSLerror(s, ERR_R_MALLOC_FAILURE); | - | ||||||||||||
2414 | goto err; never executed: goto err; | 0 | ||||||||||||
2415 | } | - | ||||||||||||
2416 | x = NULL; | - | ||||||||||||
2417 | } executed 21 times by 1 test: end of block Executed by:
| 21 | ||||||||||||
2418 | - | |||||||||||||
2419 | if (sk_X509_num(sk) <= 0) {
| 0-7 | ||||||||||||
2420 | /* | - | ||||||||||||
2421 | * TLS does not mind 0 certs returned. | - | ||||||||||||
2422 | * Fail for TLS only if we required a certificate. | - | ||||||||||||
2423 | */ | - | ||||||||||||
2424 | if ((s->verify_mode & SSL_VERIFY_PEER) &&
| 0 | ||||||||||||
2425 | (s->verify_mode & SSL_VERIFY_FAIL_IF_NO_PEER_CERT)) {
| 0 | ||||||||||||
2426 | SSLerror(s, SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE); | - | ||||||||||||
2427 | al = SSL_AD_HANDSHAKE_FAILURE; | - | ||||||||||||
2428 | goto f_err; never executed: goto f_err; | 0 | ||||||||||||
2429 | } | - | ||||||||||||
2430 | /* No client certificate so digest cached records */ | - | ||||||||||||
2431 | if (S3I(s)->handshake_buffer && !tls1_digest_cached_records(s)) {
| 0 | ||||||||||||
2432 | al = SSL_AD_INTERNAL_ERROR; | - | ||||||||||||
2433 | goto f_err; never executed: goto f_err; | 0 | ||||||||||||
2434 | } | - | ||||||||||||
2435 | } else { never executed: end of block | 0 | ||||||||||||
2436 | i = ssl_verify_cert_chain(s, sk); | - | ||||||||||||
2437 | if (i <= 0) {
| 0-7 | ||||||||||||
2438 | al = ssl_verify_alarm_type(s->verify_result); | - | ||||||||||||
2439 | SSLerror(s, SSL_R_NO_CERTIFICATE_RETURNED); | - | ||||||||||||
2440 | goto f_err; never executed: goto f_err; | 0 | ||||||||||||
2441 | } | - | ||||||||||||
2442 | } executed 7 times by 1 test: end of block Executed by:
| 7 | ||||||||||||
2443 | - | |||||||||||||
2444 | X509_free(s->session->peer); | - | ||||||||||||
2445 | s->session->peer = sk_X509_shift(sk); | - | ||||||||||||
2446 | s->session->verify_result = s->verify_result; | - | ||||||||||||
2447 | - | |||||||||||||
2448 | /* | - | ||||||||||||
2449 | * With the current implementation, sess_cert will always be NULL | - | ||||||||||||
2450 | * when we arrive here | - | ||||||||||||
2451 | */ | - | ||||||||||||
2452 | if (SSI(s)->sess_cert == NULL) {
| 0-7 | ||||||||||||
2453 | SSI(s)->sess_cert = ssl_sess_cert_new(); | - | ||||||||||||
2454 | if (SSI(s)->sess_cert == NULL) {
| 0-7 | ||||||||||||
2455 | SSLerror(s, ERR_R_MALLOC_FAILURE); | - | ||||||||||||
2456 | goto err; never executed: goto err; | 0 | ||||||||||||
2457 | } | - | ||||||||||||
2458 | } executed 7 times by 1 test: end of block Executed by:
| 7 | ||||||||||||
2459 | sk_X509_pop_free(SSI(s)->sess_cert->cert_chain, X509_free); | - | ||||||||||||
2460 | SSI(s)->sess_cert->cert_chain = sk; | - | ||||||||||||
2461 | - | |||||||||||||
2462 | /* | - | ||||||||||||
2463 | * Inconsistency alert: cert_chain does *not* include the | - | ||||||||||||
2464 | * peer's own certificate, while we do include it in s3_clnt.c | - | ||||||||||||
2465 | */ | - | ||||||||||||
2466 | - | |||||||||||||
2467 | sk = NULL; | - | ||||||||||||
2468 | - | |||||||||||||
2469 | ret = 1; | - | ||||||||||||
2470 | if (0) { | - | ||||||||||||
2471 | truncated: | - | ||||||||||||
2472 | al = SSL_AD_DECODE_ERROR; | - | ||||||||||||
2473 | SSLerror(s, SSL_R_BAD_PACKET_LENGTH); | - | ||||||||||||
2474 | f_err: code before this statement never executed: f_err: | 0 | ||||||||||||
2475 | ssl3_send_alert(s, SSL3_AL_FATAL, al); | - | ||||||||||||
2476 | } never executed: end of block | 0 | ||||||||||||
2477 | err: code before this statement executed 7 times by 1 test: err: Executed by:
| 7 | ||||||||||||
2478 | X509_free(x); | - | ||||||||||||
2479 | sk_X509_pop_free(sk, X509_free); | - | ||||||||||||
2480 | - | |||||||||||||
2481 | return (ret); executed 7 times by 1 test: return (ret); Executed by:
| 7 | ||||||||||||
2482 | } | - | ||||||||||||
2483 | - | |||||||||||||
2484 | int | - | ||||||||||||
2485 | ssl3_send_server_certificate(SSL *s) | - | ||||||||||||
2486 | { | - | ||||||||||||
2487 | CBB cbb, server_cert; | - | ||||||||||||
2488 | X509 *x; | - | ||||||||||||
2489 | - | |||||||||||||
2490 | /* | - | ||||||||||||
2491 | * Server Certificate - RFC 5246, section 7.4.2. | - | ||||||||||||
2492 | */ | - | ||||||||||||
2493 | - | |||||||||||||
2494 | memset(&cbb, 0, sizeof(cbb)); | - | ||||||||||||
2495 | - | |||||||||||||
2496 | if (S3I(s)->hs.state == SSL3_ST_SW_CERT_A) {
| 0-55 | ||||||||||||
2497 | if ((x = ssl_get_server_send_cert(s)) == NULL) {
| 0-55 | ||||||||||||
2498 | SSLerror(s, ERR_R_INTERNAL_ERROR); | - | ||||||||||||
2499 | return (0); never executed: return (0); | 0 | ||||||||||||
2500 | } | - | ||||||||||||
2501 | - | |||||||||||||
2502 | if (!ssl3_handshake_msg_start(s, &cbb, &server_cert,
| 0-55 | ||||||||||||
2503 | SSL3_MT_CERTIFICATE))
| 0-55 | ||||||||||||
2504 | goto err; never executed: goto err; | 0 | ||||||||||||
2505 | if (!ssl3_output_cert_chain(s, &server_cert, x))
| 0-55 | ||||||||||||
2506 | goto err; never executed: goto err; | 0 | ||||||||||||
2507 | if (!ssl3_handshake_msg_finish(s, &cbb))
| 0-55 | ||||||||||||
2508 | goto err; never executed: goto err; | 0 | ||||||||||||
2509 | - | |||||||||||||
2510 | S3I(s)->hs.state = SSL3_ST_SW_CERT_B; | - | ||||||||||||
2511 | } executed 55 times by 3 tests: end of block Executed by:
| 55 | ||||||||||||
2512 | - | |||||||||||||
2513 | /* SSL3_ST_SW_CERT_B */ | - | ||||||||||||
2514 | return (ssl3_handshake_write(s)); executed 55 times by 3 tests: return (ssl3_handshake_write(s)); Executed by:
| 55 | ||||||||||||
2515 | - | |||||||||||||
2516 | err: | - | ||||||||||||
2517 | CBB_cleanup(&cbb); | - | ||||||||||||
2518 | - | |||||||||||||
2519 | return (0); never executed: return (0); | 0 | ||||||||||||
2520 | } | - | ||||||||||||
2521 | - | |||||||||||||
2522 | /* send a new session ticket (not necessarily for a new session) */ | - | ||||||||||||
2523 | int | - | ||||||||||||
2524 | ssl3_send_newsession_ticket(SSL *s) | - | ||||||||||||
2525 | { | - | ||||||||||||
2526 | CBB cbb, session_ticket, ticket; | - | ||||||||||||
2527 | SSL_CTX *tctx = s->initial_ctx; | - | ||||||||||||
2528 | size_t enc_session_len, enc_session_max_len, hmac_len; | - | ||||||||||||
2529 | size_t session_len = 0; | - | ||||||||||||
2530 | unsigned char *enc_session = NULL, *session = NULL; | - | ||||||||||||
2531 | unsigned char iv[EVP_MAX_IV_LENGTH]; | - | ||||||||||||
2532 | unsigned char key_name[16]; | - | ||||||||||||
2533 | unsigned char *hmac; | - | ||||||||||||
2534 | unsigned int hlen; | - | ||||||||||||
2535 | EVP_CIPHER_CTX ctx; | - | ||||||||||||
2536 | HMAC_CTX hctx; | - | ||||||||||||
2537 | int len; | - | ||||||||||||
2538 | - | |||||||||||||
2539 | /* | - | ||||||||||||
2540 | * New Session Ticket - RFC 5077, section 3.3. | - | ||||||||||||
2541 | */ | - | ||||||||||||
2542 | - | |||||||||||||
2543 | EVP_CIPHER_CTX_init(&ctx); | - | ||||||||||||
2544 | HMAC_CTX_init(&hctx); | - | ||||||||||||
2545 | - | |||||||||||||
2546 | memset(&cbb, 0, sizeof(cbb)); | - | ||||||||||||
2547 | - | |||||||||||||
2548 | if (S3I(s)->hs.state == SSL3_ST_SW_SESSION_TICKET_A) {
| 0-59 | ||||||||||||
2549 | if (!ssl3_handshake_msg_start(s, &cbb, &session_ticket,
| 0-59 | ||||||||||||
2550 | SSL3_MT_NEWSESSION_TICKET))
| 0-59 | ||||||||||||
2551 | goto err; never executed: goto err; | 0 | ||||||||||||
2552 | - | |||||||||||||
2553 | if (!SSL_SESSION_ticket(s->session, &session, &session_len))
| 0-59 | ||||||||||||
2554 | goto err; never executed: goto err; | 0 | ||||||||||||
2555 | if (session_len > 0xffff)
| 0-59 | ||||||||||||
2556 | goto err; never executed: goto err; | 0 | ||||||||||||
2557 | - | |||||||||||||
2558 | /* | - | ||||||||||||
2559 | * Initialize HMAC and cipher contexts. If callback is present | - | ||||||||||||
2560 | * it does all the work, otherwise use generated values from | - | ||||||||||||
2561 | * parent context. | - | ||||||||||||
2562 | */ | - | ||||||||||||
2563 | if (tctx->internal->tlsext_ticket_key_cb != NULL) {
| 0-59 | ||||||||||||
2564 | if (tctx->internal->tlsext_ticket_key_cb(s,
| 0 | ||||||||||||
2565 | key_name, iv, &ctx, &hctx, 1) < 0) {
| 0 | ||||||||||||
2566 | EVP_CIPHER_CTX_cleanup(&ctx); | - | ||||||||||||
2567 | goto err; never executed: goto err; | 0 | ||||||||||||
2568 | } | - | ||||||||||||
2569 | } else { never executed: end of block | 0 | ||||||||||||
2570 | arc4random_buf(iv, 16); | - | ||||||||||||
2571 | EVP_EncryptInit_ex(&ctx, EVP_aes_128_cbc(), NULL, | - | ||||||||||||
2572 | tctx->internal->tlsext_tick_aes_key, iv); | - | ||||||||||||
2573 | HMAC_Init_ex(&hctx, tctx->internal->tlsext_tick_hmac_key, | - | ||||||||||||
2574 | 16, tlsext_tick_md(), NULL); | - | ||||||||||||
2575 | memcpy(key_name, tctx->internal->tlsext_tick_key_name, 16); | - | ||||||||||||
2576 | } executed 59 times by 1 test: end of block Executed by:
| 59 | ||||||||||||
2577 | - | |||||||||||||
2578 | /* Encrypt the session state. */ | - | ||||||||||||
2579 | enc_session_max_len = session_len + EVP_MAX_BLOCK_LENGTH; | - | ||||||||||||
2580 | if ((enc_session = calloc(1, enc_session_max_len)) == NULL)
| 0-59 | ||||||||||||
2581 | goto err; never executed: goto err; | 0 | ||||||||||||
2582 | enc_session_len = 0; | - | ||||||||||||
2583 | if (!EVP_EncryptUpdate(&ctx, enc_session, &len, session,
| 0-59 | ||||||||||||
2584 | session_len))
| 0-59 | ||||||||||||
2585 | goto err; never executed: goto err; | 0 | ||||||||||||
2586 | enc_session_len += len; | - | ||||||||||||
2587 | if (!EVP_EncryptFinal_ex(&ctx, enc_session + enc_session_len,
| 0-59 | ||||||||||||
2588 | &len))
| 0-59 | ||||||||||||
2589 | goto err; never executed: goto err; | 0 | ||||||||||||
2590 | enc_session_len += len; | - | ||||||||||||
2591 | - | |||||||||||||
2592 | if (enc_session_len > enc_session_max_len)
| 0-59 | ||||||||||||
2593 | goto err; never executed: goto err; | 0 | ||||||||||||
2594 | - | |||||||||||||
2595 | /* Generate the HMAC. */ | - | ||||||||||||
2596 | if (!HMAC_Update(&hctx, key_name, sizeof(key_name)))
| 0-59 | ||||||||||||
2597 | goto err; never executed: goto err; | 0 | ||||||||||||
2598 | if (!HMAC_Update(&hctx, iv, EVP_CIPHER_CTX_iv_length(&ctx)))
| 0-59 | ||||||||||||
2599 | goto err; never executed: goto err; | 0 | ||||||||||||
2600 | if (!HMAC_Update(&hctx, enc_session, enc_session_len))
| 0-59 | ||||||||||||
2601 | goto err; never executed: goto err; | 0 | ||||||||||||
2602 | - | |||||||||||||
2603 | if ((hmac_len = HMAC_size(&hctx)) <= 0)
| 0-59 | ||||||||||||
2604 | goto err; never executed: goto err; | 0 | ||||||||||||
2605 | - | |||||||||||||
2606 | /* | - | ||||||||||||
2607 | * Ticket lifetime hint (advisory only): | - | ||||||||||||
2608 | * We leave this unspecified for resumed session | - | ||||||||||||
2609 | * (for simplicity), and guess that tickets for new | - | ||||||||||||
2610 | * sessions will live as long as their sessions. | - | ||||||||||||
2611 | */ | - | ||||||||||||
2612 | if (!CBB_add_u32(&session_ticket,
| 0-59 | ||||||||||||
2613 | s->internal->hit ? 0 : s->session->timeout))
| 0-59 | ||||||||||||
2614 | goto err; never executed: goto err; | 0 | ||||||||||||
2615 | - | |||||||||||||
2616 | if (!CBB_add_u16_length_prefixed(&session_ticket, &ticket))
| 0-59 | ||||||||||||
2617 | goto err; never executed: goto err; | 0 | ||||||||||||
2618 | if (!CBB_add_bytes(&ticket, key_name, sizeof(key_name)))
| 0-59 | ||||||||||||
2619 | goto err; never executed: goto err; | 0 | ||||||||||||
2620 | if (!CBB_add_bytes(&ticket, iv, EVP_CIPHER_CTX_iv_length(&ctx)))
| 0-59 | ||||||||||||
2621 | goto err; never executed: goto err; | 0 | ||||||||||||
2622 | if (!CBB_add_bytes(&ticket, enc_session, enc_session_len))
| 0-59 | ||||||||||||
2623 | goto err; never executed: goto err; | 0 | ||||||||||||
2624 | if (!CBB_add_space(&ticket, &hmac, hmac_len))
| 0-59 | ||||||||||||
2625 | goto err; never executed: goto err; | 0 | ||||||||||||
2626 | - | |||||||||||||
2627 | if (!HMAC_Final(&hctx, hmac, &hlen))
| 0-59 | ||||||||||||
2628 | goto err; never executed: goto err; | 0 | ||||||||||||
2629 | if (hlen != hmac_len)
| 0-59 | ||||||||||||
2630 | goto err; never executed: goto err; | 0 | ||||||||||||
2631 | - | |||||||||||||
2632 | if (!ssl3_handshake_msg_finish(s, &cbb))
| 0-59 | ||||||||||||
2633 | goto err; never executed: goto err; | 0 | ||||||||||||
2634 | - | |||||||||||||
2635 | S3I(s)->hs.state = SSL3_ST_SW_SESSION_TICKET_B; | - | ||||||||||||
2636 | } executed 59 times by 1 test: end of block Executed by:
| 59 | ||||||||||||
2637 | - | |||||||||||||
2638 | EVP_CIPHER_CTX_cleanup(&ctx); | - | ||||||||||||
2639 | HMAC_CTX_cleanup(&hctx); | - | ||||||||||||
2640 | freezero(session, session_len); | - | ||||||||||||
2641 | free(enc_session); | - | ||||||||||||
2642 | - | |||||||||||||
2643 | /* SSL3_ST_SW_SESSION_TICKET_B */ | - | ||||||||||||
2644 | return (ssl3_handshake_write(s)); executed 59 times by 1 test: return (ssl3_handshake_write(s)); Executed by:
| 59 | ||||||||||||
2645 | - | |||||||||||||
2646 | err: | - | ||||||||||||
2647 | CBB_cleanup(&cbb); | - | ||||||||||||
2648 | EVP_CIPHER_CTX_cleanup(&ctx); | - | ||||||||||||
2649 | HMAC_CTX_cleanup(&hctx); | - | ||||||||||||
2650 | freezero(session, session_len); | - | ||||||||||||
2651 | free(enc_session); | - | ||||||||||||
2652 | - | |||||||||||||
2653 | return (-1); never executed: return (-1); | 0 | ||||||||||||
2654 | } | - | ||||||||||||
2655 | - | |||||||||||||
2656 | int | - | ||||||||||||
2657 | ssl3_send_cert_status(SSL *s) | - | ||||||||||||
2658 | { | - | ||||||||||||
2659 | CBB cbb, certstatus, ocspresp; | - | ||||||||||||
2660 | - | |||||||||||||
2661 | memset(&cbb, 0, sizeof(cbb)); | - | ||||||||||||
2662 | - | |||||||||||||
2663 | if (S3I(s)->hs.state == SSL3_ST_SW_CERT_STATUS_A) {
| 0 | ||||||||||||
2664 | if (!ssl3_handshake_msg_start(s, &cbb, &certstatus,
| 0 | ||||||||||||
2665 | SSL3_MT_CERTIFICATE_STATUS))
| 0 | ||||||||||||
2666 | goto err; never executed: goto err; | 0 | ||||||||||||
2667 | if (!CBB_add_u8(&certstatus, s->tlsext_status_type))
| 0 | ||||||||||||
2668 | goto err; never executed: goto err; | 0 | ||||||||||||
2669 | if (!CBB_add_u24_length_prefixed(&certstatus, &ocspresp))
| 0 | ||||||||||||
2670 | goto err; never executed: goto err; | 0 | ||||||||||||
2671 | if (!CBB_add_bytes(&ocspresp, s->internal->tlsext_ocsp_resp,
| 0 | ||||||||||||
2672 | s->internal->tlsext_ocsp_resplen))
| 0 | ||||||||||||
2673 | goto err; never executed: goto err; | 0 | ||||||||||||
2674 | if (!ssl3_handshake_msg_finish(s, &cbb))
| 0 | ||||||||||||
2675 | goto err; never executed: goto err; | 0 | ||||||||||||
2676 | - | |||||||||||||
2677 | S3I(s)->hs.state = SSL3_ST_SW_CERT_STATUS_B; | - | ||||||||||||
2678 | } never executed: end of block | 0 | ||||||||||||
2679 | - | |||||||||||||
2680 | /* SSL3_ST_SW_CERT_STATUS_B */ | - | ||||||||||||
2681 | return (ssl3_handshake_write(s)); never executed: return (ssl3_handshake_write(s)); | 0 | ||||||||||||
2682 | - | |||||||||||||
2683 | err: | - | ||||||||||||
2684 | CBB_cleanup(&cbb); | - | ||||||||||||
2685 | - | |||||||||||||
2686 | return (-1); never executed: return (-1); | 0 | ||||||||||||
2687 | } | - | ||||||||||||
Source code | Switch to Preprocessed file |