1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-04-19 01:04:04 +03:00

337 Commits

Author SHA1 Message Date
Gilles Peskine
ad84044386 Test split, coalesced-split and empty handshake records
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-04-01 10:39:48 +02:00
Gilles Peskine
49f179d9c8 Always call mbedtls_ssl_handshake_set_state
Call a single function for all handshake state changes, for easier tracing.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-04-01 10:39:04 +02:00
Manuel Pégourié-Gonnard
8a4ec49671 Cleanly reject non-HS in-between HS fragments
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2025-03-10 21:38:48 +01:00
Gilles Peskine
c22e315086 Fix a log message
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-03-07 10:44:57 +01:00
Gilles Peskine
229e200cb4 Note unused variables when debugging is disabled
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-03-06 21:33:32 +01:00
Gilles Peskine
dee926359c Pacify uncrustify
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-03-06 21:33:29 +01:00
Gilles Peskine
0a467ccd24 Unify handshake fragment log messages
There is no longer any different processing at this point, just
near-identical log messages.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-03-06 19:22:52 +01:00
Gilles Peskine
b888cca5b6 Fix handshake defragmentation when the record has multiple messages
A handshake record may contain multiple handshake messages, or multiple
fragments (there can be the final fragment of a pending message, then zero
or more whole messages, and an initial fragment of an incomplete message).
This was previously untested, but supported, so don't break it.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-03-06 19:22:40 +01:00
Gilles Peskine
3175fc3be2 Fix end check before memmove
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-03-06 19:10:41 +01:00
Gilles Peskine
58c3301f65 Make conversion explicit to silence MSVC warning
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-03-05 17:03:20 +01:00
Gilles Peskine
302f37b05d Fix dodgy printf calls
Pacify `clang -Wformat-pedantic`.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-03-05 17:03:20 +01:00
Gilles Peskine
cc856a2c0e Handshake defragmentation: reassemble incrementally
Reassemble handshake fragments incrementally instead of all at the end. That
is, every time we receive a non-initial handshake fragment, append it to the
initial fragment. Since we only have to deal with at most two handshake
fragments at the same time, this simplifies the code (no re-parsing of a
record) and is a little more memory-efficient (no need to store one record
header per record).

This commit also fixes a bug. The previous code did not calculate offsets
correctly when records use an explicit IV, which is the case in TLS 1.2 with
CBC (encrypt-then-MAC or not), GCM and CCM encryption (i.e. all but null and
ChachaPoly). This led to the wrong data when an encrypted handshake message
was fragmented (Finished or renegotiation). The new code handles this
correctly.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-03-05 17:03:20 +01:00
Gilles Peskine
22c51b9a0b mbedtls_ssl_prepare_handshake_record(): log offsets after decryption
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-03-05 17:03:20 +01:00
Gilles Peskine
af0c461f39 mbedtls_ssl_prepare_handshake_record(): refactor first fragment prep
Minor refactoring of the initial checks and preparation when receiving the
first fragment. Use `ssl->in_hsfraglen` to determine whether there is a
pending handshake fragment, for consistency, and possibly for more
robustness in case handshake fragments are mixed with non-handshake
records (although this is not currently supported anyway).

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-03-05 17:03:20 +01:00
Gilles Peskine
1e81d349b8 Tweak handshake fragment log message
In preparation for reworking mbedtls_ssl_prepare_handshake_record(),
tweak the "handshake fragment:" log message.

This changes what information is displayed when a record contains data
beyond the expected end of the handshake message. This case is currently
untested and its handling will change in a subsequent commit.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-03-05 17:03:20 +01:00
Gilles Peskine
3d490a91ad Tweak "waiting for more handshake fragments" log message
In preparation for reworking mbedtls_ssl_prepare_handshake_record(), tweak
the "waiting for more handshake fragments" log message in
ssl_consume_current_message(), and add a similar one in
mbedtls_ssl_prepare_handshake_record(). Assert both.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-03-05 17:03:20 +01:00
Gilles Peskine
b710599e4a Merge in_hsfraglen with badmac_seen_or_in_hsfraglen
In the `mbedtls_ssl_context` structure, merge the field `in_hsfraglen` into
`badmac_seen_or_in_hsfraglen`. This restores the ABI of `libmbedtls` as it
was in Mbed TLS 3.6.0 through 3.6.2.

The field `badmac_seen_or_in_hsfraglen` (formerly `badmac_seen`) was only
used for DTLS (despite being present in non-DTLS builds), and the field
`in_hsfraglen` was only used in non-DTLS TLS. Therefore the two values can
be stored in the same field.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-02-17 16:28:51 +01:00
Gilles Peskine
ebdd405f68 Change the type of in_hsfraglen to unsigned
In the `mbedtls_ssl_context` structure, change the type of `in_hsfraglen`
from `size_t` to `unsigned`. This is in preparation for merging
`in_hsfraglen` into `badmac_seen_or_in_hsfraglen`, which has the type
`unsigned` and cannot change since we do not want to change the ABI.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-02-17 16:26:27 +01:00
Gilles Peskine
f6a676d93f Rename badmac_seen to badmac_seen_or_in_hsfraglen
Prepare to unify two fields of the `mbedtls_ssl_context` structure:
`badmac_seen` (always present but only used in DTLS) and
`in_hsfraglen` (always present but only used in non-DTLS TLS).

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-02-17 16:10:14 +01:00
Gilles Peskine
69f8f45e6f Minor readability improvement
No behavior change.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-02-17 16:08:59 +01:00
Deomid rojer Ryabkov
bbe8745d19 Remove in_hshdr
The first fragment of a fragmented handshake message always starts at the beginning of the buffer so there's no need to store it.

