-
Notifications
You must be signed in to change notification settings - Fork 149
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
Runtime check for EC keys in Secure Session #693
Runtime check for EC keys in Secure Session #693
Conversation
* Deny non-EC keys when creating/negotiating Secure Session. It was possible to create Secure Session by passing private RSA key to `secure_session_create`. But then it would fail while negotiating connection with another peer since Secure Session doesn't actually support RSA keys. This commit make it fail a little bit earlier. * Add test to make sure `secure_session_create` fail with RSA key. * Add test to make sure `secure_session_create` fail with empty peer ID (peer_id_len == 0).
* Move test keys to different file, make `clang-tidy` satisfied * Rewrite messages in test functions
0x1f, 0xe9, 0xea, 0x48, 0x11, 0xe1, 0xf9, 0x71, 0x8e, 0x24, 0x11, 0xcb, 0xfd, 0xc0, 0xa3, | ||
0x6e, 0xd6, 0xac, 0x88, 0xb6, 0x44, 0xc2, 0x9a, 0x24, 0x84, 0xee, 0x50, 0x4c, 0x3e, 0xa0, | ||
}; | ||
/* Test keys can be found in themis_secure_session_test_keys.h */ |
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.
👍
@@ -668,11 +666,40 @@ static void test_basic_flow_no_transport(void) | |||
} | |||
} | |||
|
|||
static void test_empty_peer_id(void) | |||
{ | |||
memcpy(&(client.transport), &transport, sizeof(secure_session_user_callbacks_t)); |
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.
remember: using memcpy
is ok only for tests / non-sensitive data
tests/themis/themis_secure_session.c
Outdated
testsuite_fail_if(client.session != NULL, "secure_session_create must fail with empty Peer ID"); | ||
} | ||
|
||
static void test_invalid_private_key_type(void) |
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.
Let's test public key and make sure that tests are passing and write comment why is that.
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.
IMO, it's would be better to split this into separate tests: RSA private keys, RSA public keys, EC public keys.
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.
agree
* Mention GitHub issue # in changelog. * Add one more check to `secure_session.c` to only allow EC private keys in `secure_session_create()`. * Add more tests to make sure the session cannot be created with public EC and public RSA keys.
memcpy(&(client_rsa.transport), &transport, sizeof(secure_session_user_callbacks_t)); | ||
client_rsa.transport.user_data = &client_rsa; |
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.
Well, this a weird way to setup a Secure Session – with global variables and memcpy() – but I'll let it pass given that all tests here are like that. It's not nice coding practice because it makes impossible to run the tests in parallel. However, refactoring this is a topic for another day.
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 guess the easiest way to refactor this is to mark those glogal vars as thread local and then create as many threads as we like, so they will run in parallel. Another question is whether the test framework is ready for such changes. And these tests are really fast, like almost instant, and the only computation-heavy check is soter rand: NIST STS
, which, btw, only uses one CPU core.
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.
You can also just create a new client context and callbacks for each test :) Which is arguably more readable and obvious than thread-local variables. It's more verbose, yeah, but dumb test code is better than smart one, IMO.
tests/themis/themis_secure_session.c
Outdated
testsuite_fail_if(client.session != NULL, "secure_session_create must fail with empty Peer ID"); | ||
} | ||
|
||
static void test_invalid_private_key_type(void) |
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.
IMO, it's would be better to split this into separate tests: RSA private keys, RSA public keys, EC public keys.
* Changed text in changelog * Removed unneeded checks: - `themis_get_asym_key_kind()` already checks pointer and length - non-EC keys won't reach `secure_session_peer_init()` so we actually don't need that check * Split tests into more funcs
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.
Nice work 👍
src/themis/secure_session_peer.c
Outdated
#include "soter/soter_wipe.h" | ||
#include "themis/secure_keygen.h" |
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 guess it's not necessary to include this any more.
Forgot to remove in prev commit
It was possible to create Secure Session by passing private RSA key to
secure_session_create()
. But then it would fail while negotiatingconnection with another peer since Secure Session doesn't actually
support RSA keys. This PR make it fail a little bit earlier.
secure_session_create
fails with EC pub key, RSA priv/pub keys.secure_session_create
fail with empty peer ID (id == NULL || id_len == 0).Checklist