-
Notifications
You must be signed in to change notification settings - Fork 7.4k
net: sockets: tls: Check whether peer was verified after handshake (with TLS_PEER_VERIFY_OPTIONAL) #52541
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
Comments
Apart from that, I also thought of allowing the application to register a custom TLS verification function, as is done in OpenSSL with the This issue is quite different from my original post, but having more control over the TLS stack from the application could be a good thing, especially during the TLS handshake. I haven't given it much thought, but I'm opening up the discussion, as I'm very interested. |
I'm still not sure whether this feature deserves to be added to main tree. However just to share my work, I drafted something that fulfil my needs for now: lucasdietrich@273ff70 To make it simple I decided to directly register application callback using Callback is configured like this from the application: #include <zephyr/net/socket.h>
#include <zephyr/net/tls_verify_cb.h>
int configure_verify_cb(void)
{
struct tls_verify_cb verify_cb;
verify_cb.callback = tls_verify_callback;
verify_cb.user_data = NULL;
return zsock_setsockopt(
sock, SOL_TLS, TLS_PEER_VERIFY_CB, &verify_cb, sizeof(verify_cb));
} Application verify callback looks like this: #include <mbedtls/x509_crt.h>
#include <mbedtls/oid.h>
static int tls_verify_callback(void *user_data,
struct mbedtls_x509_crt *crt,
int depth,
uint32_t *flags)
{
if (depth != 0) return 0;
bool accept = false;
/* Filter connections by common name */
for (name = &crt->subject; name != NULL; name = name->next) {
if (MBEDTLS_OID_CMP(MBEDTLS_OID_AT_CN, &name->oid) == 0) {
accept = validate_common_name(name->val.p, name->val.len);
}
}
return accept ? 0 : -1; /* -1 error is forwarded to zsock_accept() */
} |
this callback is really necessary especially when we handle cert chain. |
I think we could add two new options, one to get the result of the last handshake on the socket, and second to install certificate verify callback:
However, as you say, exposing some mebd TLS details to the application in this case seems unavoidable to me, even for the first option, the verify results are so detailed, abstracting them seem impractical: Perhaps we could at least make the option format transparent (I. e. register |
I've opened the PR: #90068 |
For TLS connections, it would be interesting to know whether the peer was verified when the socket option TLS_PEER_VERIFY_OPTIONAL is enabled.
It seems to be quite feasible, getting the result of
mbedtls_ssl_get_verify_result(tls->ssl)
after handshake would do the trick. However I have no idea of an API to present this result to the application.Suggestions are welcome.
MbedTLS documentation:
https://github.com/Mbed-TLS/mbedtls/blob/4cf77e99ab43105b863061c85796b8dbffd93ab1/include/mbedtls/ssl.h#L1925-L1928
https://github.com/Mbed-TLS/mbedtls/blob/4cf77e99ab43105b863061c85796b8dbffd93ab1/include/mbedtls/ssl.h#L4399-L4411
The text was updated successfully, but these errors were encountered: