@@ -4570,8 +4570,8 @@ int SendTls13ClientHello(WOLFSSL* ssl)
45704570 }
45714571#endif /* WOLFSSL_DTLS */
45724572
4573- #ifdef HAVE_SESSION_TICKET
45744573 if (ssl->options.resuming &&
4574+ ssl->session->version.major != 0 &&
45754575 (ssl->session->version.major != ssl->version.major ||
45764576 ssl->session->version.minor != ssl->version.minor)) {
45774577 #ifndef WOLFSSL_NO_TLS12
@@ -4590,7 +4590,6 @@ int SendTls13ClientHello(WOLFSSL* ssl)
45904590 return VERSION_ERROR;
45914591 }
45924592 }
4593- #endif
45944593
45954594 suites = WOLFSSL_SUITES(ssl);
45964595 if (suites == NULL) {
@@ -4644,6 +4643,13 @@ int SendTls13ClientHello(WOLFSSL* ssl)
46444643 ssl->session->sessionIDSz = 0;
46454644 ssl->options.tls13MiddleBoxCompat = 0;
46464645 }
4646+ #endif
4647+ #ifdef WOLFSSL_DTLS13
4648+ if (ssl->options.dtls) {
4649+ /* RFC 9147 Section 5: DTLS implementations do not use the
4650+ * TLS 1.3 "compatibility mode" */
4651+ ssl->options.tls13MiddleBoxCompat = 0;
4652+ }
46474653#endif
46484654 GetTls13SessionId(ssl, NULL, &sessIdSz);
46494655 args->length += (word16)sessIdSz;
@@ -5587,16 +5593,25 @@ int DoTls13ServerHello(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
55875593 }
55885594 else
55895595#endif /* WOLFSSL_TLS13_MIDDLEBOX_COMPAT */
5596+ #if defined(WOLFSSL_QUIC) || defined(WOLFSSL_DTLS13)
5597+ if (0
55905598#ifdef WOLFSSL_QUIC
5591- if (WOLFSSL_IS_QUIC(ssl)) {
5599+ || WOLFSSL_IS_QUIC(ssl)
5600+ #endif
5601+ #ifdef WOLFSSL_DTLS13
5602+ || ssl->options.dtls
5603+ #endif
5604+ ) {
5605+ /* RFC 9147 Section 5.3 / RFC 9001 Section 8.4: DTLS 1.3 and QUIC
5606+ * ServerHello must have empty legacy_session_id_echo. */
55925607 if (args->sessIdSz != 0) {
55935608 WOLFSSL_MSG("args->sessIdSz != 0");
55945609 WOLFSSL_ERROR_VERBOSE(INVALID_PARAMETER);
55955610 return INVALID_PARAMETER;
55965611 }
55975612 }
55985613 else
5599- #endif /* WOLFSSL_QUIC */
5614+ #endif /* WOLFSSL_QUIC || WOLFSSL_DTLS13 */
56005615 if (args->sessIdSz != ssl->session->sessionIDSz || (args->sessIdSz > 0 &&
56015616 XMEMCMP(ssl->session->sessionID, args->sessId, args->sessIdSz) != 0))
56025617 {
@@ -6559,6 +6574,7 @@ static int RestartHandshakeHashWithCookie(WOLFSSL* ssl, Cookie* cookie)
65596574 word16 length;
65606575 int keyShareExt = 0;
65616576 int ret;
6577+ byte sessIdSz;
65626578
65636579 ret = TlsCheckCookie(ssl, cookie->data, (byte)cookie->len);
65646580 if (ret < 0)
@@ -6583,7 +6599,13 @@ static int RestartHandshakeHashWithCookie(WOLFSSL* ssl, Cookie* cookie)
65836599 return ret;
65846600
65856601 /* Reconstruct the HelloRetryMessage for handshake hash. */
6586- length = HRR_BODY_SZ - ID_LEN + ssl->session->sessionIDSz +
6602+ sessIdSz = ssl->session->sessionIDSz;
6603+ #ifdef WOLFSSL_DTLS13
6604+ /* RFC 9147 Section 5.3: DTLS 1.3 must use empty legacy_session_id. */
6605+ if (ssl->options.dtls)
6606+ sessIdSz = 0;
6607+ #endif
6608+ length = HRR_BODY_SZ - ID_LEN + sessIdSz +
65876609 HRR_COOKIE_HDR_SZ + cookie->len;
65886610 length += HRR_VERSIONS_SZ;
65896611 /* HashSz (1 byte) + Hash (HashSz bytes) + CipherSuite (2 bytes) */
@@ -6610,10 +6632,10 @@ static int RestartHandshakeHashWithCookie(WOLFSSL* ssl, Cookie* cookie)
66106632 XMEMCPY(hrr + hrrIdx, helloRetryRequestRandom, RAN_LEN);
66116633 hrrIdx += RAN_LEN;
66126634
6613- hrr[hrrIdx++] = ssl->session->sessionIDSz ;
6614- if (ssl->session->sessionIDSz > 0) {
6615- XMEMCPY(hrr + hrrIdx, ssl->session->sessionID, ssl->session->sessionIDSz );
6616- hrrIdx += ssl->session->sessionIDSz ;
6635+ hrr[hrrIdx++] = sessIdSz ;
6636+ if (sessIdSz > 0) {
6637+ XMEMCPY(hrr + hrrIdx, ssl->session->sessionID, sessIdSz );
6638+ hrrIdx += sessIdSz ;
66176639 }
66186640
66196641 /* Restore the cipher suite from the cookie. */
@@ -6626,7 +6648,7 @@ static int RestartHandshakeHashWithCookie(WOLFSSL* ssl, Cookie* cookie)
66266648 hrr[hrrIdx++] = 0;
66276649
66286650 /* Extensions' length */
6629- length -= HRR_BODY_SZ - ID_LEN + ssl->session->sessionIDSz ;
6651+ length -= HRR_BODY_SZ - ID_LEN + sessIdSz ;
66306652 c16toa(length, hrr + hrrIdx);
66316653 hrrIdx += 2;
66326654
@@ -7051,9 +7073,20 @@ int DoTls13ClientHello(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
70517073 if (sessIdSz + args->idx > helloSz)
70527074 ERROR_OUT(BUFFER_ERROR, exit_dch);
70537075
7054- ssl->session->sessionIDSz = sessIdSz;
7055- if (sessIdSz > 0)
7056- XMEMCPY(ssl->session->sessionID, input + args->idx, sessIdSz);
7076+ #ifdef WOLFSSL_DTLS13
7077+ /* RFC 9147 Section 5.3: DTLS 1.3 ServerHello must have empty
7078+ * legacy_session_id_echo. Don't store the client's value so it
7079+ * won't be echoed in SendTls13ServerHello. */
7080+ if (ssl->options.dtls) {
7081+ ssl->session->sessionIDSz = 0;
7082+ }
7083+ else
7084+ #endif
7085+ {
7086+ ssl->session->sessionIDSz = sessIdSz;
7087+ if (sessIdSz > 0)
7088+ XMEMCPY(ssl->session->sessionID, input + args->idx, sessIdSz);
7089+ }
70577090 args->idx += sessIdSz;
70587091
70597092#ifdef WOLFSSL_TLS13_MIDDLEBOX_COMPAT
@@ -7626,10 +7659,21 @@ int SendTls13ServerHello(WOLFSSL* ssl, byte extMsgType)
76267659 WOLFSSL_BUFFER(ssl->arrays->serverRandom, RAN_LEN);
76277660#endif
76287661
7629- output[idx++] = ssl->session->sessionIDSz;
7630- if (ssl->session->sessionIDSz > 0) {
7631- XMEMCPY(output + idx, ssl->session->sessionID, ssl->session->sessionIDSz);
7632- idx += ssl->session->sessionIDSz;
7662+ #ifdef WOLFSSL_DTLS13
7663+ if (ssl->options.dtls) {
7664+ /* RFC 9147 Section 5.3: DTLS 1.3 ServerHello must have empty
7665+ * legacy_session_id_echo. */
7666+ output[idx++] = 0;
7667+ }
7668+ else
7669+ #endif
7670+ {
7671+ output[idx++] = ssl->session->sessionIDSz;
7672+ if (ssl->session->sessionIDSz > 0) {
7673+ XMEMCPY(output + idx, ssl->session->sessionID,
7674+ ssl->session->sessionIDSz);
7675+ idx += ssl->session->sessionIDSz;
7676+ }
76337677 }
76347678
76357679 /* Chosen cipher suite */
0 commit comments