diff options
author | jsing <> | 2022-10-01 16:23:15 +0000 |
---|---|---|
committer | jsing <> | 2022-10-01 16:23:15 +0000 |
commit | d5e660940f76ba9fedb2400c0fa888e996ee93c9 (patch) | |
tree | 17355bd2c7397fbcda5912079e30abc288561c2f /src/lib/libssl/ssl_both.c | |
parent | 891337e5a26a9faa47ed08abfbaeaf58e11c669c (diff) | |
download | openbsd-d5e660940f76ba9fedb2400c0fa888e996ee93c9.tar.gz openbsd-d5e660940f76ba9fedb2400c0fa888e996ee93c9.tar.bz2 openbsd-d5e660940f76ba9fedb2400c0fa888e996ee93c9.zip |
Move handshake message handling functions from ssl_both.c to client/server.
Currently, ssl_both.c contains several functions that are used by both the
legacy client and legacy server. This interwines the client and server,
making it harder to make progressive changes. While it does deduplicate
some code, it also ends up with code that is conditioned on s->server and
forces the caller to pass in SSL3_ST_* values.
Move these functions from ssl_both.c into ssl_clnt.c and ssl_srvr.c,
renaming as appropriate and removing the s->server conditionals. Also move
the client and server function prototypes from ssl_locl.h into the .c
files, making them static in the process.
ok tb@
Diffstat (limited to 'src/lib/libssl/ssl_both.c')
-rw-r--r-- | src/lib/libssl/ssl_both.c | 148 |
1 files changed, 1 insertions, 147 deletions
diff --git a/src/lib/libssl/ssl_both.c b/src/lib/libssl/ssl_both.c index cfd32387d6..801b5bea29 100644 --- a/src/lib/libssl/ssl_both.c +++ b/src/lib/libssl/ssl_both.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ssl_both.c,v 1.42 2022/02/05 14:54:10 jsing Exp $ */ | 1 | /* $OpenBSD: ssl_both.c,v 1.43 2022/10/01 16:23:15 jsing Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -161,152 +161,6 @@ ssl3_do_write(SSL *s, int type) | |||
161 | return (0); | 161 | return (0); |
162 | } | 162 | } |
163 | 163 | ||
164 | int | ||
165 | ssl3_send_finished(SSL *s, int state_a, int state_b) | ||
166 | { | ||
167 | CBB cbb, finished; | ||
168 | |||
169 | memset(&cbb, 0, sizeof(cbb)); | ||
170 | |||
171 | if (s->s3->hs.state == state_a) { | ||
172 | if (!tls12_derive_finished(s)) | ||
173 | goto err; | ||
174 | |||
175 | /* Copy finished so we can use it for renegotiation checks. */ | ||
176 | if (!s->server) { | ||
177 | memcpy(s->s3->previous_client_finished, | ||
178 | s->s3->hs.finished, s->s3->hs.finished_len); | ||
179 | s->s3->previous_client_finished_len = | ||
180 | s->s3->hs.finished_len; | ||
181 | } else { | ||
182 | memcpy(s->s3->previous_server_finished, | ||
183 | s->s3->hs.finished, s->s3->hs.finished_len); | ||
184 | s->s3->previous_server_finished_len = | ||
185 | s->s3->hs.finished_len; | ||
186 | } | ||
187 | |||
188 | if (!ssl3_handshake_msg_start(s, &cbb, &finished, | ||
189 | SSL3_MT_FINISHED)) | ||
190 | goto err; | ||
191 | if (!CBB_add_bytes(&finished, s->s3->hs.finished, | ||
192 | s->s3->hs.finished_len)) | ||
193 | goto err; | ||
194 | if (!ssl3_handshake_msg_finish(s, &cbb)) | ||
195 | goto err; | ||
196 | |||
197 | s->s3->hs.state = state_b; | ||
198 | } | ||
199 | |||
200 | return (ssl3_handshake_write(s)); | ||
201 | |||
202 | err: | ||
203 | CBB_cleanup(&cbb); | ||
204 | |||
205 | return (-1); | ||
206 | } | ||
207 | |||
208 | int | ||
209 | ssl3_get_finished(SSL *s, int a, int b) | ||
210 | { | ||
211 | int al, md_len, ret; | ||
212 | CBS cbs; | ||
213 | |||
214 | /* should actually be 36+4 :-) */ | ||
215 | if ((ret = ssl3_get_message(s, a, b, SSL3_MT_FINISHED, 64)) <= 0) | ||
216 | return ret; | ||
217 | |||
218 | /* If this occurs, we have missed a message */ | ||
219 | if (!s->s3->change_cipher_spec) { | ||
220 | al = SSL_AD_UNEXPECTED_MESSAGE; | ||
221 | SSLerror(s, SSL_R_GOT_A_FIN_BEFORE_A_CCS); | ||
222 | goto fatal_err; | ||
223 | } | ||
224 | s->s3->change_cipher_spec = 0; | ||
225 | |||
226 | md_len = TLS1_FINISH_MAC_LENGTH; | ||
227 | |||
228 | if (s->internal->init_num < 0) { | ||
229 | al = SSL_AD_DECODE_ERROR; | ||
230 | SSLerror(s, SSL_R_BAD_DIGEST_LENGTH); | ||
231 | goto fatal_err; | ||
232 | } | ||
233 | |||
234 | CBS_init(&cbs, s->internal->init_msg, s->internal->init_num); | ||
235 | |||
236 | if (s->s3->hs.peer_finished_len != md_len || | ||
237 | CBS_len(&cbs) != md_len) { | ||
238 | al = SSL_AD_DECODE_ERROR; | ||
239 | SSLerror(s, SSL_R_BAD_DIGEST_LENGTH); | ||
240 | goto fatal_err; | ||
241 | } | ||
242 | |||
243 | if (!CBS_mem_equal(&cbs, s->s3->hs.peer_finished, CBS_len(&cbs))) { | ||
244 | al = SSL_AD_DECRYPT_ERROR; | ||
245 | SSLerror(s, SSL_R_DIGEST_CHECK_FAILED); | ||
246 | goto fatal_err; | ||
247 | } | ||
248 | |||
249 | /* Copy finished so we can use it for renegotiation checks. */ | ||
250 | OPENSSL_assert(md_len <= EVP_MAX_MD_SIZE); | ||
251 | if (s->server) { | ||
252 | memcpy(s->s3->previous_client_finished, | ||
253 | s->s3->hs.peer_finished, md_len); | ||
254 | s->s3->previous_client_finished_len = md_len; | ||
255 | } else { | ||
256 | memcpy(s->s3->previous_server_finished, | ||
257 | s->s3->hs.peer_finished, md_len); | ||
258 | s->s3->previous_server_finished_len = md_len; | ||
259 | } | ||
260 | |||
261 | return (1); | ||
262 | fatal_err: | ||
263 | ssl3_send_alert(s, SSL3_AL_FATAL, al); | ||
264 | return (0); | ||
265 | } | ||
266 | |||
267 | int | ||
268 | ssl3_send_change_cipher_spec(SSL *s, int a, int b) | ||
269 | { | ||
270 | size_t outlen; | ||
271 | CBB cbb; | ||
272 | |||
273 | memset(&cbb, 0, sizeof(cbb)); | ||
274 | |||
275 | if (s->s3->hs.state == a) { | ||
276 | if (!CBB_init_fixed(&cbb, s->internal->init_buf->data, | ||
277 | s->internal->init_buf->length)) | ||
278 | goto err; | ||
279 | if (!CBB_add_u8(&cbb, SSL3_MT_CCS)) | ||
280 | goto err; | ||
281 | if (!CBB_finish(&cbb, NULL, &outlen)) | ||
282 | goto err; | ||
283 | |||
284 | if (outlen > INT_MAX) | ||
285 | goto err; | ||
286 | |||
287 | s->internal->init_num = (int)outlen; | ||
288 | s->internal->init_off = 0; | ||
289 | |||
290 | if (SSL_is_dtls(s)) { | ||
291 | s->d1->handshake_write_seq = | ||
292 | s->d1->next_handshake_write_seq; | ||
293 | dtls1_set_message_header_int(s, SSL3_MT_CCS, 0, | ||
294 | s->d1->handshake_write_seq, 0, 0); | ||
295 | dtls1_buffer_message(s, 1); | ||
296 | } | ||
297 | |||
298 | s->s3->hs.state = b; | ||
299 | } | ||
300 | |||
301 | /* SSL3_ST_CW_CHANGE_B */ | ||
302 | return ssl3_record_write(s, SSL3_RT_CHANGE_CIPHER_SPEC); | ||
303 | |||
304 | err: | ||
305 | CBB_cleanup(&cbb); | ||
306 | |||
307 | return -1; | ||
308 | } | ||
309 | |||
310 | static int | 164 | static int |
311 | ssl3_add_cert(CBB *cbb, X509 *x) | 165 | ssl3_add_cert(CBB *cbb, X509 *x) |
312 | { | 166 | { |