-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Introduce SSL getter API for handshake state #4383
Comments
Note: this is a follow-up to #4371 and #4373. If we execute #4371 without this follow-up it would make some people's working code "non-compliant" with no transition path. (In addition to the recent posting on the list, I've seen at least twice in the past code that accessed So while in principle it's something we could do any time in 3.x (add a getter function), in practice I think this is a necessary follow-up to #4373. |
As I previously wrote elsewhere:
I'm |
ITYM “I'm now thinking”? I think that 3.0 or at least 3.1 should have getters for things we know people need. Sample programs would give us a clue. I'm not sure if the handshake state is one of those though. |
One data point for server-side use of mbedTLS is lighttpd. I am a lighttpd developer and author of lighttpd mod_mbedtls TLS module and I posted more detail in #5331, but wanted to mention here that lighttpd mod_mbedtls needs more than "is the handshake over yet?". lighttpd currently steps the handshake for a) ALPN to be able to handle server certificate selection and support RFC8737 Automated Certificate Management Environment (ACME) TLS Application-Layer Protocol Negotiation (ALPN) Challenge Extension, and for b) client certificate validation. |
@ronald-cron-arm I think at this point you're the most familiar with the TLS 1.3 handshake states, could you have a look and comment? I'm a bit providing a simple The alternative would be to add a series of functions like |
@mpg ok I will have a look. |
Another item which could use improvement in stepping handshake and which is very visible on server-side use of mbedTLS: some callbacks are only for |
I'm rather in favor of adding new functions with specific goals. The state is an internal detail and not every condition can be observed solely from the state field. For example, as we're seeing now, a new version of the protocol can introduce new states. Another example is a potential |
(Note: also requested by two people in #5184, correctly pointing out that currently there's no way to use |
Another request for state, for handshake reasons. |
@mpg I have not traced through the code to understand the DTLS flows, so this is a question: Possible overload suggestion: Now that there is |
Musing: Were there to be a new accessor available to check the cookie status, then the new accessor could be called from f_cert_cb before |
Didn't know it's forbidden here to repeat what has been already said... As for me having not read the previous conversation, while I respect your opinion, brother, may I kindly ask you to refrain from far-fetched assumptions and "policing"? Thank you! |
Fair enough. The path MbedTLS is taking is now clear. Unfortunately, it looks like the problem with a session-based DTLS server that I tried to shed some light upon above will become buried even deeper with callbacks. Moreover, since there is no easy transition path between |
I think that's correct, but I was thinking of a smaller change, like: diff --git a/library/ssl_srv.c b/library/ssl_srv.c
index 094fca8932d7..7379b6df18ca 100644
--- a/library/ssl_srv.c
+++ b/library/ssl_srv.c
@@ -1875,7 +1875,10 @@ read_record_header:
/*
* Server certification selection (after processing TLS extensions)
*/
- if( ssl->conf->f_cert_cb && ( ret = ssl->conf->f_cert_cb( ssl ) ) != 0 )
+ if( ssl->conf->f_cert_cb &&
+ !( ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM &&
+ ssl->handshake->verify_cookie_len != 0 ) &&
+ ( ret = ssl->conf->f_cert_cb( ssl ) ) != 0 )
{
MBEDTLS_SSL_DEBUG_RET( 1, "f_cert_cb", ret );
return( ret ); (or something equivalent with better formatting and a comment).
I agree, I think that was (2) in the first paragraph of this comment. I think both ways would work, though right now I have a slight preference for (1) because I think it's just simpler. |
I agree that's not ideal. OTOH, like someone said over in the OpenSSL discussion, I think the "right" way to solve the underlying issue is neither callbacks nor stepping the handshake, but a dedicated BIO implementation that would probably use a single unconnected socket and handle the dispatch. There's a mismatch between what the DTLS layer expects and what the sockets API provides, and bridging that gap should be the BIO callback's job. And ideally it should be provided by the DTLS library (or at least a working example of how to go about it), rather that written over and over again by each application developer. Unfortunately, considering all the other things on our plate, that's unlikely to happen soon. If you ever have the right combination of time and motivation and feel like submitting a PR for this, please get in touch on the mailing list first to discuss the general design and the planning (our review bandwidth tends to be a bottleneck, so for large/complex contributions it's better if the review effort is budgeted in advance). |
As a matter of principle, I think we could consider back-porting selected features in order to make supporting both 2.x and 3.x easier, but unfortunately in this case the changes affect the ABI, which we "try very hard" not to break in LTS branches - meaning we'd only break the ABI in an LTS if that was the only way we found to fix a security vulnerability. Sorry about that, I hear your pain, but I don't think we can do anything to relieve it now. (Perhaps in the future we release 4.0 we can wait a bit before turning the latest 3.x to LTS status, to leave time for similar issues to surface and find solutions that make it less of a pain to support both 3.x and 4.x.) |
Personally, I think complicating the implementation of BIO is a dead-end approach. And the exact reason I abandoned my attempts to incorporate OpenSSL in favour of MbedTLS was that:
Yes, that was on my TODO list. In particular, I planned to develop and donate a correctly working example as part of the MbedTLS example suite. But... Since we hit a major snag with MbedTLS 3.0 in regards to EDIT:
Indeed, there is much more sense in what you are saying than modifying a totally unrelated server certificate selection callback. Since there are already things like typedef int mbedtls_ssl_greeter_t(void *ctx);
void mbedtls_ssl_set_greeter(mbedtls_ssl_context *ssl, void *ctx, mbedtls_ssl_greeter_t *func); ... which again makes sense only for DTLS servers and triggers |
f_cert_cb is intended to be called unconditionally, unless there is a fatal error in processing the client hello before that point. Your simple patch would add an exception, which I do not think is the best design choice here. If the handshake proceeds (it does), then f_cert_cb should be called to be able to perform certificate selection and any other application-level policy that should occur after the ClientHello has been processed. @mpg, I think your suggestion ((2) in the first paragraph of this comment) is a better solution, though other alternatives might also be proposed by those who know DTLS better than I. A place for DTLS |
Added #5653 to implement mbedtls_ssl_is_handshake_over(), as discussed above. Not setting it to close this issue, as there is still conversation going on here about other problems aroundt this area. |
As discussed in issue and subsequent design review issue #8529, the handshake and handshake state should not be directly exposed. As mentioned above exposing the internal state does not guarantee consistent behaviour across different versions. We have added callbacks at #5454 and #8456 and stepping the handshake is possbile. We are not considering adding a dedicated BIO implementation at this stage. I will be closing this issue, but please feel free to re-open or write a new-one if there is still a gap that we need to consider moving forward. |
Context: This was raised by Jeremy Audiger on the Mbed TLS mailing list.
Issue: When we make
mbedtls_ssl_context
internal, there is no supported way of extracting the handshake state. Given that we do expose the fact that the handshake happens in steps viambedtls_ssl_handshake_step()
, there should arguably be a public getter function that allows to retrieve the handshake state.The text was updated successfully, but these errors were encountered: