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

ktls: config socket ULP #4066

Merged
merged 6 commits into from
Jul 12, 2023
Merged

ktls: config socket ULP #4066

merged 6 commits into from
Jul 12, 2023

Conversation

toidiu
Copy link
Contributor

@toidiu toidiu commented Jun 20, 2023

Description of changes:

This PR adds entry points for enabling kTLS for a connection. enable_send/recv currently only attempt to enable the "tls" ULP on the socket. If this operation succeeds, its possible to enable kTLS by setting keys on the socket (following PR).

The most interesting part of this PR is the validation that needs to occur before we can enable kTLS. This is done before most kTLS operations; and I also added tests to make sure it behaves as expected.

Call-outs:

The following two functions will eventually be part of the public API:

  • int s2n_connection_ktls_enable_send(struct s2n_connection *conn);
  • int s2n_connection_ktls_enable_recv(struct s2n_connection *conn);

Testing:

Unit tests.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@github-actions github-actions bot added the s2n-core team label Jun 20, 2023
@toidiu toidiu mentioned this pull request Jun 20, 2023
32 tasks
@toidiu toidiu force-pushed the ak-ktls0_config_socket branch 5 times, most recently from ab5903e to 607a74b Compare June 22, 2023 18:25
@toidiu toidiu force-pushed the ak-ktls0_config_socket branch 3 times, most recently from 9de2265 to 588e394 Compare July 4, 2023 05:40
@toidiu toidiu changed the title Ak ktls0 config socket ktls: config socket ULP Jul 4, 2023
@toidiu toidiu force-pushed the ak-ktls0_config_socket branch from 588e394 to dbdc819 Compare July 4, 2023 06:15
@toidiu toidiu marked this pull request as ready for review July 5, 2023 17:59
@toidiu toidiu requested review from lrstewart and maddeleine July 5, 2023 18:00
tls/s2n_ktls.h Outdated Show resolved Hide resolved
tls/s2n_ktls.c Show resolved Hide resolved
tls/s2n_ktls.c Show resolved Hide resolved
tls/s2n_ktls.c Show resolved Hide resolved
tls/s2n_ktls.c Outdated Show resolved Hide resolved
tls/s2n_ktls.c Outdated Show resolved Hide resolved
tls/s2n_ktls.c Outdated Show resolved Hide resolved
tls/s2n_ktls.c Outdated Show resolved Hide resolved
error/s2n_errno.c Show resolved Hide resolved
error/s2n_errno.c Outdated Show resolved Hide resolved
@toidiu toidiu requested a review from maddeleine July 7, 2023 22:02
@toidiu toidiu force-pushed the ak-ktls0_config_socket branch from c21995a to c235257 Compare July 8, 2023 00:25
tls/s2n_ktls.h Show resolved Hide resolved
tls/s2n_ktls.c Outdated Show resolved Hide resolved
tls/s2n_ktls.c Outdated Show resolved Hide resolved
tls/s2n_ktls.c Outdated Show resolved Hide resolved
tls/s2n_ktls.c Outdated Show resolved Hide resolved
tls/s2n_ktls.c Outdated Show resolved Hide resolved
tests/unit/s2n_ktls_test.c Outdated Show resolved Hide resolved
@toidiu toidiu force-pushed the ak-ktls0_config_socket branch from c235257 to 5e80fd0 Compare July 11, 2023 06:56
@toidiu toidiu requested a review from maddeleine July 11, 2023 18:34
Comment on lines +335 to +336

S2N_RESULT s2n_skip_handshake(struct s2n_connection *conn)
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this is no longer a static test method, I'd probably change the name to s2n_connection_skip_handshake. Or maybe s2n_connection_set_complete? I definitely think the name could use a revisit ;)

