Skip to content

Commit 8f47735

Browse files
committed
dtls: add compat flag for buggy pre 5.9.0 DTLSv1.3 clients
1 parent 887f242 commit 8f47735

3 files changed

Lines changed: 20 additions & 6 deletions

File tree

.wolfssl_known_macro_extras

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,7 @@ WOLFSSL_DRBG_SHA256
744744
WOLFSSL_DTLS_DISALLOW_FUTURE
745745
WOLFSSL_DTLS_RECORDS_CAN_SPAN_DATAGRAMS
746746
WOLFSSL_DTLS_RESEND_ONLY_TIMEOUT
747+
WOLFSSL_DTLS13_5_9_0_COMPAT
747748
WOLFSSL_DUMP_MEMIO_STREAM
748749
WOLFSSL_DUP_CERTPOL
749750
WOLFSSL_EARLY_DATA_NO_ANTI_REPLAY

src/dtls.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -635,9 +635,8 @@ static int SendStatelessReplyDtls13(const WOLFSSL* ssl, WolfSSL_CH* ch)
635635

636636
XMEMSET(&cs, 0, sizeof(cs));
637637

638-
/* We need to echo the session ID sent by the client */
639638
if (ch->sessionId.size > ID_LEN) {
640-
/* Too large. We can't echo this. */
639+
/* Too large */
641640
ERROR_OUT(INVALID_PARAMETER, dtls13_cleanup);
642641
}
643642

@@ -861,9 +860,16 @@ static int SendStatelessReplyDtls13(const WOLFSSL* ssl, WolfSSL_CH* ch)
861860
nonConstSSL->options.tls1_1 = 1;
862861
nonConstSSL->options.tls1_3 = 1;
863862

863+
#ifdef WOLFSSL_DTLS13_5_9_0_COMPAT
864+
nonConstSSL->session->sessionIDSz = (byte)ch->sessionId.size;
865+
if (ch->sessionId.size > 0)
866+
XMEMCPY(nonConstSSL->session->sessionID, ch->sessionId.elements,
867+
ch->sessionId.size);
868+
#else
864869
/* RFC 9147 Section 5.3: DTLS 1.3 ServerHello must have empty
865870
* legacy_session_id_echo. Don't copy the client's session ID. */
866871
nonConstSSL->session->sessionIDSz = 0;
872+
#endif
867873
nonConstSSL->options.cipherSuite0 = cs.cipherSuite0;
868874
nonConstSSL->options.cipherSuite = cs.cipherSuite;
869875
nonConstSSL->extensions = parsedExts;

src/tls13.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5775,7 +5775,14 @@ int DoTls13ServerHello(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
57755775
) {
57765776
/* RFC 9147 Section 5.3 / RFC 9001 Section 8.4: DTLS 1.3 and QUIC
57775777
* ServerHello must have empty legacy_session_id_echo. */
5778-
if (args->sessIdSz != 0) {
5778+
int requireEmptyEcho = 1;
5779+
#ifdef WOLFSSL_DTLS13_5_9_0_COMPAT
5780+
/* Compat: a wolfSSL <= 5.9.0 DTLS 1.3 server echoes the client's
5781+
* legacy_session_id; accept any echo. */
5782+
if (ssl->options.dtls)
5783+
requireEmptyEcho = 0;
5784+
#endif
5785+
if (requireEmptyEcho && args->sessIdSz != 0) {
57795786
WOLFSSL_MSG("args->sessIdSz != 0");
57805787
WOLFSSL_ERROR_VERBOSE(INVALID_PARAMETER);
57815788
return INVALID_PARAMETER;
@@ -6973,7 +6980,7 @@ static int RestartHandshakeHashWithCookie(WOLFSSL* ssl, Cookie* cookie)
69736980

69746981
/* Reconstruct the HelloRetryMessage for handshake hash. */
69756982
sessIdSz = ssl->session->sessionIDSz;
6976-
#ifdef WOLFSSL_DTLS13
6983+
#if defined(WOLFSSL_DTLS13) && !defined(WOLFSSL_DTLS13_5_9_0_COMPAT)
69776984
/* RFC 9147 Section 5.3: DTLS 1.3 must use empty legacy_session_id. */
69786985
if (ssl->options.dtls)
69796986
sessIdSz = 0;
@@ -7453,7 +7460,7 @@ int DoTls13ClientHello(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
74537460
if (sessIdSz + args->idx > helloSz)
74547461
ERROR_OUT(BUFFER_ERROR, exit_dch);
74557462

7456-
#ifdef WOLFSSL_DTLS13
7463+
#if defined(WOLFSSL_DTLS13) && !defined(WOLFSSL_DTLS13_5_9_0_COMPAT)
74577464
/* RFC 9147 Section 5.3: DTLS 1.3 ServerHello must have empty
74587465
* legacy_session_id_echo. Don't store the client's value so it
74597466
* won't be echoed in SendTls13ServerHello. */
@@ -8058,7 +8065,7 @@ int SendTls13ServerHello(WOLFSSL* ssl, byte extMsgType)
80588065
WOLFSSL_BUFFER(ssl->arrays->serverRandom, RAN_LEN);
80598066
#endif
80608067

8061-
#ifdef WOLFSSL_DTLS13
8068+
#if defined(WOLFSSL_DTLS13) && !defined(WOLFSSL_DTLS13_5_9_0_COMPAT)
80628069
if (ssl->options.dtls) {
80638070
/* RFC 9147 Section 5.3: DTLS 1.3 ServerHello must have empty
80648071
* legacy_session_id_echo. */

0 commit comments

Comments
 (0)