Signed-off-by: Deomid rojer Ryabkov <rojer@rojer.me>
2025-02-17 15:59:55 +01:00
Deomid rojer Ryabkov
85ec2b3632 Add a safety check for in_hsfraglen
Signed-off-by: Deomid rojer Ryabkov <rojer@rojer.me>
2025-02-17 15:59:04 +01:00
Deomid rojer Ryabkov
5c853ea2c5 Allow fragments less HS msg header size (4 bytes)
Except the first

Signed-off-by: Deomid rojer Ryabkov <rojer@rojer.me>
2025-02-17 15:59:04 +01:00
Deomid rojer Ryabkov
1f4088ceda Review comments
Signed-off-by: Deomid rojer Ryabkov <rojer@rojer.me>
2025-02-17 15:59:04 +01:00
Deomid rojer Ryabkov
3fc5a4dc86 Defragment incoming TLS handshake messages
Signed-off-by: Deomid rojer Ryabkov <rojer@rojer.me>
2025-02-17 15:59:04 +01:00
Gilles Peskine
5a668dd5af Reduce level of non-error debug message
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-09-20 07:44:36 +02:00
Gilles Peskine
015d222008 Remove transitional always-on internal option
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-09-20 07:44:36 +02:00
Gilles Peskine
78df03aaa5 Separate accepting TLS 1.3 middlebox compatibility from sending it
The compile-time option MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE gates both
support for interoperability with a peer that uses middlebox compatibility
mode, and support for activating that mode ourselves. Change code that is
only needed for interoperability to be guarded by
MBEDTLS_SSL_TLS1_3_ACCEPT_COMPATIBILITY_MODE.

As of this commit, MBEDTLS_SSL_TLS1_3_ACCEPT_COMPATIBILITY_MODE is always
enabled: there is no way to disable it, and there are no tests with it
disabled.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-09-20 07:40:02 +02:00
Ronald Cron
9f44c883f4 Rename some "new_session_tickets" symbols
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2024-08-28 17:47:46 +02:00
Ronald Cron
97dc5832c5 Improve debug logs
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2024-08-28 10:42:01 +02:00
Ronald Cron
d67f801c63 Do not add a new field in the SSL config
We cannot add a new field in SSL config in
an LTS. Use `session_tickets` field instead.

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2024-08-28 10:41:54 +02:00
Ronald Cron
b675b2ba5d TLS 1.3: Ignore tickets if disabled at runtime
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2024-08-27 15:41:24 +02:00
Ronald Cron
698c8e902e ssl_msg.c: Rename _check_new_session_ticket to _is_new_session_ticket
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2024-04-05 14:16:32 +02:00
Ronald Cron
6071f611f6 tls13: cli: Ignore tickets if not supported
If a TLS 1.3 client receives a ticket and
the feature is not enabled, ignore it.

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2024-04-05 14:16:32 +02:00
Ronald Cron
3641df2980 tls13: cli: Rename STATE_SENT to STATE_IND_SENT
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2024-03-12 17:48:18 +01:00
Ronald Cron
05d7cfbd9c tls13: cli: Rename STATE_UNKNOWN to STATE_IDLE
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2024-03-12 17:48:18 +01:00
Ronald Cron
d2884662c1 tls13: cli: Split early data user status and internal state
Do not use the return values of
mbedtls_ssl_get_early_data_status()
(MBEDTLS_SSL_EARLY_DATA_STATUS_ macros)
for the state of the negotiation and
transfer of early data during the
handshake.

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2024-03-12 17:48:15 +01:00
Ronald Cron
61fd13c6a5 Merge remote-tracking branch 'mbedtls/development' into tls13-cli-max-early-data-size 2024-03-10 18:09:47 +01:00
Ronald Cron
db944a7863 ssl_msg.c: Fix log position
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2024-03-08 14:50:58 +01:00
Ronald Cron
5dbfcceb81 tls13: cli: Fix error code not checked
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2024-03-01 15:15:30 +01:00
Ronald Cron
de9b03dcba tls13: Rename early_data_count to total_early_data_size
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2024-03-01 15:14:17 +01:00
Ronald Cron
62f971aa60 tls13: cli: Enforce maximum size of early data
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2024-03-01 15:10:22 +01:00
Ronald Cron
01d273d31f Enforce maximum size of early data in case of HRR
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2024-03-01 09:29:16 +01:00
Ronald Cron
919e596c05 Enforce maximum size of early data when rejected
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2024-03-01 09:29:16 +01:00
Ronald Cron
d4069247b8 Improve comments/documentation
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2024-02-21 17:37:26 +01:00
Ronald Cron
49221900b0 tls13: write_early_data: Add endpoint check
Return in error of the API is not called
from a client endpoint.

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2024-02-21 14:37:52 +01:00
Xiaokang Qian
b62732e1d6 tls13: cli: Add mbedtls_ssl_write_early_data() API
Signed-off-by: Xiaokang Qian <xiaokang.qian@arm.com>
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2024-02-07 08:06:46 +01:00
Manuel Pégourié-Gonnard
5c9cc0b30f
Merge pull request #8727 from ronald-cron-arm/tls13-ignore-early-data-when-rejected
TLS 1.3: SRV: Ignore early data when rejected
2024-02-06 13:16:03 +00:00
Ronald Cron
71c6e65d83 tls13: ssl_msg.c: Improve/add comments
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2024-02-05 16:54:37 +01:00
Manuel Pégourié-Gonnard
32c28cebb4
Merge pull request #8715 from valeriosetti/issue7964
Remove all internal functions from public headers
2024-02-05 15:09:15 +00:00