tls/s2n_ktls.h Outdated Show resolved Hide resolved
tls/s2n_ktls.c Outdated Show resolved Hide resolved
tls/s2n_ktls.c Outdated Show resolved Hide resolved
tls/s2n_ktls.c Show resolved Hide resolved
tls/s2n_ktls.h Outdated Show resolved Hide resolved
tls/s2n_ktls.c Outdated Show resolved Hide resolved
tls/s2n_ktls.c Outdated Show resolved Hide resolved
tls/s2n_ktls.c Outdated Show resolved Hide resolved
tls/s2n_ktls.c Outdated
Comment on lines 98 to 94
if (ktls_mode == S2N_KTLS_MODE_SEND && conn->ktls_send_enabled) {
RESULT_BAIL(S2N_ERR_KTLS_ALREADY_ENABLED);
}
if (ktls_mode == S2N_KTLS_MODE_RECV && conn->ktls_recv_enabled) {
RESULT_BAIL(S2N_ERR_KTLS_ALREADY_ENABLED);
}

int fd = 0;
RESULT_GUARD(s2n_ktls_retrieve_file_descriptor(conn, ktls_mode, &fd));
Copy link
Contributor

Choose a reason for hiding this comment

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

Since all this logic differs for send vs recv, why not keep it in s2n_connection_ktls_enable_send / s2n_connection_ktls_enable_recv rather than in the common method they both call?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

tls/s2n_ktls.c Outdated Show resolved Hide resolved
tls/s2n_ktls.c Outdated Show resolved Hide resolved
tests/unit/s2n_ktls_test.c Outdated Show resolved Hide resolved
Comment on lines 33 to 34

S2N_RESULT s2n_test_configure_mock_ktls_connection(struct s2n_connection *conn, int fd, bool complete_handshake)
Copy link
Contributor

@lrstewart lrstewart Jul 11, 2023

Choose a reason for hiding this comment

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

This threw me a bit: If you're trying to test configuring a connection for ktls, why are you mocking the configuration? A better name might be "s2n_setup_valid_connection_for_ktls". I would also suggest removing the "fd" and "complete_handshake" args-- you never actually use "fd" for anything, and "complete_handshake" is the only option to produce a connection that's not valid for ktls. Instead, you can just set conn->handshake.message_number = 0 to reset the handshake.

tests/unit/s2n_ktls_test.c Outdated Show resolved Hide resolved
tests/unit/s2n_ktls_test.c Outdated Show resolved Hide resolved
tests/unit/s2n_ktls_test.c Outdated Show resolved Hide resolved
@toidiu toidiu requested a review from lrstewart July 11, 2023 23:07
Comment on lines 33 to 34

S2N_RESULT s2n_test_configure_valid_ktls_connection(struct s2n_connection *conn)
Copy link
Contributor

Choose a reason for hiding this comment

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

#4066 (comment) I really think this shouldn't be "configure ktls connection". You're not actually configuring ktls. You're configuring a basic tls connection so that ktls can later be enabled.

Comment on lines 183 to 184
/* write to conn->out buffer and assert error */
EXPECT_SUCCESS(s2n_stuffer_write_bytes(&server_conn->out, &write_byte, 1));
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: you can avoid write_byte if you just do

Suggested change
/* write to conn->out buffer and assert error */
EXPECT_SUCCESS(s2n_stuffer_write_bytes(&server_conn->out, &write_byte, 1));
/* write to conn->out buffer and assert error */
EXPECT_SUCCESS(s2n_stuffer_write_uint8(&server_conn->out, 0));

Conversely if you want to only read one byte, s2n_stuffer_read_uint8 is the better choice. If you just want to clear it though, you just need to do s2n_stuffer_wipe().

@toidiu toidiu force-pushed the ak-ktls0_config_socket branch from ef34e0f to 31b30fa Compare July 12, 2023 04:45
@toidiu toidiu force-pushed the ak-ktls0_config_socket branch from 31b30fa to fe8dea1 Compare July 12, 2023 19:39
@toidiu toidiu enabled auto-merge (squash) July 12, 2023 19:40
@toidiu toidiu merged commit d3822c1 into aws:main Jul 12, 2023
@toidiu toidiu deleted the ak-ktls0_config_socket branch July 12, 2023 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants