-
Notifications
You must be signed in to change notification settings - Fork 948
DTLS 1.3: don't echo legacy_session_id in ServerHello #10007
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
6c972ad
7d4865c
bf9686e
6f6af91
9d11f91
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4653,6 +4653,13 @@ int SendTls13ClientHello(WOLFSSL* ssl) | |
| ssl->session->sessionIDSz = 0; | ||
| ssl->options.tls13MiddleBoxCompat = 0; | ||
| } | ||
| #endif | ||
| #ifdef WOLFSSL_DTLS13 | ||
| if (ssl->options.dtls) { | ||
| /* RFC 9147 Section 5: DTLS implementations do not use the | ||
| * TLS 1.3 "compatibility mode" */ | ||
| ssl->options.tls13MiddleBoxCompat = 0; | ||
| } | ||
| #endif | ||
| GetTls13SessionId(ssl, NULL, &sessIdSz); | ||
| args->length += (word16)sessIdSz; | ||
|
|
@@ -5596,16 +5603,25 @@ int DoTls13ServerHello(WOLFSSL* ssl, const byte* input, word32* inOutIdx, | |
| } | ||
| else | ||
| #endif /* WOLFSSL_TLS13_MIDDLEBOX_COMPAT */ | ||
| #if defined(WOLFSSL_QUIC) || defined(WOLFSSL_DTLS13) | ||
| if (0 | ||
| #ifdef WOLFSSL_QUIC | ||
| if (WOLFSSL_IS_QUIC(ssl)) { | ||
| || WOLFSSL_IS_QUIC(ssl) | ||
| #endif | ||
| #ifdef WOLFSSL_DTLS13 | ||
| || ssl->options.dtls | ||
| #endif | ||
| ) { | ||
| /* RFC 9147 Section 5.3 / RFC 9001 Section 8.4: DTLS 1.3 and QUIC | ||
| * ServerHello must have empty legacy_session_id_echo. */ | ||
| if (args->sessIdSz != 0) { | ||
| WOLFSSL_MSG("args->sessIdSz != 0"); | ||
| WOLFSSL_ERROR_VERBOSE(INVALID_PARAMETER); | ||
| return INVALID_PARAMETER; | ||
| } | ||
| } | ||
| else | ||
| #endif /* WOLFSSL_QUIC */ | ||
| #endif /* WOLFSSL_QUIC || WOLFSSL_DTLS13 */ | ||
| if (args->sessIdSz != ssl->session->sessionIDSz || (args->sessIdSz > 0 && | ||
| XMEMCMP(ssl->session->sessionID, args->sessId, args->sessIdSz) != 0)) | ||
| { | ||
|
|
@@ -6568,6 +6584,7 @@ static int RestartHandshakeHashWithCookie(WOLFSSL* ssl, Cookie* cookie) | |
| word16 length; | ||
| int keyShareExt = 0; | ||
| int ret; | ||
| byte sessIdSz; | ||
|
|
||
| ret = TlsCheckCookie(ssl, cookie->data, (byte)cookie->len); | ||
| if (ret < 0) | ||
|
|
@@ -6592,7 +6609,13 @@ static int RestartHandshakeHashWithCookie(WOLFSSL* ssl, Cookie* cookie) | |
| return ret; | ||
|
|
||
| /* Reconstruct the HelloRetryMessage for handshake hash. */ | ||
| length = HRR_BODY_SZ - ID_LEN + ssl->session->sessionIDSz + | ||
| sessIdSz = ssl->session->sessionIDSz; | ||
| #ifdef WOLFSSL_DTLS13 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please don't gather single if without the body as it makes the code very hard to read.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using var |
||
| /* RFC 9147 Section 5.3: DTLS 1.3 must use empty legacy_session_id. */ | ||
| if (ssl->options.dtls) | ||
| sessIdSz = 0; | ||
| #endif | ||
| length = HRR_BODY_SZ - ID_LEN + sessIdSz + | ||
| HRR_COOKIE_HDR_SZ + cookie->len; | ||
| length += HRR_VERSIONS_SZ; | ||
| /* HashSz (1 byte) + Hash (HashSz bytes) + CipherSuite (2 bytes) */ | ||
|
|
@@ -6619,10 +6642,10 @@ static int RestartHandshakeHashWithCookie(WOLFSSL* ssl, Cookie* cookie) | |
| XMEMCPY(hrr + hrrIdx, helloRetryRequestRandom, RAN_LEN); | ||
| hrrIdx += RAN_LEN; | ||
|
|
||
| hrr[hrrIdx++] = ssl->session->sessionIDSz; | ||
| if (ssl->session->sessionIDSz > 0) { | ||
| XMEMCPY(hrr + hrrIdx, ssl->session->sessionID, ssl->session->sessionIDSz); | ||
| hrrIdx += ssl->session->sessionIDSz; | ||
| hrr[hrrIdx++] = sessIdSz; | ||
| if (sessIdSz > 0) { | ||
| XMEMCPY(hrr + hrrIdx, ssl->session->sessionID, sessIdSz); | ||
| hrrIdx += sessIdSz; | ||
| } | ||
|
|
||
| /* Cipher Suite */ | ||
|
|
@@ -6633,7 +6656,7 @@ static int RestartHandshakeHashWithCookie(WOLFSSL* ssl, Cookie* cookie) | |
| hrr[hrrIdx++] = 0; | ||
|
|
||
| /* Extensions' length */ | ||
| length -= HRR_BODY_SZ - ID_LEN + ssl->session->sessionIDSz; | ||
| length -= HRR_BODY_SZ - ID_LEN + sessIdSz; | ||
| c16toa(length, hrr + hrrIdx); | ||
| hrrIdx += 2; | ||
|
|
||
|
|
@@ -7058,9 +7081,20 @@ int DoTls13ClientHello(WOLFSSL* ssl, const byte* input, word32* inOutIdx, | |
| if (sessIdSz + args->idx > helloSz) | ||
| ERROR_OUT(BUFFER_ERROR, exit_dch); | ||
|
|
||
| ssl->session->sessionIDSz = sessIdSz; | ||
| if (sessIdSz > 0) | ||
| XMEMCPY(ssl->session->sessionID, input + args->idx, sessIdSz); | ||
| #ifdef WOLFSSL_DTLS13 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. similar to comments above
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using var |
||
| /* RFC 9147 Section 5.3: DTLS 1.3 ServerHello must have empty | ||
| * legacy_session_id_echo. Don't store the client's value so it | ||
| * won't be echoed in SendTls13ServerHello. */ | ||
| if (ssl->options.dtls) { | ||
| ssl->session->sessionIDSz = 0; | ||
| } | ||
| else | ||
| #endif | ||
| { | ||
| ssl->session->sessionIDSz = sessIdSz; | ||
| if (sessIdSz > 0) | ||
| XMEMCPY(ssl->session->sessionID, input + args->idx, sessIdSz); | ||
| } | ||
julek-wolfssl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| args->idx += sessIdSz; | ||
|
|
||
| #ifdef WOLFSSL_TLS13_MIDDLEBOX_COMPAT | ||
|
|
@@ -7618,10 +7652,21 @@ int SendTls13ServerHello(WOLFSSL* ssl, byte extMsgType) | |
| WOLFSSL_BUFFER(ssl->arrays->serverRandom, RAN_LEN); | ||
| #endif | ||
|
|
||
| output[idx++] = ssl->session->sessionIDSz; | ||
| if (ssl->session->sessionIDSz > 0) { | ||
| XMEMCPY(output + idx, ssl->session->sessionID, ssl->session->sessionIDSz); | ||
| idx += ssl->session->sessionIDSz; | ||
| #ifdef WOLFSSL_DTLS13 | ||
| if (ssl->options.dtls) { | ||
| /* RFC 9147 Section 5.3: DTLS 1.3 ServerHello must have empty | ||
| * legacy_session_id_echo. */ | ||
| output[idx++] = 0; | ||
| } | ||
| else | ||
| #endif | ||
| { | ||
| output[idx++] = ssl->session->sessionIDSz; | ||
| if (ssl->session->sessionIDSz > 0) { | ||
| XMEMCPY(output + idx, ssl->session->sessionID, | ||
| ssl->session->sessionIDSz); | ||
| idx += ssl->session->sessionIDSz; | ||
| } | ||
| } | ||
|
|
||
| /* Chosen cipher suite */ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.