From b90131dfe696b40b7cc0bc18cdfc307e6d14480a Mon Sep 17 00:00:00 2001 From: Jakub Jelen Date: Tue, 28 Apr 2020 13:09:54 +0200 Subject: tests: Verify functionality of none cipher and mac Signed-off-by: Jakub Jelen Reviewed-by: Andreas Schneider --- tests/unittests/torture_packet.c | 54 ++++++++++++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/unittests/torture_packet.c b/tests/unittests/torture_packet.c index 130ddad0..9f07f394 100644 --- a/tests/unittests/torture_packet.c +++ b/tests/unittests/torture_packet.c @@ -93,17 +93,21 @@ torture_packet(const char *cipher, const char *mac_type, crypto->decryptMAC = copy_data(mac, sizeof(mac)); in_cipher = session->current_crypto->in_cipher; - rc = in_cipher->set_decrypt_key(in_cipher, - session->current_crypto->decryptkey, - session->current_crypto->decryptIV); - assert_int_equal(rc, SSH_OK); + if (in_cipher->set_decrypt_key != NULL) { + rc = in_cipher->set_decrypt_key(in_cipher, + session->current_crypto->decryptkey, + session->current_crypto->decryptIV); + assert_int_equal(rc, SSH_OK); + } out_cipher = session->current_crypto->out_cipher; - rc = out_cipher->set_encrypt_key(out_cipher, - session->current_crypto->encryptkey, - session->current_crypto->encryptIV); + if (out_cipher->set_decrypt_key != NULL) { + rc = out_cipher->set_encrypt_key(out_cipher, + session->current_crypto->encryptkey, + session->current_crypto->encryptIV); + assert_int_equal(rc, SSH_OK); + } session->current_crypto->used = SSH_DIRECTION_BOTH; - assert_int_equal(rc, SSH_OK); assert_non_null(session->out_buffer); ssh_buffer_add_data(session->out_buffer, test_data, payload_len); @@ -161,6 +165,35 @@ static void torture_packet_aes256_ctr_etm(UNUSED_PARAM(void **state)) } } +#ifdef WITH_INSECURE_NONE +static void torture_packet_none_sha1(UNUSED_PARAM(void **state)) +{ + int i; + + for (i = 1; i < 256; ++i) { + torture_packet("none", "hmac-sha1", "none", i); + } +} + +static void torture_packet_aes128_ctr_none(UNUSED_PARAM(void **state)) +{ + int i; + + for (i = 1; i < 256; ++i) { + torture_packet("aes128-ctr", "none", "none", i); + } +} + +static void torture_packet_none_none(UNUSED_PARAM(void **state)) +{ + int i; + + for (i = 1; i < 256; ++i) { + torture_packet("none", "none", "none", i); + } +} +#endif /* WITH_INSECURE_NONE */ + static void torture_packet_aes128_ctr(void **state) { int i; @@ -329,6 +362,11 @@ int torture_run_tests(void) { cmocka_unit_test(torture_packet_aes256_gcm), cmocka_unit_test(torture_packet_compress_zlib), cmocka_unit_test(torture_packet_compress_zlib_openssh), +#ifdef WITH_INSECURE_NONE + cmocka_unit_test(torture_packet_none_sha1), + cmocka_unit_test(torture_packet_aes128_ctr_none), + cmocka_unit_test(torture_packet_none_none), +#endif }; ssh_init(); -- cgit v1.2.3