Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/libressl/src/ssl/ssl_asn1.c |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /* $OpenBSD: ssl_asn1.c,v 1.57 2018/08/27 16:42:48 jsing Exp $ */ | - | ||||||||||||||||||
2 | /* | - | ||||||||||||||||||
3 | * Copyright (c) 2016 Joel Sing <jsing@openbsd.org> | - | ||||||||||||||||||
4 | * | - | ||||||||||||||||||
5 | * Permission to use, copy, modify, and distribute this software for any | - | ||||||||||||||||||
6 | * purpose with or without fee is hereby granted, provided that the above | - | ||||||||||||||||||
7 | * copyright notice and this permission notice appear in all copies. | - | ||||||||||||||||||
8 | * | - | ||||||||||||||||||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | - | ||||||||||||||||||
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | - | ||||||||||||||||||
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | - | ||||||||||||||||||
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | - | ||||||||||||||||||
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | - | ||||||||||||||||||
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | - | ||||||||||||||||||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | - | ||||||||||||||||||
16 | */ | - | ||||||||||||||||||
17 | - | |||||||||||||||||||
18 | #include <limits.h> | - | ||||||||||||||||||
19 | - | |||||||||||||||||||
20 | #include <openssl/ssl.h> | - | ||||||||||||||||||
21 | #include <openssl/x509.h> | - | ||||||||||||||||||
22 | - | |||||||||||||||||||
23 | #include "ssl_locl.h" | - | ||||||||||||||||||
24 | - | |||||||||||||||||||
25 | #include "bytestring.h" | - | ||||||||||||||||||
26 | - | |||||||||||||||||||
27 | #define SSLASN1_TAG (CBS_ASN1_CONSTRUCTED | CBS_ASN1_CONTEXT_SPECIFIC) | - | ||||||||||||||||||
28 | #define SSLASN1_TIME_TAG (SSLASN1_TAG | 1) | - | ||||||||||||||||||
29 | #define SSLASN1_TIMEOUT_TAG (SSLASN1_TAG | 2) | - | ||||||||||||||||||
30 | #define SSLASN1_PEER_CERT_TAG (SSLASN1_TAG | 3) | - | ||||||||||||||||||
31 | #define SSLASN1_SESSION_ID_CTX_TAG (SSLASN1_TAG | 4) | - | ||||||||||||||||||
32 | #define SSLASN1_VERIFY_RESULT_TAG (SSLASN1_TAG | 5) | - | ||||||||||||||||||
33 | #define SSLASN1_HOSTNAME_TAG (SSLASN1_TAG | 6) | - | ||||||||||||||||||
34 | #define SSLASN1_LIFETIME_TAG (SSLASN1_TAG | 9) | - | ||||||||||||||||||
35 | #define SSLASN1_TICKET_TAG (SSLASN1_TAG | 10) | - | ||||||||||||||||||
36 | - | |||||||||||||||||||
37 | static uint64_t | - | ||||||||||||||||||
38 | time_max(void) | - | ||||||||||||||||||
39 | { | - | ||||||||||||||||||
40 | if (sizeof(time_t) == sizeof(int32_t))
| 0-3 | ||||||||||||||||||
41 | return INT32_MAX; never executed: return (2147483647) ; | 0 | ||||||||||||||||||
42 | if (sizeof(time_t) == sizeof(int64_t))
| 0-3 | ||||||||||||||||||
43 | return INT64_MAX; executed 3 times by 1 test: return (9223372036854775807L) ; Executed by:
| 3 | ||||||||||||||||||
44 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
45 | } | - | ||||||||||||||||||
46 | - | |||||||||||||||||||
47 | static int | - | ||||||||||||||||||
48 | SSL_SESSION_encode(SSL_SESSION *s, unsigned char **out, size_t *out_len, | - | ||||||||||||||||||
49 | int ticket_encoding) | - | ||||||||||||||||||
50 | { | - | ||||||||||||||||||
51 | CBB cbb, session, cipher_suite, session_id, master_key, time, timeout; | - | ||||||||||||||||||
52 | CBB peer_cert, sidctx, verify_result, hostname, lifetime, ticket, value; | - | ||||||||||||||||||
53 | unsigned char *peer_cert_bytes = NULL; | - | ||||||||||||||||||
54 | int len, rv = 0; | - | ||||||||||||||||||
55 | uint16_t cid; | - | ||||||||||||||||||
56 | - | |||||||||||||||||||
57 | if (!CBB_init(&cbb, 0))
| 0-67 | ||||||||||||||||||
58 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
59 | - | |||||||||||||||||||
60 | if (!CBB_add_asn1(&cbb, &session, CBS_ASN1_SEQUENCE))
| 0-67 | ||||||||||||||||||
61 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
62 | - | |||||||||||||||||||
63 | /* Session ASN1 version. */ | - | ||||||||||||||||||
64 | if (!CBB_add_asn1_uint64(&session, SSL_SESSION_ASN1_VERSION))
| 0-67 | ||||||||||||||||||
65 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
66 | - | |||||||||||||||||||
67 | /* TLS/SSL protocol version. */ | - | ||||||||||||||||||
68 | if (s->ssl_version < 0)
| 0-67 | ||||||||||||||||||
69 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
70 | if (!CBB_add_asn1_uint64(&session, s->ssl_version))
| 0-67 | ||||||||||||||||||
71 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
72 | - | |||||||||||||||||||
73 | /* Cipher suite ID. */ | - | ||||||||||||||||||
74 | /* XXX - require cipher to be non-NULL or always/only use cipher_id. */ | - | ||||||||||||||||||
75 | cid = (uint16_t)(s->cipher_id & 0xffff); | - | ||||||||||||||||||
76 | if (s->cipher != NULL)
| 8-59 | ||||||||||||||||||
77 | cid = ssl3_cipher_get_value(s->cipher); executed 59 times by 1 test: cid = ssl3_cipher_get_value(s->cipher); Executed by:
| 59 | ||||||||||||||||||
78 | if (!CBB_add_asn1(&session, &cipher_suite, CBS_ASN1_OCTETSTRING))
| 0-67 | ||||||||||||||||||
79 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
80 | if (!CBB_add_u16(&cipher_suite, cid))
| 0-67 | ||||||||||||||||||
81 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
82 | - | |||||||||||||||||||
83 | /* Session ID - zero length for a ticket. */ | - | ||||||||||||||||||
84 | if (!CBB_add_asn1(&session, &session_id, CBS_ASN1_OCTETSTRING))
| 0-67 | ||||||||||||||||||
85 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
86 | if (!CBB_add_bytes(&session_id, s->session_id,
| 0-67 | ||||||||||||||||||
87 | ticket_encoding ? 0 : s->session_id_length))
| 0-67 | ||||||||||||||||||
88 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
89 | - | |||||||||||||||||||
90 | /* Master key. */ | - | ||||||||||||||||||
91 | if (!CBB_add_asn1(&session, &master_key, CBS_ASN1_OCTETSTRING))
| 0-67 | ||||||||||||||||||
92 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
93 | if (!CBB_add_bytes(&master_key, s->master_key, s->master_key_length))
| 0-67 | ||||||||||||||||||
94 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
95 | - | |||||||||||||||||||
96 | /* Time [1]. */ | - | ||||||||||||||||||
97 | if (s->time != 0) {
| 5-62 | ||||||||||||||||||
98 | if (s->time < 0)
| 1-61 | ||||||||||||||||||
99 | goto err; executed 1 time by 1 test: goto err; Executed by:
| 1 | ||||||||||||||||||
100 | if (!CBB_add_asn1(&session, &time, SSLASN1_TIME_TAG))
| 0-61 | ||||||||||||||||||
101 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
102 | if (!CBB_add_asn1_uint64(&time, s->time))
| 0-61 | ||||||||||||||||||
103 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
104 | } executed 61 times by 2 tests: end of block Executed by:
| 61 | ||||||||||||||||||
105 | - | |||||||||||||||||||
106 | /* Timeout [2]. */ | - | ||||||||||||||||||
107 | if (s->timeout != 0) {
| 4-62 | ||||||||||||||||||
108 | if (s->timeout < 0)
| 1-61 | ||||||||||||||||||
109 | goto err; executed 1 time by 1 test: goto err; Executed by:
| 1 | ||||||||||||||||||
110 | if (!CBB_add_asn1(&session, &timeout, SSLASN1_TIMEOUT_TAG))
| 0-61 | ||||||||||||||||||
111 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
112 | if (!CBB_add_asn1_uint64(&timeout, s->timeout))
| 0-61 | ||||||||||||||||||
113 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
114 | } executed 61 times by 2 tests: end of block Executed by:
| 61 | ||||||||||||||||||
115 | - | |||||||||||||||||||
116 | /* Peer certificate [3]. */ | - | ||||||||||||||||||
117 | if (s->peer != NULL) {
| 9-56 | ||||||||||||||||||
118 | if ((len = i2d_X509(s->peer, &peer_cert_bytes)) <= 0)
| 0-9 | ||||||||||||||||||
119 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
120 | if (!CBB_add_asn1(&session, &peer_cert, SSLASN1_PEER_CERT_TAG))
| 0-9 | ||||||||||||||||||
121 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
122 | if (!CBB_add_bytes(&peer_cert, peer_cert_bytes, len))
| 0-9 | ||||||||||||||||||
123 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
124 | } executed 9 times by 2 tests: end of block Executed by:
| 9 | ||||||||||||||||||
125 | - | |||||||||||||||||||
126 | /* Session ID context [4]. */ | - | ||||||||||||||||||
127 | /* XXX - Actually handle this as optional? */ | - | ||||||||||||||||||
128 | if (!CBB_add_asn1(&session, &sidctx, SSLASN1_SESSION_ID_CTX_TAG))
| 0-65 | ||||||||||||||||||
129 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
130 | if (!CBB_add_asn1(&sidctx, &value, CBS_ASN1_OCTETSTRING))
| 0-65 | ||||||||||||||||||
131 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
132 | if (!CBB_add_bytes(&value, s->sid_ctx, s->sid_ctx_length))
| 0-65 | ||||||||||||||||||
133 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
134 | - | |||||||||||||||||||
135 | /* Verify result [5]. */ | - | ||||||||||||||||||
136 | if (s->verify_result != X509_V_OK) {
| 3-62 | ||||||||||||||||||
137 | if (s->verify_result < 0)
| 0-3 | ||||||||||||||||||
138 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
139 | if (!CBB_add_asn1(&session, &verify_result,
| 0-3 | ||||||||||||||||||
140 | SSLASN1_VERIFY_RESULT_TAG))
| 0-3 | ||||||||||||||||||
141 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
142 | if (!CBB_add_asn1_uint64(&verify_result, s->verify_result))
| 0-3 | ||||||||||||||||||
143 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
144 | } executed 3 times by 2 tests: end of block Executed by:
| 3 | ||||||||||||||||||
145 | - | |||||||||||||||||||
146 | /* Hostname [6]. */ | - | ||||||||||||||||||
147 | if (s->tlsext_hostname != NULL) {
| 2-63 | ||||||||||||||||||
148 | if (!CBB_add_asn1(&session, &hostname, SSLASN1_HOSTNAME_TAG))
| 0-2 | ||||||||||||||||||
149 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
150 | if (!CBB_add_asn1(&hostname, &value, CBS_ASN1_OCTETSTRING))
| 0-2 | ||||||||||||||||||
151 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
152 | if (!CBB_add_bytes(&value, (const uint8_t *)s->tlsext_hostname,
| 0-2 | ||||||||||||||||||
153 | strlen(s->tlsext_hostname)))
| 0-2 | ||||||||||||||||||
154 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
155 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
156 | - | |||||||||||||||||||
157 | /* PSK identity hint [7]. */ | - | ||||||||||||||||||
158 | /* PSK identity [8]. */ | - | ||||||||||||||||||
159 | - | |||||||||||||||||||
160 | /* Ticket lifetime hint [9]. */ | - | ||||||||||||||||||
161 | if (s->tlsext_tick_lifetime_hint > 0) {
| 2-63 | ||||||||||||||||||
162 | if (!CBB_add_asn1(&session, &lifetime, SSLASN1_LIFETIME_TAG))
| 0-2 | ||||||||||||||||||
163 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
164 | if (!CBB_add_asn1_uint64(&lifetime,
| 0-2 | ||||||||||||||||||
165 | s->tlsext_tick_lifetime_hint))
| 0-2 | ||||||||||||||||||
166 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
167 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
168 | - | |||||||||||||||||||
169 | /* Ticket [10]. */ | - | ||||||||||||||||||
170 | if (s->tlsext_tick != NULL) {
| 2-63 | ||||||||||||||||||
171 | if (!CBB_add_asn1(&session, &ticket, SSLASN1_TICKET_TAG))
| 0-2 | ||||||||||||||||||
172 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
173 | if (!CBB_add_asn1(&ticket, &value, CBS_ASN1_OCTETSTRING))
| 0-2 | ||||||||||||||||||
174 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
175 | if (!CBB_add_bytes(&value, s->tlsext_tick, s->tlsext_ticklen))
| 0-2 | ||||||||||||||||||
176 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
177 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
178 | - | |||||||||||||||||||
179 | /* Compression method [11]. */ | - | ||||||||||||||||||
180 | /* SRP username [12]. */ | - | ||||||||||||||||||
181 | - | |||||||||||||||||||
182 | if (!CBB_finish(&cbb, out, out_len))
| 0-65 | ||||||||||||||||||
183 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
184 | - | |||||||||||||||||||
185 | rv = 1; | - | ||||||||||||||||||
186 | - | |||||||||||||||||||
187 | err: code before this statement executed 65 times by 2 tests: err: Executed by:
| 65 | ||||||||||||||||||
188 | CBB_cleanup(&cbb); | - | ||||||||||||||||||
189 | free(peer_cert_bytes); | - | ||||||||||||||||||
190 | - | |||||||||||||||||||
191 | return rv; executed 67 times by 2 tests: return rv; Executed by:
| 67 | ||||||||||||||||||
192 | } | - | ||||||||||||||||||
193 | - | |||||||||||||||||||
194 | int | - | ||||||||||||||||||
195 | SSL_SESSION_ticket(SSL_SESSION *ss, unsigned char **out, size_t *out_len) | - | ||||||||||||||||||
196 | { | - | ||||||||||||||||||
197 | if (ss == NULL)
| 0-59 | ||||||||||||||||||
198 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
199 | - | |||||||||||||||||||
200 | if (ss->cipher == NULL && ss->cipher_id == 0)
| 0-59 | ||||||||||||||||||
201 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
202 | - | |||||||||||||||||||
203 | return SSL_SESSION_encode(ss, out, out_len, 1); executed 59 times by 1 test: return SSL_SESSION_encode(ss, out, out_len, 1); Executed by:
| 59 | ||||||||||||||||||
204 | } | - | ||||||||||||||||||
205 | - | |||||||||||||||||||
206 | int | - | ||||||||||||||||||
207 | i2d_SSL_SESSION(SSL_SESSION *ss, unsigned char **pp) | - | ||||||||||||||||||
208 | { | - | ||||||||||||||||||
209 | unsigned char *data = NULL; | - | ||||||||||||||||||
210 | size_t data_len = 0; | - | ||||||||||||||||||
211 | int rv = -1; | - | ||||||||||||||||||
212 | - | |||||||||||||||||||
213 | if (ss == NULL)
| 0-8 | ||||||||||||||||||
214 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
215 | - | |||||||||||||||||||
216 | if (ss->cipher == NULL && ss->cipher_id == 0)
| 0-8 | ||||||||||||||||||
217 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
218 | - | |||||||||||||||||||
219 | if (!SSL_SESSION_encode(ss, &data, &data_len, 0))
| 2-6 | ||||||||||||||||||
220 | goto err; executed 2 times by 1 test: goto err; Executed by:
| 2 | ||||||||||||||||||
221 | - | |||||||||||||||||||
222 | if (data_len > INT_MAX)
| 0-6 | ||||||||||||||||||
223 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
224 | - | |||||||||||||||||||
225 | if (pp != NULL) {
| 3 | ||||||||||||||||||
226 | if (*pp == NULL) {
| 0-3 | ||||||||||||||||||
227 | *pp = data; | - | ||||||||||||||||||
228 | data = NULL; | - | ||||||||||||||||||
229 | } else { never executed: end of block | 0 | ||||||||||||||||||
230 | memcpy(*pp, data, data_len); | - | ||||||||||||||||||
231 | *pp += data_len; | - | ||||||||||||||||||
232 | } executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||||||||
233 | } | - | ||||||||||||||||||
234 | - | |||||||||||||||||||
235 | rv = (int)data_len; | - | ||||||||||||||||||
236 | - | |||||||||||||||||||
237 | err: code before this statement executed 6 times by 1 test: err: Executed by:
| 6 | ||||||||||||||||||
238 | freezero(data, data_len); | - | ||||||||||||||||||
239 | - | |||||||||||||||||||
240 | return rv; executed 8 times by 1 test: return rv; Executed by:
| 8 | ||||||||||||||||||
241 | } | - | ||||||||||||||||||
242 | - | |||||||||||||||||||
243 | SSL_SESSION * | - | ||||||||||||||||||
244 | d2i_SSL_SESSION(SSL_SESSION **a, const unsigned char **pp, long length) | - | ||||||||||||||||||
245 | { | - | ||||||||||||||||||
246 | CBS cbs, session, cipher_suite, session_id, master_key, peer_cert; | - | ||||||||||||||||||
247 | CBS hostname, ticket; | - | ||||||||||||||||||
248 | uint64_t version, tls_version, stime, timeout, verify_result, lifetime; | - | ||||||||||||||||||
249 | const unsigned char *peer_cert_bytes; | - | ||||||||||||||||||
250 | uint16_t cipher_value; | - | ||||||||||||||||||
251 | SSL_SESSION *s = NULL; | - | ||||||||||||||||||
252 | size_t data_len; | - | ||||||||||||||||||
253 | int present; | - | ||||||||||||||||||
254 | - | |||||||||||||||||||
255 | if (a != NULL)
| 0-3 | ||||||||||||||||||
256 | s = *a; executed 3 times by 1 test: s = *a; Executed by:
| 3 | ||||||||||||||||||
257 | - | |||||||||||||||||||
258 | if (s == NULL) {
| 0-3 | ||||||||||||||||||
259 | if ((s = SSL_SESSION_new()) == NULL) {
| 0 | ||||||||||||||||||
260 | SSLerrorx(ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||
261 | return (NULL); never executed: return ( ((void *)0) ); | 0 | ||||||||||||||||||
262 | } | - | ||||||||||||||||||
263 | } never executed: end of block | 0 | ||||||||||||||||||
264 | - | |||||||||||||||||||
265 | CBS_init(&cbs, *pp, length); | - | ||||||||||||||||||
266 | - | |||||||||||||||||||
267 | if (!CBS_get_asn1(&cbs, &session, CBS_ASN1_SEQUENCE))
| 0-3 | ||||||||||||||||||
268 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
269 | - | |||||||||||||||||||
270 | /* Session ASN1 version. */ | - | ||||||||||||||||||
271 | if (!CBS_get_asn1_uint64(&session, &version))
| 0-3 | ||||||||||||||||||
272 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
273 | if (version != SSL_SESSION_ASN1_VERSION)
| 0-3 | ||||||||||||||||||
274 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
275 | - | |||||||||||||||||||
276 | /* TLS/SSL Protocol Version. */ | - | ||||||||||||||||||
277 | if (!CBS_get_asn1_uint64(&session, &tls_version))
| 0-3 | ||||||||||||||||||
278 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
279 | if (tls_version > INT_MAX)
| 0-3 | ||||||||||||||||||
280 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
281 | s->ssl_version = (int)tls_version; | - | ||||||||||||||||||
282 | - | |||||||||||||||||||
283 | /* Cipher suite. */ | - | ||||||||||||||||||
284 | if (!CBS_get_asn1(&session, &cipher_suite, CBS_ASN1_OCTETSTRING))
| 0-3 | ||||||||||||||||||
285 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
286 | if (!CBS_get_u16(&cipher_suite, &cipher_value))
| 0-3 | ||||||||||||||||||
287 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
288 | if (CBS_len(&cipher_suite) != 0)
| 0-3 | ||||||||||||||||||
289 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
290 | - | |||||||||||||||||||
291 | /* XXX - populate cipher instead? */ | - | ||||||||||||||||||
292 | s->cipher = NULL; | - | ||||||||||||||||||
293 | s->cipher_id = SSL3_CK_ID | cipher_value; | - | ||||||||||||||||||
294 | - | |||||||||||||||||||
295 | /* Session ID. */ | - | ||||||||||||||||||
296 | if (!CBS_get_asn1(&session, &session_id, CBS_ASN1_OCTETSTRING))
| 0-3 | ||||||||||||||||||
297 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
298 | if (!CBS_write_bytes(&session_id, s->session_id, sizeof(s->session_id),
| 0-3 | ||||||||||||||||||
299 | &data_len))
| 0-3 | ||||||||||||||||||
300 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
301 | if (data_len > UINT_MAX)
| 0-3 | ||||||||||||||||||
302 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
303 | s->session_id_length = (unsigned int)data_len; | - | ||||||||||||||||||
304 | - | |||||||||||||||||||
305 | /* Master key. */ | - | ||||||||||||||||||
306 | if (!CBS_get_asn1(&session, &master_key, CBS_ASN1_OCTETSTRING))
| 0-3 | ||||||||||||||||||
307 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
308 | if (!CBS_write_bytes(&master_key, s->master_key, sizeof(s->master_key),
| 0-3 | ||||||||||||||||||
309 | &data_len))
| 0-3 | ||||||||||||||||||
310 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
311 | if (data_len > INT_MAX)
| 0-3 | ||||||||||||||||||
312 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
313 | s->master_key_length = (int)data_len; | - | ||||||||||||||||||
314 | - | |||||||||||||||||||
315 | /* Time [1]. */ | - | ||||||||||||||||||
316 | s->time = time(NULL); | - | ||||||||||||||||||
317 | if (!CBS_get_optional_asn1_uint64(&session, &stime, SSLASN1_TIME_TAG,
| 0-3 | ||||||||||||||||||
318 | 0))
| 0-3 | ||||||||||||||||||
319 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
320 | if (stime > time_max())
| 0-3 | ||||||||||||||||||
321 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
322 | if (stime != 0)
| 1-2 | ||||||||||||||||||
323 | s->time = (time_t)stime; executed 1 time by 1 test: s->time = (time_t)stime; Executed by:
| 1 | ||||||||||||||||||
324 | - | |||||||||||||||||||
325 | /* Timeout [2]. */ | - | ||||||||||||||||||
326 | s->timeout = 3; | - | ||||||||||||||||||
327 | if (!CBS_get_optional_asn1_uint64(&session, &timeout,
| 0-3 | ||||||||||||||||||
328 | SSLASN1_TIMEOUT_TAG, 0))
| 0-3 | ||||||||||||||||||
329 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
330 | if (timeout > LONG_MAX)
| 0-3 | ||||||||||||||||||
331 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
332 | if (timeout != 0)
| 1-2 | ||||||||||||||||||
333 | s->timeout = (long)timeout; executed 1 time by 1 test: s->timeout = (long)timeout; Executed by:
| 1 | ||||||||||||||||||
334 | - | |||||||||||||||||||
335 | /* Peer certificate [3]. */ | - | ||||||||||||||||||
336 | X509_free(s->peer); | - | ||||||||||||||||||
337 | s->peer = NULL; | - | ||||||||||||||||||
338 | if (!CBS_get_optional_asn1(&session, &peer_cert, &present,
| 0-3 | ||||||||||||||||||
339 | SSLASN1_PEER_CERT_TAG))
| 0-3 | ||||||||||||||||||
340 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
341 | if (present) {
| 1-2 | ||||||||||||||||||
342 | data_len = CBS_len(&peer_cert); | - | ||||||||||||||||||
343 | if (data_len > LONG_MAX)
| 0-1 | ||||||||||||||||||
344 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
345 | peer_cert_bytes = CBS_data(&peer_cert); | - | ||||||||||||||||||
346 | if (d2i_X509(&s->peer, &peer_cert_bytes,
| 0-1 | ||||||||||||||||||
347 | (long)data_len) == NULL)
| 0-1 | ||||||||||||||||||
348 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
349 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||
350 | - | |||||||||||||||||||
351 | /* Session ID context [4]. */ | - | ||||||||||||||||||
352 | s->sid_ctx_length = 0; | - | ||||||||||||||||||
353 | if (!CBS_get_optional_asn1_octet_string(&session, &session_id, &present,
| 0-3 | ||||||||||||||||||
354 | SSLASN1_SESSION_ID_CTX_TAG))
| 0-3 | ||||||||||||||||||
355 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
356 | if (present) {
| 0-3 | ||||||||||||||||||
357 | if (!CBS_write_bytes(&session_id, (uint8_t *)&s->sid_ctx,
| 0-3 | ||||||||||||||||||
358 | sizeof(s->sid_ctx), &data_len))
| 0-3 | ||||||||||||||||||
359 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
360 | if (data_len > UINT_MAX)
| 0-3 | ||||||||||||||||||
361 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
362 | s->sid_ctx_length = (unsigned int)data_len; | - | ||||||||||||||||||
363 | } executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||||||||
364 | - | |||||||||||||||||||
365 | /* Verify result [5]. */ | - | ||||||||||||||||||
366 | s->verify_result = X509_V_OK; | - | ||||||||||||||||||
367 | if (!CBS_get_optional_asn1_uint64(&session, &verify_result,
| 0-3 | ||||||||||||||||||
368 | SSLASN1_VERIFY_RESULT_TAG, X509_V_OK))
| 0-3 | ||||||||||||||||||
369 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
370 | if (verify_result > LONG_MAX)
| 0-3 | ||||||||||||||||||
371 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
372 | s->verify_result = (long)verify_result; | - | ||||||||||||||||||
373 | - | |||||||||||||||||||
374 | /* Hostname [6]. */ | - | ||||||||||||||||||
375 | free(s->tlsext_hostname); | - | ||||||||||||||||||
376 | s->tlsext_hostname = NULL; | - | ||||||||||||||||||
377 | if (!CBS_get_optional_asn1_octet_string(&session, &hostname, &present,
| 0-3 | ||||||||||||||||||
378 | SSLASN1_HOSTNAME_TAG))
| 0-3 | ||||||||||||||||||
379 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
380 | if (present) {
| 1-2 | ||||||||||||||||||
381 | if (CBS_contains_zero_byte(&hostname))
| 0-1 | ||||||||||||||||||
382 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
383 | if (!CBS_strdup(&hostname, &s->tlsext_hostname))
| 0-1 | ||||||||||||||||||
384 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
385 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||
386 | - | |||||||||||||||||||
387 | /* PSK identity hint [7]. */ | - | ||||||||||||||||||
388 | /* PSK identity [8]. */ | - | ||||||||||||||||||
389 | - | |||||||||||||||||||
390 | /* Ticket lifetime [9]. */ | - | ||||||||||||||||||
391 | s->tlsext_tick_lifetime_hint = 0; | - | ||||||||||||||||||
392 | /* XXX - tlsext_ticklen is not yet set... */ | - | ||||||||||||||||||
393 | if (s->tlsext_ticklen > 0 && s->session_id_length > 0)
| 0-3 | ||||||||||||||||||
394 | s->tlsext_tick_lifetime_hint = -1; never executed: s->tlsext_tick_lifetime_hint = -1; | 0 | ||||||||||||||||||
395 | if (!CBS_get_optional_asn1_uint64(&session, &lifetime,
| 0-3 | ||||||||||||||||||
396 | SSLASN1_LIFETIME_TAG, 0))
| 0-3 | ||||||||||||||||||
397 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
398 | if (lifetime > LONG_MAX)
| 0-3 | ||||||||||||||||||
399 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
400 | if (lifetime > 0)
| 1-2 | ||||||||||||||||||
401 | s->tlsext_tick_lifetime_hint = (long)lifetime; executed 1 time by 1 test: s->tlsext_tick_lifetime_hint = (long)lifetime; Executed by:
| 1 | ||||||||||||||||||
402 | - | |||||||||||||||||||
403 | /* Ticket [10]. */ | - | ||||||||||||||||||
404 | free(s->tlsext_tick); | - | ||||||||||||||||||
405 | s->tlsext_tick = NULL; | - | ||||||||||||||||||
406 | if (!CBS_get_optional_asn1_octet_string(&session, &ticket, &present,
| 0-3 | ||||||||||||||||||
407 | SSLASN1_TICKET_TAG))
| 0-3 | ||||||||||||||||||
408 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
409 | if (present) {
| 1-2 | ||||||||||||||||||
410 | if (!CBS_stow(&ticket, &s->tlsext_tick, &s->tlsext_ticklen))
| 0-1 | ||||||||||||||||||
411 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
412 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||
413 | - | |||||||||||||||||||
414 | /* Compression method [11]. */ | - | ||||||||||||||||||
415 | /* SRP username [12]. */ | - | ||||||||||||||||||
416 | - | |||||||||||||||||||
417 | *pp = CBS_data(&cbs); | - | ||||||||||||||||||
418 | - | |||||||||||||||||||
419 | if (a != NULL)
| 0-3 | ||||||||||||||||||
420 | *a = s; executed 3 times by 1 test: *a = s; Executed by:
| 3 | ||||||||||||||||||
421 | - | |||||||||||||||||||
422 | return (s); executed 3 times by 1 test: return (s); Executed by:
| 3 | ||||||||||||||||||
423 | - | |||||||||||||||||||
424 | err: | - | ||||||||||||||||||
425 | ERR_asprintf_error_data("offset=%d", (int)(CBS_data(&cbs) - *pp)); | - | ||||||||||||||||||
426 | - | |||||||||||||||||||
427 | if (s != NULL && (a == NULL || *a != s))
| 0 | ||||||||||||||||||
428 | SSL_SESSION_free(s); never executed: SSL_SESSION_free(s); | 0 | ||||||||||||||||||
429 | - | |||||||||||||||||||
430 | return (NULL); never executed: return ( ((void *)0) ); | 0 | ||||||||||||||||||
431 | } | - | ||||||||||||||||||
Source code | Switch to Preprocessed file |