Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/libressl/src/ssl/ssl_versions.c |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /* $OpenBSD: ssl_versions.c,v 1.3 2017/05/06 20:37:25 jsing Exp $ */ | - | ||||||||||||
2 | /* | - | ||||||||||||
3 | * Copyright (c) 2016, 2017 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 "ssl_locl.h" | - | ||||||||||||
19 | - | |||||||||||||
20 | static int | - | ||||||||||||
21 | ssl_clamp_version_range(uint16_t *min_ver, uint16_t *max_ver, | - | ||||||||||||
22 | uint16_t clamp_min, uint16_t clamp_max) | - | ||||||||||||
23 | { | - | ||||||||||||
24 | if (clamp_min > clamp_max || *min_ver > *max_ver)
| 0-414 | ||||||||||||
25 | return 0; executed 5 times by 1 test: return 0; Executed by:
| 5 | ||||||||||||
26 | if (clamp_max < *min_ver || clamp_min > *max_ver)
| 0-408 | ||||||||||||
27 | return 0; executed 1 time by 1 test: return 0; Executed by:
| 1 | ||||||||||||
28 | - | |||||||||||||
29 | if (*min_ver < clamp_min)
| 10-398 | ||||||||||||
30 | *min_ver = clamp_min; executed 10 times by 2 tests: *min_ver = clamp_min; Executed by:
| 10 | ||||||||||||
31 | if (*max_ver > clamp_max)
| 66-342 | ||||||||||||
32 | *max_ver = clamp_max; executed 66 times by 3 tests: *max_ver = clamp_max; Executed by:
| 66 | ||||||||||||
33 | - | |||||||||||||
34 | return 1; executed 408 times by 5 tests: return 1; Executed by:
| 408 | ||||||||||||
35 | } | - | ||||||||||||
36 | - | |||||||||||||
37 | int | - | ||||||||||||
38 | ssl_version_set_min(const SSL_METHOD *meth, uint16_t ver, uint16_t max_ver, | - | ||||||||||||
39 | uint16_t *out_ver) | - | ||||||||||||
40 | { | - | ||||||||||||
41 | uint16_t min_version, max_version; | - | ||||||||||||
42 | - | |||||||||||||
43 | if (ver == 0) {
| 17-18 | ||||||||||||
44 | *out_ver = meth->internal->min_version; | - | ||||||||||||
45 | return 1; executed 18 times by 1 test: return 1; Executed by:
| 18 | ||||||||||||
46 | } | - | ||||||||||||
47 | - | |||||||||||||
48 | min_version = ver; | - | ||||||||||||
49 | max_version = max_ver; | - | ||||||||||||
50 | - | |||||||||||||
51 | if (!ssl_clamp_version_range(&min_version, &max_version,
| 2-15 | ||||||||||||
52 | meth->internal->min_version, meth->internal->max_version))
| 2-15 | ||||||||||||
53 | return 0; executed 2 times by 1 test: return 0; Executed by:
| 2 | ||||||||||||
54 | - | |||||||||||||
55 | *out_ver = min_version; | - | ||||||||||||
56 | - | |||||||||||||
57 | return 1; executed 15 times by 1 test: return 1; Executed by:
| 15 | ||||||||||||
58 | } | - | ||||||||||||
59 | - | |||||||||||||
60 | int | - | ||||||||||||
61 | ssl_version_set_max(const SSL_METHOD *meth, uint16_t ver, uint16_t min_ver, | - | ||||||||||||
62 | uint16_t *out_ver) | - | ||||||||||||
63 | { | - | ||||||||||||
64 | uint16_t min_version, max_version; | - | ||||||||||||
65 | - | |||||||||||||
66 | if (ver == 0) {
| 16-17 | ||||||||||||
67 | *out_ver = meth->internal->max_version; | - | ||||||||||||
68 | return 1; executed 16 times by 1 test: return 1; Executed by:
| 16 | ||||||||||||
69 | } | - | ||||||||||||
70 | - | |||||||||||||
71 | min_version = min_ver; | - | ||||||||||||
72 | max_version = ver; | - | ||||||||||||
73 | - | |||||||||||||
74 | if (!ssl_clamp_version_range(&min_version, &max_version,
| 3-14 | ||||||||||||
75 | meth->internal->min_version, meth->internal->max_version))
| 3-14 | ||||||||||||
76 | return 0; executed 3 times by 1 test: return 0; Executed by:
| 3 | ||||||||||||
77 | - | |||||||||||||
78 | *out_ver = max_version; | - | ||||||||||||
79 | - | |||||||||||||
80 | return 1; executed 14 times by 1 test: return 1; Executed by:
| 14 | ||||||||||||
81 | } | - | ||||||||||||
82 | - | |||||||||||||
83 | int | - | ||||||||||||
84 | ssl_enabled_version_range(SSL *s, uint16_t *min_ver, uint16_t *max_ver) | - | ||||||||||||
85 | { | - | ||||||||||||
86 | uint16_t min_version, max_version; | - | ||||||||||||
87 | - | |||||||||||||
88 | /* | - | ||||||||||||
89 | * The enabled versions have to be a contiguous range, which means we | - | ||||||||||||
90 | * cannot enable and disable single versions at our whim, even though | - | ||||||||||||
91 | * this is what the OpenSSL flags allow. The historical way this has | - | ||||||||||||
92 | * been handled is by making a flag mean that all higher versions | - | ||||||||||||
93 | * are disabled, if any version lower than the flag is enabled. | - | ||||||||||||
94 | */ | - | ||||||||||||
95 | - | |||||||||||||
96 | min_version = 0; | - | ||||||||||||
97 | max_version = TLS1_2_VERSION; | - | ||||||||||||
98 | - | |||||||||||||
99 | if ((s->internal->options & SSL_OP_NO_TLSv1) == 0)
| 21-178 | ||||||||||||
100 | min_version = TLS1_VERSION; executed 178 times by 4 tests: min_version = 0x0301; Executed by:
| 178 | ||||||||||||
101 | else if ((s->internal->options & SSL_OP_NO_TLSv1_1) == 0)
| 4-17 | ||||||||||||
102 | min_version = TLS1_1_VERSION; executed 4 times by 1 test: min_version = 0x0302; Executed by:
| 4 | ||||||||||||
103 | else if ((s->internal->options & SSL_OP_NO_TLSv1_2) == 0)
| 2-15 | ||||||||||||
104 | min_version = TLS1_2_VERSION; executed 15 times by 3 tests: min_version = 0x0303; Executed by:
| 15 | ||||||||||||
105 | - | |||||||||||||
106 | if ((s->internal->options & SSL_OP_NO_TLSv1_2) && min_version < TLS1_2_VERSION)
| 0-189 | ||||||||||||
107 | max_version = TLS1_1_VERSION; executed 10 times by 2 tests: max_version = 0x0302; Executed by:
| 10 | ||||||||||||
108 | if ((s->internal->options & SSL_OP_NO_TLSv1_1) && min_version < TLS1_1_VERSION)
| 8-176 | ||||||||||||
109 | max_version = TLS1_VERSION; executed 8 times by 2 tests: max_version = 0x0301; Executed by:
| 8 | ||||||||||||
110 | if ((s->internal->options & SSL_OP_NO_TLSv1) && min_version < TLS1_VERSION)
| 2-178 | ||||||||||||
111 | max_version = 0; executed 2 times by 1 test: max_version = 0; Executed by:
| 2 | ||||||||||||
112 | - | |||||||||||||
113 | /* Everything has been disabled... */ | - | ||||||||||||
114 | if (min_version == 0 || max_version == 0)
| 0-197 | ||||||||||||
115 | return 0; executed 2 times by 1 test: return 0; Executed by:
| 2 | ||||||||||||
116 | - | |||||||||||||
117 | /* Limit to configured version range. */ | - | ||||||||||||
118 | if (!ssl_clamp_version_range(&min_version, &max_version,
| 0-197 | ||||||||||||
119 | s->internal->min_version, s->internal->max_version))
| 0-197 | ||||||||||||
120 | return 0; never executed: return 0; | 0 | ||||||||||||
121 | - | |||||||||||||
122 | if (min_ver != NULL)
| 0-197 | ||||||||||||
123 | *min_ver = min_version; executed 197 times by 5 tests: *min_ver = min_version; Executed by:
| 197 | ||||||||||||
124 | if (max_ver != NULL)
| 2-195 | ||||||||||||
125 | *max_ver = max_version; executed 195 times by 5 tests: *max_ver = max_version; Executed by:
| 195 | ||||||||||||
126 | - | |||||||||||||
127 | return 1; executed 197 times by 5 tests: return 1; Executed by:
| 197 | ||||||||||||
128 | } | - | ||||||||||||
129 | - | |||||||||||||
130 | int | - | ||||||||||||
131 | ssl_supported_version_range(SSL *s, uint16_t *min_ver, uint16_t *max_ver) | - | ||||||||||||
132 | { | - | ||||||||||||
133 | uint16_t min_version, max_version; | - | ||||||||||||
134 | - | |||||||||||||
135 | /* DTLS cannot currently be disabled... */ | - | ||||||||||||
136 | if (SSL_IS_DTLS(s)) {
| 23-184 | ||||||||||||
137 | min_version = max_version = DTLS1_VERSION; | - | ||||||||||||
138 | goto done; executed 23 times by 2 tests: goto done; Executed by:
| 23 | ||||||||||||
139 | } | - | ||||||||||||
140 | - | |||||||||||||
141 | if (!ssl_enabled_version_range(s, &min_version, &max_version))
| 1-183 | ||||||||||||
142 | return 0; executed 1 time by 1 test: return 0; Executed by:
| 1 | ||||||||||||
143 | - | |||||||||||||
144 | /* Limit to the versions supported by this method. */ | - | ||||||||||||
145 | if (!ssl_clamp_version_range(&min_version, &max_version,
| 1-182 | ||||||||||||
146 | s->method->internal->min_version,
| 1-182 | ||||||||||||
147 | s->method->internal->max_version))
| 1-182 | ||||||||||||
148 | return 0; executed 1 time by 1 test: return 0; Executed by:
| 1 | ||||||||||||
149 | - | |||||||||||||
150 | done: code before this statement executed 182 times by 5 tests: done: Executed by:
| 182 | ||||||||||||
151 | if (min_ver != NULL)
| 74-131 | ||||||||||||
152 | *min_ver = min_version; executed 131 times by 4 tests: *min_ver = min_version; Executed by:
| 131 | ||||||||||||
153 | if (max_ver != NULL)
| 0-205 | ||||||||||||
154 | *max_ver = max_version; executed 205 times by 5 tests: *max_ver = max_version; Executed by:
| 205 | ||||||||||||
155 | - | |||||||||||||
156 | return 1; executed 205 times by 5 tests: return 1; Executed by:
| 205 | ||||||||||||
157 | } | - | ||||||||||||
158 | - | |||||||||||||
159 | int | - | ||||||||||||
160 | ssl_max_shared_version(SSL *s, uint16_t peer_ver, uint16_t *max_ver) | - | ||||||||||||
161 | { | - | ||||||||||||
162 | uint16_t min_version, max_version, shared_version; | - | ||||||||||||
163 | - | |||||||||||||
164 | *max_ver = 0; | - | ||||||||||||
165 | - | |||||||||||||
166 | if (SSL_IS_DTLS(s)) {
| 13-72 | ||||||||||||
167 | if (peer_ver >= DTLS1_VERSION) {
| 1-12 | ||||||||||||
168 | *max_ver = DTLS1_VERSION; | - | ||||||||||||
169 | return 1; executed 12 times by 2 tests: return 1; Executed by:
| 12 | ||||||||||||
170 | } | - | ||||||||||||
171 | return 0; executed 1 time by 1 test: return 0; Executed by:
| 1 | ||||||||||||
172 | } | - | ||||||||||||
173 | - | |||||||||||||
174 | if (peer_ver >= TLS1_2_VERSION)
| 30-42 | ||||||||||||
175 | shared_version = TLS1_2_VERSION; executed 42 times by 4 tests: shared_version = 0x0303; Executed by:
| 42 | ||||||||||||
176 | else if (peer_ver >= TLS1_1_VERSION)
| 5-25 | ||||||||||||
177 | shared_version = TLS1_1_VERSION; executed 5 times by 1 test: shared_version = 0x0302; Executed by:
| 5 | ||||||||||||
178 | else if (peer_ver >= TLS1_VERSION)
| 2-23 | ||||||||||||
179 | shared_version = TLS1_VERSION; executed 23 times by 3 tests: shared_version = 0x0301; Executed by:
| 23 | ||||||||||||
180 | else | - | ||||||||||||
181 | return 0; executed 2 times by 1 test: return 0; Executed by:
| 2 | ||||||||||||
182 | - | |||||||||||||
183 | if (!ssl_supported_version_range(s, &min_version, &max_version))
| 2-68 | ||||||||||||
184 | return 0; executed 2 times by 1 test: return 0; Executed by:
| 2 | ||||||||||||
185 | - | |||||||||||||
186 | if (shared_version < min_version)
| 2-66 | ||||||||||||
187 | return 0; executed 2 times by 1 test: return 0; Executed by:
| 2 | ||||||||||||
188 | - | |||||||||||||
189 | if (shared_version > max_version)
| 5-61 | ||||||||||||
190 | shared_version = max_version; executed 5 times by 1 test: shared_version = max_version; Executed by:
| 5 | ||||||||||||
191 | - | |||||||||||||
192 | *max_ver = shared_version; | - | ||||||||||||
193 | - | |||||||||||||
194 | return 1; executed 66 times by 4 tests: return 1; Executed by:
| 66 | ||||||||||||
195 | } | - | ||||||||||||
196 | - | |||||||||||||
197 | uint16_t | - | ||||||||||||
198 | ssl_max_server_version(SSL *s) | - | ||||||||||||
199 | { | - | ||||||||||||
200 | uint16_t max_version, min_version = 0; | - | ||||||||||||
201 | - | |||||||||||||
202 | if (SSL_IS_DTLS(s))
| 0 | ||||||||||||
203 | return (DTLS1_VERSION); never executed: return (0xFEFF); | 0 | ||||||||||||
204 | - | |||||||||||||
205 | if (!ssl_enabled_version_range(s, &min_version, &max_version))
| 0 | ||||||||||||
206 | return 0; never executed: return 0; | 0 | ||||||||||||
207 | - | |||||||||||||
208 | /* | - | ||||||||||||
209 | * Limit to the versions supported by this method. The SSL method | - | ||||||||||||
210 | * will be changed during version negotiation, as such we want to | - | ||||||||||||
211 | * use the SSL method from the context. | - | ||||||||||||
212 | */ | - | ||||||||||||
213 | if (!ssl_clamp_version_range(&min_version, &max_version,
| 0 | ||||||||||||
214 | s->ctx->method->internal->min_version,
| 0 | ||||||||||||
215 | s->ctx->method->internal->max_version))
| 0 | ||||||||||||
216 | return 0; never executed: return 0; | 0 | ||||||||||||
217 | - | |||||||||||||
218 | return (max_version); never executed: return (max_version); | 0 | ||||||||||||
219 | } | - | ||||||||||||
Source code | Switch to Preprocessed file |