Skip to content

net: sockets: tls: Add new options for certificate verification #90068

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

rlubos
Copy link
Collaborator

@rlubos rlubos commented May 16, 2025

Add new TLS socket options:

  • TLS_CERT_VERIFY_RESULT to retrieve certificate verification result,
  • TLS_CERT_VERIFY_CALLBACK to regsiter ceritificate verification callback.

Plus associated tests.

Resolves #52541

rlubos added 3 commits May 16, 2025 14:42
Add new TLS socket option, TLS_CERT_VERIFY_RESULT, to obtain the
certificate verification result from the most recent handshake on the
socket. The option works if TLS_PEER_VERIFY_OPTIONAL was set on the
socket, in which case the handshake may succeed even if certificate
verification fails.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Extract server configuration, client configuration and test shutdown
into separate functions so that they're reusable in other tests.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Add test case to verify if TLS_CERT_VERIFY_RESULT socket option works as
expected.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
}

cert_verify = (struct tls_cert_verify_cb *)optval;
if (cert_verify->cb == NULL && cert_verify->ctx != NULL) {
Copy link
Member

Choose a reason for hiding this comment

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

Why do we care what the ctx is here, or was the idea that user can unset the callback by setting both values null (this is not documented if that is the idea)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I just thought that setting context w/o the callback does not make sense. Perhaps we should just forbid the NULL cb pointer?

Copy link
Member

Choose a reason for hiding this comment

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

Is user able to unregister the callback somehow, or does it make sense in the first place?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure actually if mbed TLS allows that, perhaps better to check for NULL pointer after all. I'll send a fix.

rlubos added 2 commits May 19, 2025 10:07
Add new TLS socket option, TLS_CERT_VERIFY_CALLBACK, which allows to
register an application callback to verify certificates obtained during
the TLS handshake.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
Add test case to verify if TLS_CERT_VERIFY_CALLBACK socket option works
as expected.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
@rlubos rlubos force-pushed the net/tls-cert-verify-opts branch from fc6641d to 8b7775c Compare May 19, 2025 08:07
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

net: sockets: tls: Check whether peer was verified after handshake (with TLS_PEER_VERIFY_OPTIONAL)
3 participants