Skip to content
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

TLS 1.2 Refactoring #2808

Merged
merged 2 commits into from
Dec 8, 2021
Merged

TLS 1.2 Refactoring #2808

merged 2 commits into from
Dec 8, 2021

Conversation

hrantzsch
Copy link
Collaborator

@hrantzsch hrantzsch commented Oct 1, 2021

The refactoring of the TLS 1.2 code done by @pist-eb and his colleagues in #2806 only. This way we can review and merge into the TLS 1.3 dev branch independently of the added TLS 1.3 code.

src/lib/tls/tls_messages.h Outdated Show resolved Hide resolved
@reneme
Copy link
Collaborator

reneme commented Oct 11, 2021

In the upstream implementation, concrete implementations of Handshake_Message::serialize() were private. This refactoring exposes them as part of the public class interface. Leaving that here for later investigation.

Copy link
Collaborator

@reneme reneme left a comment

Choose a reason for hiding this comment

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

In a first pass over the changes I focussed on the refactoring of the TLS message implementations. Mainly sanity checking the PIMPL-scheme layout. Furthermore, I double-checked the upstream protocol implementation code and the associated relocated _impl_12 classes.

No real surprises, but I'd like to discuss whether we should revert the splitting of the Server_Hello parsing code into the abstract _Impl and concrete _Impl_12 classes. I feel it would be better to do those (logic altering) changes in the next step. That said: I didn't find obvious issues with the separation either. @pist-eb, what do you think?

Anyway! Great to see the protocol version abstraction falling into place. 👍

#include <botan/internal/tls_handshake_hash.h>
#include <botan/internal/msg_cert_req_impl.h>
#include <botan/der_enc.h>
#include <botan/ber_dec.h>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove superfluous includes

src/lib/tls/msg_cert_req_impl.cpp Outdated Show resolved Hide resolved
src/lib/tls/msg_cert_req_impl.h Outdated Show resolved Hide resolved
src/lib/tls/msg_cert_req.cpp Outdated Show resolved Hide resolved
src/lib/tls/msg_cert_verify_impl.h Outdated Show resolved Hide resolved
src/lib/tls/msg_server_hello_impl.cpp Show resolved Hide resolved
RandomNumberGenerator& rng,
const Client_Hello& client_hello,
const Server_Hello::Settings& server_settings,
const std::string next_protocol) :
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks different from the upstream Server_Hello constructor. Note to self: need to look deeper into it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess this prepares the Server_Hello_Impl base class for code sharing between 1.2 and 1.3. Frankly, I feel like we should refrain from doing this in this refactoring step and rather do those logic changes with the integration of 1.3.

Copy link

@pist-eb pist-eb Oct 12, 2021

Choose a reason for hiding this comment

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

Yes, indeed the _Impl base classes for messages were prepared to share the common logic of TLS 1.2 and TLS 1.3.

public:
explicit Client_Hello_Impl_13()
{
// TODO throw std::runtime_error("Implemenation for TLSv1.3 not ready yet. You are welcome to implement it.");
Copy link
Collaborator

Choose a reason for hiding this comment

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

why not actually throw?

Copy link

Choose a reason for hiding this comment

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

I cannot recall now, but either BoGo_shim was failing with that throw, or one of our custom test scenarios.

src/lib/tls/tls_message_factory.h Outdated Show resolved Hide resolved
src/lib/tls/tls_messages.h Outdated Show resolved Hide resolved
@pist-eb
Copy link

pist-eb commented Oct 12, 2021

In a first pass over the changes I focussed on the refactoring of the TLS message implementations. Mainly sanity checking the PIMPL-scheme layout. Furthermore, I double-checked the upstream protocol implementation code and the associated relocated _impl_12 classes.

No real surprises, but I'd like to discuss whether we should revert the splitting of the Server_Hello parsing code into the abstract _Impl and concrete _Impl_12 classes. I feel it would be better to do those (logic altering) changes in the next step. That said: I didn't find obvious issues with the separation either. @pist-eb, what do you think?

Anyway! Great to see the protocol version abstraction falling into place. 👍

Honestly, the border between the 'refactoring of TLS 1.2' and 'implementation of TLS 1.3' was quite thin and maybe we partially started some TLS 1.3 logic changes already during refactoring. Please, feel free to adapt refactored code to your needs and ideas :)

Copy link
Collaborator

@reneme reneme left a comment

Choose a reason for hiding this comment

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

Things look good so far. Still missing tls_channel_impl_12 and tls_client_impl_12.

src/lib/tls/tls_client.cpp Outdated Show resolved Hide resolved
src/lib/tls/tls_client.cpp Outdated Show resolved Hide resolved
src/lib/tls/tls_channel_impl.h Outdated Show resolved Hide resolved
src/lib/tls/tls12/tls_server_impl_12.cpp Show resolved Hide resolved
src/lib/tls/tls12/tls_server_impl_12.cpp Show resolved Hide resolved
Copy link
Collaborator

@reneme reneme left a comment

Choose a reason for hiding this comment

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

This was the final review pass going through the remaining implementation files (mainly channel_impl_12 and client_impl_12. Unsurprisingly, 99% of these files are just copy & pasted code from the previous (non-pimpl-ed) locations.

This concludes comparing the implementations side-by-side with the respective implementation on the current master. Cumbersome work, but that also gave me a good overview of the TLS 1.2 implementation code base and the newly added layer of abstraction.

src/lib/tls/tls12/tls_channel_impl_12.cpp Outdated Show resolved Hide resolved
src/lib/tls/tls12/tls_channel_impl_12.cpp Outdated Show resolved Hide resolved
@reneme
Copy link
Collaborator

reneme commented Oct 22, 2021

So I went through the refactoring code and compared it to the respective implementations in latest master. Looks good to me. No real surprises, just lot's of code moving around.

@pist-eb We don't expect you to tackle the nitpicks and comments I attached in the last two weeks. @hrantzsch and I are going to resolve those next week.

After that, from our perspective it should be fine to merge this to dev/tls-13. We'll continue as described in GH #2714, except you have any objections to this plan, @randombit?

In any case, dev/tls-13 will need a rebase soon, to bring in the recent CI fixes and make sure everything is green. We'll do that after we tackled the nitpicks.

@pist-eb
Copy link

pist-eb commented Oct 22, 2021

Please note, that in our refactoring we still had some doubts, whether there are more classes that could be 'protocol version specific' in the end. Unfortunately, we couldn't determine all of them at refactoring phase, probably everything will become clear when implementing TLS 1.3 :)

Co-authored-by: Marek Kocik <extern.Marek.Kocik@elektrobit.com>
Co-authored-by: Grzegorz Dulewicz <extern.Grzegorz.Dulewicz@elektrobit.com>
Co-authored-by: Pawel Bazelewski <extern.pawel.bazelewski@elektrobit.com>
Co-authored-by: Pawel Jarosz <extern.pawel.jarosz@elektrobit.com>
@reneme
Copy link
Collaborator

reneme commented Oct 25, 2021

Rebased to latest master (to pick up recent CI fixes)

Co-authored-by: René Meusel <rene.meusel@nexenio.com>
Copy link
Collaborator

@reneme reneme left a comment

Choose a reason for hiding this comment

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

Good for now. I'm sure we'll find many more things while getting our feet wet when implementing TLS 1.3.

@hrantzsch hrantzsch merged commit 08140e7 into dev/tls-13 Dec 8, 2021
@randombit randombit deleted the dev/tls-13-refactoring branch December 1, 2022 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants