-
Notifications
You must be signed in to change notification settings - Fork 717
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
test: add self talk test using AF_INET socket #3807
Conversation
49ccf81
to
c260588
Compare
1565f98
to
708a342
Compare
OpenBSD fails with. Thinking that this is because we run the test in a OpenBSD VM rather than an actual instance. Planning to ignore running the test on that platform to get around this.
|
fix applied in ffc9b52
OpenBSD was failing due the use of https://stackoverflow.com/a/34042435 describers the issue in MacOS. To get around this I am going to define the value myself. This is safe because the hex value
|
ffc9b52
to
ad22c2e
Compare
|
||
/* Setup config */ | ||
EXPECT_SUCCESS(s2n_connection_set_blinding(server_conn, S2N_SELF_SERVICE_BLINDING)); | ||
EXPECT_EQUAL(s2n_connection_get_delay(server_conn), 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this function only used to see if blinding was invoked? I'm not sure why you'd check it before actually attempting a connection.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it was a sanity check for myself when writing the test. The previous version with NON_BLOCKING sockets and sleeps required this. I can remove it.
EXPECT_EQUAL(server_conn->actual_protocol_version, S2N_TLS12); | ||
|
||
char sync = 0; | ||
char send_buffer[1] = { 0 }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
char send_buffer[1] = { 0 }; | |
char send_buffer[] = { 0 }; |
Nit: In C you don't need to specify how large the buffer is if you're initializing it with elements.
return S2N_RESULT_OK; | ||
} | ||
|
||
int main(int argc, char **argv) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not exactly sure what the point of this test is. You seem to be testing that you can negotiate and send/recv data on a special socket? But I'm not sure why that needs to be tested. Maybe you could add a comment explaining the purpose of this test, as it's not obvious to me.
Are we planning on adding more to this test in the future?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mention the reason for this in the PR description. I dont want to add that in the code because this test really has nothing to do with kTLS (it just established the base case).
Adding comments about kTLS is confusing because we could add tests similar to this that dont deal with kTLS. The only special thing about this test is that it uses a AF_INET
socket. Thats actually huge because thats what our customers use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the test has nothing to do with kTLS, then we should have a comment describing what it's testing without mentioning kTLS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, to me it doesn't really look like you're testing s2n here. It looks like you're testing the INET domain, which isn't really related to s2n. Is the point of this test to get a technique/method in place so that you can test KTLS in the future?
int sync_pipe[2] = { 0 }; | ||
EXPECT_SUCCESS(pipe(sync_pipe)); | ||
|
||
pid_t child = fork(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm uncertain, but I thought we moved away from using explicit forks in our tests. -- Although I'm not sure what they got replaced with.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They were replaced with s2n_negotiate_test_server_and_client + non-blocking io sockets or stuffers. You use forks if both sides need to be talking at the same time. If they're going to alternate talking, you don't need forks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Talked to Apoorv offline: he DOES need both sides talking at the same time for the socket listen/connect part. But I wonder if we can isolate just that part with threads or something so that we can otherwise keep everything in the same process?
|
||
RESULT_GUARD_POSIX(read(read_pipe, &sync, 1)); | ||
RESULT_GUARD_POSIX(s2n_recv(client_conn, recv_buffer, 1, &blocked)); | ||
RESULT_ENSURE_EQ(memcmp(&CHAR_B, &recv_buffer[0], 1), 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't these just use EXPECT_EQ? Why call memcmp
to compare a single byte?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this test isn't explicitly for ktls, I'm not sure I understand its purpose. If it is for ktls, then you're likely going to want multiple self-talk tests, and you're likely going to want non-blocking IO. This test won't work for either of those cases.
Maybe what you want is a version of s2n_test_io_pair that uses an AF_INET socket.
|
||
static S2N_RESULT start_client(int fd, int read_pipe) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This model is fine for a one-off test, but it makes writing self-talk tests extremely difficult. You've got a single self-talk test in this whole file :) I would strongly suggest looking into getting this working with s2n_negotiate_test_server_and_client.
s2n_blocked_status blocked = S2N_NOT_BLOCKED; | ||
RESULT_GUARD_POSIX(s2n_negotiate(client_conn, &blocked)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works because you're using blocking sockets. If you were using non-blocking sockets, it would be possible for s2n_negotiate to fail with S2N_ERR_IO_BLOCKING and you'd need to handle that.
spoke offline and while we will eventually want a INET enabled socket, we will only want it to test kTLS. So I am closing this PR until kTLS is complete and testable |
To keep the context and conclusion in one place: #3807 (comment)
The current testing strategy(fork) is too verbose and the reason why we moved away from it. Condensing the setup into a setup function and then only including the testing functionality in the test is what we want ideally. |
Continuing this in #4075 |
Description of changes:
socket man page: https://man7.org/linux/man-pages/man2/socket.2.html
Our self talk test use
AF_UNIX
, which is a local link. This PR adds a self_talk test which usesAF_INET
(ipv4 protocols). Using AF_INET is going to be necessary to test kTLS functionality since its not possible to enable kTLS for a AF_UNIX socket.Testing:
self talk test
Is this a refactor change? If so, how have you proved that the intended behavior hasn't changed?
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.