diff options
author | jsing <> | 2017-10-08 16:24:02 +0000 |
---|---|---|
committer | jsing <> | 2017-10-08 16:24:02 +0000 |
commit | 759dd02e3ff981ea9d2869cfe079c8f201eba19d (patch) | |
tree | 3353b68b503515d359d87d0e023b6b9bc1e1453c | |
parent | a5b4d2c04b558a0cdaf1eaacb3f83fcc27e23de7 (diff) | |
download | openbsd-759dd02e3ff981ea9d2869cfe079c8f201eba19d.tar.gz openbsd-759dd02e3ff981ea9d2869cfe079c8f201eba19d.tar.bz2 openbsd-759dd02e3ff981ea9d2869cfe079c8f201eba19d.zip |
Convert ssl3_send_change_cipher_spec() to use CBB and make it handle DTLS,
which allows us to drop dtls1_send_change_cipher_spec() entirely.
ok inoguchi@
-rw-r--r-- | src/lib/libssl/d1_both.c | 41 | ||||
-rw-r--r-- | src/lib/libssl/d1_clnt.c | 4 | ||||
-rw-r--r-- | src/lib/libssl/d1_srvr.c | 7 | ||||
-rw-r--r-- | src/lib/libssl/s3_lib.c | 12 | ||||
-rw-r--r-- | src/lib/libssl/ssl_both.c | 37 | ||||
-rw-r--r-- | src/lib/libssl/ssl_locl.h | 8 |
6 files changed, 52 insertions, 57 deletions
diff --git a/src/lib/libssl/d1_both.c b/src/lib/libssl/d1_both.c index 6b86cfc03e..42f8cbd537 100644 --- a/src/lib/libssl/d1_both.c +++ b/src/lib/libssl/d1_both.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: d1_both.c,v 1.51 2017/05/07 04:22:24 beck Exp $ */ | 1 | /* $OpenBSD: d1_both.c,v 1.52 2017/10/08 16:24:02 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * DTLS implementation written by Nagendra Modadugu | 3 | * DTLS implementation written by Nagendra Modadugu |
4 | * (nagendra@cs.stanford.edu) for the OpenSSL project 2005. | 4 | * (nagendra@cs.stanford.edu) for the OpenSSL project 2005. |
@@ -162,9 +162,6 @@ static unsigned int dtls1_guess_mtu(unsigned int curr_mtu); | |||
162 | static void dtls1_fix_message_header(SSL *s, unsigned long frag_off, | 162 | static void dtls1_fix_message_header(SSL *s, unsigned long frag_off, |
163 | unsigned long frag_len); | 163 | unsigned long frag_len); |
164 | static unsigned char *dtls1_write_message_header(SSL *s, unsigned char *p); | 164 | static unsigned char *dtls1_write_message_header(SSL *s, unsigned char *p); |
165 | static void dtls1_set_message_header_int(SSL *s, unsigned char mt, | ||
166 | unsigned long len, unsigned short seq_num, unsigned long frag_off, | ||
167 | unsigned long frag_len); | ||
168 | static long dtls1_get_message_fragment(SSL *s, int st1, int stn, long max, | 165 | static long dtls1_get_message_fragment(SSL *s, int st1, int stn, long max, |
169 | int *ok); | 166 | int *ok); |
170 | 167 | ||
@@ -895,40 +892,6 @@ f_err: | |||
895 | return (-1); | 892 | return (-1); |
896 | } | 893 | } |
897 | 894 | ||
898 | /* | ||
899 | * for these 2 messages, we need to | ||
900 | * ssl->enc_read_ctx re-init | ||
901 | * ssl->s3->internal->read_sequence zero | ||
902 | * ssl->s3->internal->read_mac_secret re-init | ||
903 | * ssl->session->read_sym_enc assign | ||
904 | * ssl->session->read_hash assign | ||
905 | */ | ||
906 | int | ||
907 | dtls1_send_change_cipher_spec(SSL *s, int a, int b) | ||
908 | { | ||
909 | unsigned char *p; | ||
910 | |||
911 | if (S3I(s)->hs.state == a) { | ||
912 | p = (unsigned char *)s->internal->init_buf->data; | ||
913 | *p++=SSL3_MT_CCS; | ||
914 | D1I(s)->handshake_write_seq = D1I(s)->next_handshake_write_seq; | ||
915 | s->internal->init_num = DTLS1_CCS_HEADER_LENGTH; | ||
916 | |||
917 | s->internal->init_off = 0; | ||
918 | |||
919 | dtls1_set_message_header_int(s, SSL3_MT_CCS, 0, | ||
920 | D1I(s)->handshake_write_seq, 0, 0); | ||
921 | |||
922 | /* buffer the message to handle re-xmits */ | ||
923 | dtls1_buffer_message(s, 1); | ||
924 | |||
925 | S3I(s)->hs.state = b; | ||
926 | } | ||
927 | |||
928 | /* SSL3_ST_CW_CHANGE_B */ | ||
929 | return (dtls1_do_write(s, SSL3_RT_CHANGE_CIPHER_SPEC)); | ||
930 | } | ||
931 | |||
932 | int | 895 | int |
933 | dtls1_read_failed(SSL *s, int code) | 896 | dtls1_read_failed(SSL *s, int code) |
934 | { | 897 | { |
@@ -1182,7 +1145,7 @@ dtls1_set_message_header(SSL *s, unsigned char mt, unsigned long len, | |||
1182 | } | 1145 | } |
1183 | 1146 | ||
1184 | /* don't actually do the writing, wait till the MTU has been retrieved */ | 1147 | /* don't actually do the writing, wait till the MTU has been retrieved */ |
1185 | static void | 1148 | void |
1186 | dtls1_set_message_header_int(SSL *s, unsigned char mt, unsigned long len, | 1149 | dtls1_set_message_header_int(SSL *s, unsigned char mt, unsigned long len, |
1187 | unsigned short seq_num, unsigned long frag_off, unsigned long frag_len) | 1150 | unsigned short seq_num, unsigned long frag_off, unsigned long frag_len) |
1188 | { | 1151 | { |
diff --git a/src/lib/libssl/d1_clnt.c b/src/lib/libssl/d1_clnt.c index 3eebf98417..c9447138d5 100644 --- a/src/lib/libssl/d1_clnt.c +++ b/src/lib/libssl/d1_clnt.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: d1_clnt.c,v 1.76 2017/05/07 04:22:24 beck Exp $ */ | 1 | /* $OpenBSD: d1_clnt.c,v 1.77 2017/10/08 16:24:02 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * DTLS implementation written by Nagendra Modadugu | 3 | * DTLS implementation written by Nagendra Modadugu |
4 | * (nagendra@cs.stanford.edu) for the OpenSSL project 2005. | 4 | * (nagendra@cs.stanford.edu) for the OpenSSL project 2005. |
@@ -427,7 +427,7 @@ dtls1_connect(SSL *s) | |||
427 | case SSL3_ST_CW_CHANGE_B: | 427 | case SSL3_ST_CW_CHANGE_B: |
428 | if (!s->internal->hit) | 428 | if (!s->internal->hit) |
429 | dtls1_start_timer(s); | 429 | dtls1_start_timer(s); |
430 | ret = dtls1_send_change_cipher_spec(s, | 430 | ret = ssl3_send_change_cipher_spec(s, |
431 | SSL3_ST_CW_CHANGE_A, SSL3_ST_CW_CHANGE_B); | 431 | SSL3_ST_CW_CHANGE_A, SSL3_ST_CW_CHANGE_B); |
432 | if (ret <= 0) | 432 | if (ret <= 0) |
433 | goto end; | 433 | goto end; |
diff --git a/src/lib/libssl/d1_srvr.c b/src/lib/libssl/d1_srvr.c index ae90ee2093..f0e59a8e00 100644 --- a/src/lib/libssl/d1_srvr.c +++ b/src/lib/libssl/d1_srvr.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: d1_srvr.c,v 1.88 2017/05/07 04:22:24 beck Exp $ */ | 1 | /* $OpenBSD: d1_srvr.c,v 1.89 2017/10/08 16:24:02 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * DTLS implementation written by Nagendra Modadugu | 3 | * DTLS implementation written by Nagendra Modadugu |
4 | * (nagendra@cs.stanford.edu) for the OpenSSL project 2005. | 4 | * (nagendra@cs.stanford.edu) for the OpenSSL project 2005. |
@@ -596,9 +596,8 @@ dtls1_accept(SSL *s) | |||
596 | goto end; | 596 | goto end; |
597 | } | 597 | } |
598 | 598 | ||
599 | ret = dtls1_send_change_cipher_spec(s, | 599 | ret = ssl3_send_change_cipher_spec(s, |
600 | SSL3_ST_SW_CHANGE_A, SSL3_ST_SW_CHANGE_B); | 600 | SSL3_ST_SW_CHANGE_A, SSL3_ST_SW_CHANGE_B); |
601 | |||
602 | if (ret <= 0) | 601 | if (ret <= 0) |
603 | goto end; | 602 | goto end; |
604 | 603 | ||
diff --git a/src/lib/libssl/s3_lib.c b/src/lib/libssl/s3_lib.c index a05116cb8f..89af1ef3bf 100644 --- a/src/lib/libssl/s3_lib.c +++ b/src/lib/libssl/s3_lib.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: s3_lib.c,v 1.161 2017/09/25 18:04:08 jsing Exp $ */ | 1 | /* $OpenBSD: s3_lib.c,v 1.162 2017/10/08 16:24:02 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 | * |
@@ -1553,10 +1553,16 @@ ssl3_handshake_msg_finish_cbb(SSL *s, CBB *handshake) | |||
1553 | int | 1553 | int |
1554 | ssl3_handshake_write(SSL *s) | 1554 | ssl3_handshake_write(SSL *s) |
1555 | { | 1555 | { |
1556 | return ssl3_record_write(s, SSL3_RT_HANDSHAKE); | ||
1557 | } | ||
1558 | |||
1559 | int | ||
1560 | ssl3_record_write(SSL *s, int type) | ||
1561 | { | ||
1556 | if (SSL_IS_DTLS(s)) | 1562 | if (SSL_IS_DTLS(s)) |
1557 | return dtls1_do_write(s, SSL3_RT_HANDSHAKE); | 1563 | return dtls1_do_write(s, type); |
1558 | 1564 | ||
1559 | return ssl3_do_write(s, SSL3_RT_HANDSHAKE); | 1565 | return ssl3_do_write(s, type); |
1560 | } | 1566 | } |
1561 | 1567 | ||
1562 | int | 1568 | int |
diff --git a/src/lib/libssl/ssl_both.c b/src/lib/libssl/ssl_both.c index 17f93f551b..03f95977f7 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.10 2017/08/12 02:55:22 jsing Exp $ */ | 1 | /* $OpenBSD: ssl_both.c,v 1.11 2017/10/08 16:24:02 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 | * |
@@ -311,19 +311,44 @@ f_err: | |||
311 | int | 311 | int |
312 | ssl3_send_change_cipher_spec(SSL *s, int a, int b) | 312 | ssl3_send_change_cipher_spec(SSL *s, int a, int b) |
313 | { | 313 | { |
314 | unsigned char *p; | 314 | size_t outlen; |
315 | CBB cbb; | ||
316 | |||
317 | memset(&cbb, 0, sizeof(cbb)); | ||
315 | 318 | ||
316 | if (S3I(s)->hs.state == a) { | 319 | if (S3I(s)->hs.state == a) { |
317 | p = (unsigned char *)s->internal->init_buf->data; | 320 | if (!CBB_init_fixed(&cbb, s->internal->init_buf->data, |
318 | *p = SSL3_MT_CCS; | 321 | s->internal->init_buf->length)) |
319 | s->internal->init_num = 1; | 322 | goto err; |
323 | if (!CBB_add_u8(&cbb, SSL3_MT_CCS)) | ||
324 | goto err; | ||
325 | if (!CBB_finish(&cbb, NULL, &outlen)) | ||
326 | goto err; | ||
327 | |||
328 | if (outlen > INT_MAX) | ||
329 | goto err; | ||
330 | |||
331 | s->internal->init_num = (int)outlen; | ||
320 | s->internal->init_off = 0; | 332 | s->internal->init_off = 0; |
321 | 333 | ||
334 | if (SSL_IS_DTLS(s)) { | ||
335 | D1I(s)->handshake_write_seq = | ||
336 | D1I(s)->next_handshake_write_seq; | ||
337 | dtls1_set_message_header_int(s, SSL3_MT_CCS, 0, | ||
338 | D1I(s)->handshake_write_seq, 0, 0); | ||
339 | dtls1_buffer_message(s, 1); | ||
340 | } | ||
341 | |||
322 | S3I(s)->hs.state = b; | 342 | S3I(s)->hs.state = b; |
323 | } | 343 | } |
324 | 344 | ||
325 | /* SSL3_ST_CW_CHANGE_B */ | 345 | /* SSL3_ST_CW_CHANGE_B */ |
326 | return (ssl3_do_write(s, SSL3_RT_CHANGE_CIPHER_SPEC)); | 346 | return ssl3_record_write(s, SSL3_RT_CHANGE_CIPHER_SPEC); |
347 | |||
348 | err: | ||
349 | CBB_cleanup(&cbb); | ||
350 | |||
351 | return -1; | ||
327 | } | 352 | } |
328 | 353 | ||
329 | static int | 354 | static int |
diff --git a/src/lib/libssl/ssl_locl.h b/src/lib/libssl/ssl_locl.h index 17a4a0d4f6..2fec36fba9 100644 --- a/src/lib/libssl/ssl_locl.h +++ b/src/lib/libssl/ssl_locl.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ssl_locl.h,v 1.193 2017/08/28 16:37:04 jsing Exp $ */ | 1 | /* $OpenBSD: ssl_locl.h,v 1.194 2017/10/08 16:24:02 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 | * |
@@ -1147,6 +1147,7 @@ int ssl3_handshake_msg_start_cbb(SSL *s, CBB *handshake, CBB *body, | |||
1147 | uint8_t msg_type); | 1147 | uint8_t msg_type); |
1148 | int ssl3_handshake_msg_finish_cbb(SSL *s, CBB *handshake); | 1148 | int ssl3_handshake_msg_finish_cbb(SSL *s, CBB *handshake); |
1149 | int ssl3_handshake_write(SSL *s); | 1149 | int ssl3_handshake_write(SSL *s); |
1150 | int ssl3_record_write(SSL *s, int type); | ||
1150 | 1151 | ||
1151 | void tls1_record_sequence_increment(unsigned char *seq); | 1152 | void tls1_record_sequence_increment(unsigned char *seq); |
1152 | int ssl3_do_change_cipher_spec(SSL *ssl); | 1153 | int ssl3_do_change_cipher_spec(SSL *ssl); |
@@ -1166,12 +1167,13 @@ int ssl3_write_pending(SSL *s, int type, const unsigned char *buf, | |||
1166 | unsigned int len); | 1167 | unsigned int len); |
1167 | void dtls1_set_message_header(SSL *s, unsigned char mt, unsigned long len, | 1168 | void dtls1_set_message_header(SSL *s, unsigned char mt, unsigned long len, |
1168 | unsigned long frag_off, unsigned long frag_len); | 1169 | unsigned long frag_off, unsigned long frag_len); |
1170 | void dtls1_set_message_header_int(SSL *s, unsigned char mt, | ||
1171 | unsigned long len, unsigned short seq_num, unsigned long frag_off, | ||
1172 | unsigned long frag_len); | ||
1169 | 1173 | ||
1170 | int dtls1_write_app_data_bytes(SSL *s, int type, const void *buf, int len); | 1174 | int dtls1_write_app_data_bytes(SSL *s, int type, const void *buf, int len); |
1171 | int dtls1_write_bytes(SSL *s, int type, const void *buf, int len); | 1175 | int dtls1_write_bytes(SSL *s, int type, const void *buf, int len); |
1172 | 1176 | ||
1173 | int dtls1_send_change_cipher_spec(SSL *s, int a, int b); | ||
1174 | unsigned long dtls1_output_cert_chain(SSL *s, X509 *x); | ||
1175 | int dtls1_read_failed(SSL *s, int code); | 1177 | int dtls1_read_failed(SSL *s, int code); |
1176 | int dtls1_buffer_message(SSL *s, int ccs); | 1178 | int dtls1_buffer_message(SSL *s, int ccs); |
1177 | int dtls1_retransmit_message(SSL *s, unsigned short seq, | 1179 | int dtls1_retransmit_message(SSL *s, unsigned short seq, |