Skip to content

Commit 762c76f

Browse files
committed
dtls: add compat flag for buggy pre 5.9.0 DTLSv1.3 clients
1 parent 9096bcc commit 762c76f

2 files changed

Lines changed: 20 additions & 5 deletions

File tree

src/dtls.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,11 +635,12 @@ 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 */
638+
#ifdef WOLFSSL_DTLS13_5_9_0_COMPAT
639639
if (ch->sessionId.size > ID_LEN) {
640640
/* Too large. We can't echo this. */
641641
ERROR_OUT(INVALID_PARAMETER, dtls13_cleanup);
642642
}
643+
#endif
643644

644645
/* Populate the suites struct to find a common ciphersuite */
645646
XMEMSET(&suites, 0, sizeof(suites));
@@ -861,9 +862,16 @@ static int SendStatelessReplyDtls13(const WOLFSSL* ssl, WolfSSL_CH* ch)
861862
nonConstSSL->options.tls1_1 = 1;
862863
nonConstSSL->options.tls1_3 = 1;
863864

865+
#ifdef WOLFSSL_DTLS13_5_9_0_COMPAT
866+
nonConstSSL->session->sessionIDSz = (byte)ch->sessionId.size;
867+
if (ch->sessionId.size > 0)
868+
XMEMCPY(nonConstSSL->session->sessionID, ch->sessionId.elements,
869+
ch->sessionId.size);
870+
#else
864871
/* RFC 9147 Section 5.3: DTLS 1.3 ServerHello must have empty
865872
* legacy_session_id_echo. Don't copy the client's session ID. */
866873
nonConstSSL->session->sessionIDSz = 0;
874+
#endif
867875
nonConstSSL->options.cipherSuite0 = cs.cipherSuite0;
868876
nonConstSSL->options.cipherSuite = cs.cipherSuite;
869877
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;
@@ -6979,7 +6986,7 @@ static int RestartHandshakeHashWithCookie(WOLFSSL* ssl, Cookie* cookie)
69796986

69806987
/* Reconstruct the HelloRetryMessage for handshake hash. */
69816988
sessIdSz = ssl->session->sessionIDSz;
6982-
#ifdef WOLFSSL_DTLS13
6989+
#if defined(WOLFSSL_DTLS13) && !defined(WOLFSSL_DTLS13_5_9_0_COMPAT)
69836990
/* RFC 9147 Section 5.3: DTLS 1.3 must use empty legacy_session_id. */
69846991
if (ssl->options.dtls)
69856992
sessIdSz = 0;
@@ -7459,7 +7466,7 @@ int DoTls13ClientHello(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
74597466
if (sessIdSz + args->idx > helloSz)
74607467
ERROR_OUT(BUFFER_ERROR, exit_dch);
74617468

7462-
#ifdef WOLFSSL_DTLS13
7469+
#if defined(WOLFSSL_DTLS13) && !defined(WOLFSSL_DTLS13_5_9_0_COMPAT)
74637470
/* RFC 9147 Section 5.3: DTLS 1.3 ServerHello must have empty
74647471
* legacy_session_id_echo. Don't store the client's value so it
74657472
* won't be echoed in SendTls13ServerHello. */
@@ -8064,7 +8071,7 @@ int SendTls13ServerHello(WOLFSSL* ssl, byte extMsgType)
80648071
WOLFSSL_BUFFER(ssl->arrays->serverRandom, RAN_LEN);
80658072
#endif
80668073

8067-
#ifdef WOLFSSL_DTLS13
8074+
#if defined(WOLFSSL_DTLS13) && !defined(WOLFSSL_DTLS13_5_9_0_COMPAT)
80688075
if (ssl->options.dtls) {
80698076
/* RFC 9147 Section 5.3: DTLS 1.3 ServerHello must have empty
80708077
* legacy_session_id_echo. */

0 commit comments

Comments
 (0)