From 078af20e8b3bff93dd42972e4ef01702e7e1fe2b Mon Sep 17 00:00:00 2001 From: BakasuraRCE Date: Tue, 21 Jul 2020 19:16:50 -0500 Subject: fishlim: Implement correct handling of long and UTF-8 messages --- plugins/fishlim/tests/tests.c | 50 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'plugins/fishlim/tests') diff --git a/plugins/fishlim/tests/tests.c b/plugins/fishlim/tests/tests.c index 45dfd41c..bb841c5e 100644 --- a/plugins/fishlim/tests/tests.c +++ b/plugins/fishlim/tests/tests.c @@ -230,6 +230,54 @@ void __base64_cbc_len(void) { } } +/** + * Check the calculation of length limit for a plaintext in each encryption mode + */ +void __max_text_command_len(void) { + int max_encoded_len, plaintext_len; + enum fish_mode mode; + + for (max_encoded_len = 0; max_encoded_len < 10000; ++max_encoded_len) { + for (mode = FISH_ECB_MODE; mode <= FISH_CBC_MODE; ++mode) { + plaintext_len = max_text_command_len(max_encoded_len, mode); + g_assert_cmpuint(encoded_len(plaintext_len, mode), <= , max_encoded_len); + } + } +} + +/** + * Check the calculation of length limit for a plaintext in each encryption mode + */ +void __foreach_utf8_data_chunks(void) { + GRand *rand = NULL; + GString *chunks = NULL; + int tests, max_chunks_len, chunks_len; + char ascii_message[1001]; + char *data_chunk = NULL; + + rand = g_rand_new(); + + for (tests = 0; tests < 1000; ++tests) { + + max_chunks_len = g_rand_int_range(rand, 2, 301); + random_string(ascii_message, 1000); + + data_chunk = ascii_message; + + chunks = g_string_new(NULL); + + while (foreach_utf8_data_chunks(data_chunk, max_chunks_len, &chunks_len)) { + g_string_append(chunks, g_strndup(data_chunk, chunks_len)); + /* Next chunk */ + data_chunk += chunks_len; + } + /* Check data loss */ + g_assert_cmpstr(chunks->str, == , ascii_message); + g_string_free(chunks, TRUE); + } +} + + int main(int argc, char *argv[]) { g_test_init(&argc, &argv, NULL); @@ -240,6 +288,8 @@ int main(int argc, char *argv[]) { g_test_add_func("/fishlim/__base64_fish_len", __base64_fish_len); g_test_add_func("/fishlim/__base64_ecb_len", __base64_ecb_len); g_test_add_func("/fishlim/__base64_cbc_len", __base64_cbc_len); + g_test_add_func("/fishlim/__max_text_command_len", __max_text_command_len); + g_test_add_func("/fishlim/__foreach_utf8_data_chunks", __foreach_utf8_data_chunks); return g_test_run(); } -- cgit 1.4.1