libressl / portable

LibreSSL Portable itself. This includes the build scaffold and compatibility layer that builds portable LibreSSL from the OpenBSD source code. Pull requests or patches sent to tech@openbsd.org are welcome.
https://www.libressl.org
1.35k stars 269 forks source link

[DTLS] Fail to handshake on server if server uses `SSL_CTX_set_max_send_fragment` #1096

Open nak3 opened 1 week ago

nak3 commented 1 week ago

description

https://github.com/libressl/openbsd/blob/3d60073121c9fed2d9a86b0ec752999b75409e21/src/lib/libssl/d1_both.c#L292-L305

            if (BIO_ctrl(SSL_get_wbio(s),
                BIO_CTRL_DGRAM_MTU_EXCEEDED, 0, NULL) > 0)
                s->d1->mtu = BIO_ctrl(SSL_get_wbio(s),
                    BIO_CTRL_DGRAM_QUERY_MTU, 0, NULL);
            else
                return (-1);

Reproducer

Proposal patch

diff --git src/lib/libssl/d1_both.c src/lib/libssl/d1_both.c
index b5c68a173..13f4baaf9 100644
--- src/lib/libssl/d1_both.c
+++ src/lib/libssl/d1_both.c
@@ -263,6 +263,10 @@ dtls1_do_write(SSL *s, int type)
                else
                        len = s->init_num;

+               if (len > s->max_send_fragment) {
+                       len = s->max_send_fragment;
+               }
+
                /* XDTLS: this function is too long.  split out the CCS part */
                if (type == SSL3_RT_HANDSHAKE) {
                        if (s->init_off != 0) {
@@ -274,6 +278,10 @@ dtls1_do_write(SSL *s, int type)
                                        len = curr_mtu;
                                else
                                        len = s->init_num;
+
+                               if (len > s->max_send_fragment) {
+                                       len = s->max_send_fragment;
+                               }
                        }

                        dtls1_fix_message_header(s, frag_off,