Skip to content

Conversation

rlubos
Copy link
Contributor

@rlubos rlubos commented Oct 15, 2025

So far the TLS/DTLS credentials would only be validated upon first use,
i. e. when TLS/DTLS handshake was initiated. This could lead to some
confusion, especially when trying to understand the reason of the
handshake failure, as it wasn't clear whether the handshake failed due
to peer sending bad certificate or due to local configuration issues.

This commit attempts to improve this, by pre-validating the credentials
as soon as they are configured on a socket with TLS_SEC_TAG_LIST socket
option. That way, in case bad credentials are configured on a socket, or
more commonly, mbed TLS is misconfigured to handle certain credential
type, it will be caught early during socket configuration, instead of
during the handshake.

Resolves #97541

@rlubos rlubos requested a review from nordicjm October 15, 2025 13:33
@zephyrbot zephyrbot added area: Tests Issues related to a particular existing or missing test area: Networking area: Sockets Networking sockets labels Oct 15, 2025
@rlubos rlubos force-pushed the net/prevalidate-tls-credentials-on-setsockopt branch from 7c61a20 to 9e90311 Compare October 15, 2025 14:12
tag_found = true;

switch (cred->type) {
case TLS_CREDENTIAL_CA_CERTIFICATE:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should add here __fallthrough;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be, fixed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__fallthrough is needed when cases have a body, for combined cases it's not needed.

Both cases are fine here:

switch (some_var) {
case 1:
	/* some logic */
	__fallthrough;
case 2:
	/* ... */
}

switch (some_var) {
case 1:
case 2:
	/* ... */
}

So far the TLS/DTLS credentials would only be validated upon first use,
i. e. when TLS/DTLS handshake was initiated. This could lead to some
confusion, especially when trying to understand the reason of the
handshake failure, as it wasn't clear whether the handshake failed due
to peer sending bad certificate or due to local configuration issues.

This commit attempts to improve this, by pre-validating the credentials
as soon as they are configured on a socket with TLS_SEC_TAG_LIST socket
option. That way, in case bad credentials are configured on a socket, or
more commonly, mbed TLS is misconfigured to handle certain credential
type, it will be caught early during socket configuration, instead of
during the handshake.

Signed-off-by: Robert Lubos <[email protected]>
Add test cases verifying that invalid credentials are rejected by the
socket when configured on TLS/DTLS socket with TLS_SEC_TAG_LIST socket
option.

Signed-off-by: Robert Lubos <[email protected]>
@rlubos rlubos force-pushed the net/prevalidate-tls-credentials-on-setsockopt branch from 9e90311 to 9fba17b Compare October 15, 2025 16:01
@sonarqubecloud
Copy link

@rlubos rlubos requested a review from jukkar October 20, 2025 07:48
@nashif nashif merged commit 2291893 into zephyrproject-rtos:main Oct 20, 2025
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Networking area: Sockets Networking sockets area: Tests Issues related to a particular existing or missing test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tls credentials: verification of certificate

5 participants