aboutsummaryrefslogtreecommitdiff
path: root/tests/client/torture_algorithms.c
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2015-09-10 14:46:43 +0200
committerAndreas Schneider <asn@cryptomilk.org>2016-01-14 08:04:49 +0100
commit3014e3c458dee09ebf1deae560c354eb1ecdd703 (patch)
tree8851529ad391e65195bcefc8e5a709d38932951c /tests/client/torture_algorithms.c
parentdd0d04ae8d064c69f6bd7b5af107f8cf85f9eccf (diff)
downloadlibssh-3014e3c458dee09ebf1deae560c354eb1ecdd703.tar.gz
libssh-3014e3c458dee09ebf1deae560c354eb1ecdd703.tar.xz
libssh-3014e3c458dee09ebf1deae560c354eb1ecdd703.zip
tests: Migrate torture_algorithms to a cwrap test
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Diffstat (limited to 'tests/client/torture_algorithms.c')
-rw-r--r--tests/client/torture_algorithms.c325
1 files changed, 220 insertions, 105 deletions
diff --git a/tests/client/torture_algorithms.c b/tests/client/torture_algorithms.c
index 8dc76c85..0d50a621 100644
--- a/tests/client/torture_algorithms.c
+++ b/tests/client/torture_algorithms.c
@@ -25,18 +25,42 @@
#include "libssh/libssh.h"
#include "libssh/priv.h"
+static int sshd_setup(void **state)
+{
+ torture_setup_sshd_server(state);
-static int setup(void **state) {
- int verbosity=torture_libssh_verbosity();
- ssh_session session = ssh_new();
- ssh_options_set(session, SSH_OPTIONS_LOG_VERBOSITY, &verbosity);
- *state = session;
+ return 0;
+}
+
+static int sshd_teardown(void **state) {
+ torture_teardown_sshd_server(state);
return 0;
}
-static int teardown(void **state) {
- ssh_free(*state);
+static int session_setup(void **state) {
+ struct torture_state *s = *state;
+ int verbosity = torture_libssh_verbosity();
+
+ ssh_init();
+
+ s->ssh.session = ssh_new();
+ assert_non_null(s->ssh.session);
+
+ ssh_options_set(s->ssh.session, SSH_OPTIONS_LOG_VERBOSITY, &verbosity);
+ ssh_options_set(s->ssh.session, SSH_OPTIONS_HOST, TORTURE_SSH_SERVER);
+
+ return 0;
+}
+
+static int session_teardown(void **state)
+{
+ struct torture_state *s = *state;
+
+ ssh_disconnect(s->ssh.session);
+ ssh_free(s->ssh.session);
+
+ ssh_finalize();
return 0;
}
@@ -44,148 +68,191 @@ static int teardown(void **state) {
static void test_algorithm(ssh_session session, const char *algo, const char *hmac) {
int rc;
- rc = ssh_options_set(session, SSH_OPTIONS_HOST, "localhost");
- assert_true(rc == SSH_OK);
-
rc = ssh_options_set(session, SSH_OPTIONS_CIPHERS_C_S, algo);
- assert_true(rc == SSH_OK);
+ assert_int_equal(rc, SSH_OK);
rc = ssh_options_set(session, SSH_OPTIONS_CIPHERS_S_C, algo);
- assert_true(rc == SSH_OK);
+ assert_int_equal(rc, SSH_OK);
rc = ssh_options_set(session, SSH_OPTIONS_HMAC_C_S, hmac);
- assert_true(rc == SSH_OK);
+ assert_int_equal(rc, SSH_OK);
rc = ssh_options_set(session, SSH_OPTIONS_HMAC_S_C, hmac);
- assert_true(rc == SSH_OK);
+ assert_int_equal(rc, SSH_OK);
rc = ssh_connect(session);
- assert_true(rc == SSH_OK);
+ assert_int_equal(rc, SSH_OK);
rc = ssh_userauth_none(session, NULL);
if (rc != SSH_OK) {
rc = ssh_get_error_code(session);
- assert_true(rc == SSH_REQUEST_DENIED);
+ assert_int_equal(rc, SSH_REQUEST_DENIED);
}
ssh_disconnect(session);
}
static void torture_algorithms_aes128_cbc_hmac_sha1(void **state) {
- test_algorithm(*state, "aes128-cbc", "hmac-sha1");
+ struct torture_state *s = *state;
+
+ test_algorithm(s->ssh.session, "aes128-cbc", "hmac-sha1");
}
static void torture_algorithms_aes128_cbc_hmac_sha2_256(void **state) {
- test_algorithm(*state, "aes128-cbc", "hmac-sha2-256");
+ struct torture_state *s = *state;
+
+ test_algorithm(s->ssh.session, "aes128-cbc", "hmac-sha2-256");
}
static void torture_algorithms_aes128_cbc_hmac_sha2_512(void **state) {
- test_algorithm(*state, "aes128-cbc", "hmac-sha2-512");
+ struct torture_state *s = *state;
+
+ test_algorithm(s->ssh.session, "aes128-cbc", "hmac-sha2-512");
}
static void torture_algorithms_aes192_cbc_hmac_sha1(void **state) {
- test_algorithm(*state, "aes192-cbc", "hmac-sha1");
+ struct torture_state *s = *state;
+
+ test_algorithm(s->ssh.session, "aes192-cbc", "hmac-sha1");
}
static void torture_algorithms_aes192_cbc_hmac_sha2_256(void **state) {
- test_algorithm(*state, "aes192-cbc", "hmac-sha2-256");
+ struct torture_state *s = *state;
+
+ test_algorithm(s->ssh.session, "aes192-cbc", "hmac-sha2-256");
}
static void torture_algorithms_aes192_cbc_hmac_sha2_512(void **state) {
- test_algorithm(*state, "aes192-cbc", "hmac-sha2-512");
+ struct torture_state *s = *state;
+
+ test_algorithm(s->ssh.session, "aes192-cbc", "hmac-sha2-512");
}
static void torture_algorithms_aes256_cbc_hmac_sha1(void **state) {
- test_algorithm(*state, "aes256-cbc", "hmac-sha1");
+ struct torture_state *s = *state;
+
+ test_algorithm(s->ssh.session, "aes256-cbc", "hmac-sha1");
}
static void torture_algorithms_aes256_cbc_hmac_sha2_256(void **state) {
- test_algorithm(*state, "aes256-cbc", "hmac-sha2-256");
+ struct torture_state *s = *state;
+
+ test_algorithm(s->ssh.session, "aes256-cbc", "hmac-sha2-256");
}
static void torture_algorithms_aes256_cbc_hmac_sha2_512(void **state) {
- test_algorithm(*state, "aes256-cbc", "hmac-sha2-512");
+ struct torture_state *s = *state;
+
+ test_algorithm(s->ssh.session, "aes256-cbc", "hmac-sha2-512");
}
static void torture_algorithms_aes128_ctr_hmac_sha1(void **state) {
- test_algorithm(*state, "aes128-ctr", "hmac-sha1");
+ struct torture_state *s = *state;
+
+ test_algorithm(s->ssh.session, "aes128-ctr", "hmac-sha1");
}
static void torture_algorithms_aes128_ctr_hmac_sha2_256(void **state) {
- test_algorithm(*state, "aes128-ctr", "hmac-sha2-256");
+ struct torture_state *s = *state;
+
+ test_algorithm(s->ssh.session, "aes128-ctr", "hmac-sha2-256");
}
static void torture_algorithms_aes128_ctr_hmac_sha2_512(void **state) {
- test_algorithm(*state, "aes128-ctr", "hmac-sha2-512");
+ struct torture_state *s = *state;
+
+ test_algorithm(s->ssh.session, "aes128-ctr", "hmac-sha2-512");
}
static void torture_algorithms_aes192_ctr_hmac_sha1(void **state) {
- test_algorithm(*state, "aes192-ctr", "hmac-sha1");
+ struct torture_state *s = *state;
+
+ test_algorithm(s->ssh.session, "aes192-ctr", "hmac-sha1");
}
static void torture_algorithms_aes192_ctr_hmac_sha2_256(void **state) {
- test_algorithm(*state, "aes192-ctr", "hmac-sha2-256");
+ struct torture_state *s = *state;
+
+ test_algorithm(s->ssh.session, "aes192-ctr", "hmac-sha2-256");
}
static void torture_algorithms_aes192_ctr_hmac_sha2_512(void **state) {
- test_algorithm(*state, "aes192-ctr", "hmac-sha2-512");
+ struct torture_state *s = *state;
+
+ test_algorithm(s->ssh.session, "aes192-ctr", "hmac-sha2-512");
}
static void torture_algorithms_aes256_ctr_hmac_sha1(void **state) {
- test_algorithm(*state, "aes256-ctr", "hmac-sha1");
+ struct torture_state *s = *state;
+
+ test_algorithm(s->ssh.session, "aes256-ctr", "hmac-sha1");
}
static void torture_algorithms_aes256_ctr_hmac_sha2_256(void **state) {
- test_algorithm(*state, "aes256-ctr", "hmac-sha2-256");
+ struct torture_state *s = *state;
+
+ test_algorithm(s->ssh.session, "aes256-ctr", "hmac-sha2-256");
}
static void torture_algorithms_aes256_ctr_hmac_sha2_512(void **state) {
- test_algorithm(*state, "aes256-ctr", "hmac-sha2-512");
+ struct torture_state *s = *state;
+
+ test_algorithm(s->ssh.session, "aes256-ctr", "hmac-sha2-512");
}
static void torture_algorithms_3des_cbc_hmac_sha1(void **state) {
- test_algorithm(*state, "3des-cbc", "hmac-sha1");
+ struct torture_state *s = *state;
+
+ test_algorithm(s->ssh.session, "3des-cbc", "hmac-sha1");
}
static void torture_algorithms_3des_cbc_hmac_sha2_256(void **state) {
- test_algorithm(*state, "3des-cbc", "hmac-sha2-256");
+ struct torture_state *s = *state;
+
+ test_algorithm(s->ssh.session, "3des-cbc", "hmac-sha2-256");
}
static void torture_algorithms_3des_cbc_hmac_sha2_512(void **state) {
- test_algorithm(*state, "3des-cbc", "hmac-sha2-512");
+ struct torture_state *s = *state;
+
+ test_algorithm(s->ssh.session, "3des-cbc", "hmac-sha2-512");
}
static void torture_algorithms_blowfish_cbc_hmac_sha1(void **state) {
- test_algorithm(*state, "blowfish-cbc", "hmac-sha1");
+ struct torture_state *s = *state;
+
+ test_algorithm(s->ssh.session, "blowfish-cbc", "hmac-sha1");
}
static void torture_algorithms_blowfish_cbc_hmac_sha2_256(void **state) {
- test_algorithm(*state, "blowfish-cbc", "hmac-sha2-256");
+ struct torture_state *s = *state;
+
+ test_algorithm(s->ssh.session, "blowfish-cbc", "hmac-sha2-256");
}
static void torture_algorithms_blowfish_cbc_hmac_sha2_512(void **state) {
- test_algorithm(*state, "blowfish-cbc", "hmac-sha2-512");
+ struct torture_state *s = *state;
+
+ test_algorithm(s->ssh.session, "blowfish-cbc", "hmac-sha2-512");
}
static void torture_algorithms_zlib(void **state) {
- ssh_session session = *state;
+ struct torture_state *s = *state;
+ ssh_session session = s->ssh.session;
int rc;
- rc = ssh_options_set(session,SSH_OPTIONS_HOST,"localhost");
- assert_true(rc == SSH_OK);
-
rc = ssh_options_set(session, SSH_OPTIONS_COMPRESSION_C_S, "zlib");
#ifdef WITH_ZLIB
- assert_true(rc == SSH_OK);
+ assert_int_equal(rc, SSH_OK);
#else
- assert_true(rc == SSH_ERROR);
+ assert_int_equal(rc, SSH_ERROR);
#endif
rc = ssh_options_set(session, SSH_OPTIONS_COMPRESSION_S_C, "zlib");
#ifdef WITH_ZLIB
- assert_true(rc == SSH_OK);
+ assert_int_equal(rc, SSH_OK);
#else
- assert_true(rc == SSH_ERROR);
+ assert_int_equal(rc, SSH_ERROR);
#endif
rc = ssh_connect(session);
@@ -196,36 +263,34 @@ static void torture_algorithms_zlib(void **state) {
return;
}
#endif
- assert_true(rc == SSH_OK);
+ assert_int_equal(rc, SSH_OK);
rc = ssh_userauth_none(session, NULL);
if (rc != SSH_OK) {
rc = ssh_get_error_code(session);
- assert_true(rc == SSH_REQUEST_DENIED);
+ assert_int_equal(rc, SSH_REQUEST_DENIED);
}
ssh_disconnect(session);
}
static void torture_algorithms_zlib_openssh(void **state) {
- ssh_session session = *state;
+ struct torture_state *s = *state;
+ ssh_session session = s->ssh.session;
int rc;
- rc = ssh_options_set(session,SSH_OPTIONS_HOST,"localhost");
- assert_true(rc == SSH_OK);
-
rc = ssh_options_set(session, SSH_OPTIONS_COMPRESSION_C_S, "zlib@openssh.com");
#ifdef WITH_ZLIB
- assert_true(rc == SSH_OK);
+ assert_int_equal(rc, SSH_OK);
#else
- assert_true(rc == SSH_ERROR);
+ assert_int_equal(rc, SSH_ERROR);
#endif
rc = ssh_options_set(session, SSH_OPTIONS_COMPRESSION_S_C, "zlib@openssh.com");
#ifdef WITH_ZLIB
- assert_true(rc == SSH_OK);
+ assert_int_equal(rc, SSH_OK);
#else
- assert_true(rc == SSH_ERROR);
+ assert_int_equal(rc, SSH_ERROR);
#endif
rc = ssh_connect(session);
@@ -235,14 +300,14 @@ static void torture_algorithms_zlib_openssh(void **state) {
rc = ssh_userauth_none(session, NULL);
if (rc != SSH_OK) {
rc = ssh_get_error_code(session);
- assert_true(rc == SSH_REQUEST_DENIED);
+ assert_int_equal(rc, SSH_REQUEST_DENIED);
}
ssh_disconnect(session);
return;
}
assert_false(rc == SSH_OK);
#else
- assert_true(rc == SSH_OK);
+ assert_int_equal(rc, SSH_OK);
#endif
ssh_disconnect(session);
@@ -250,21 +315,19 @@ static void torture_algorithms_zlib_openssh(void **state) {
#if defined(HAVE_LIBCRYPTO) && defined(HAVE_ECC)
static void torture_algorithms_ecdh_sha2_nistp256(void **state) {
- ssh_session session = *state;
+ struct torture_state *s = *state;
+ ssh_session session = s->ssh.session;
int rc;
- rc = ssh_options_set(session,SSH_OPTIONS_HOST,"localhost");
- assert_true(rc == SSH_OK);
-
rc = ssh_options_set(session, SSH_OPTIONS_KEY_EXCHANGE, "ecdh-sha2-nistp256");
- assert_true(rc == SSH_OK);
+ assert_int_equal(rc, SSH_OK);
rc = ssh_connect(session);
- assert_true(rc == SSH_OK);
+ assert_int_equal(rc, SSH_OK);
rc = ssh_userauth_none(session, NULL);
if (rc != SSH_OK) {
rc = ssh_get_error_code(session);
- assert_true(rc == SSH_REQUEST_DENIED);
+ assert_int_equal(rc, SSH_REQUEST_DENIED);
}
ssh_disconnect(session);
@@ -272,21 +335,19 @@ static void torture_algorithms_ecdh_sha2_nistp256(void **state) {
#endif
static void torture_algorithms_dh_group1(void **state) {
- ssh_session session = *state;
+ struct torture_state *s = *state;
+ ssh_session session = s->ssh.session;
int rc;
- rc = ssh_options_set(session,SSH_OPTIONS_HOST,"localhost");
- assert_true(rc == SSH_OK);
-
rc = ssh_options_set(session, SSH_OPTIONS_KEY_EXCHANGE, "diffie-hellman-group1-sha1");
- assert_true(rc == SSH_OK);
+ assert_int_equal(rc, SSH_OK);
rc = ssh_connect(session);
- assert_true(rc == SSH_OK);
+ assert_int_equal(rc, SSH_OK);
rc = ssh_userauth_none(session, NULL);
if (rc != SSH_OK) {
rc = ssh_get_error_code(session);
- assert_true(rc == SSH_REQUEST_DENIED);
+ assert_int_equal(rc, SSH_REQUEST_DENIED);
}
ssh_disconnect(session);
@@ -294,42 +355,96 @@ static void torture_algorithms_dh_group1(void **state) {
int torture_run_tests(void) {
int rc;
struct CMUnitTest tests[] = {
- cmocka_unit_test_setup_teardown(torture_algorithms_aes128_cbc_hmac_sha1, setup, teardown),
- cmocka_unit_test_setup_teardown(torture_algorithms_aes128_cbc_hmac_sha2_256, setup, teardown),
- cmocka_unit_test_setup_teardown(torture_algorithms_aes128_cbc_hmac_sha2_512, setup, teardown),
- cmocka_unit_test_setup_teardown(torture_algorithms_aes192_cbc_hmac_sha1, setup, teardown),
- cmocka_unit_test_setup_teardown(torture_algorithms_aes192_cbc_hmac_sha2_256, setup, teardown),
- cmocka_unit_test_setup_teardown(torture_algorithms_aes192_cbc_hmac_sha2_512, setup, teardown),
- cmocka_unit_test_setup_teardown(torture_algorithms_aes256_cbc_hmac_sha1, setup, teardown),
- cmocka_unit_test_setup_teardown(torture_algorithms_aes256_cbc_hmac_sha2_256, setup, teardown),
- cmocka_unit_test_setup_teardown(torture_algorithms_aes256_cbc_hmac_sha2_512, setup, teardown),
- cmocka_unit_test_setup_teardown(torture_algorithms_aes128_ctr_hmac_sha1, setup, teardown),
- cmocka_unit_test_setup_teardown(torture_algorithms_aes128_ctr_hmac_sha2_256, setup, teardown),
- cmocka_unit_test_setup_teardown(torture_algorithms_aes128_ctr_hmac_sha2_512, setup, teardown),
- cmocka_unit_test_setup_teardown(torture_algorithms_aes192_ctr_hmac_sha1, setup, teardown),
- cmocka_unit_test_setup_teardown(torture_algorithms_aes192_ctr_hmac_sha2_256, setup, teardown),
- cmocka_unit_test_setup_teardown(torture_algorithms_aes192_ctr_hmac_sha2_512, setup, teardown),
- cmocka_unit_test_setup_teardown(torture_algorithms_aes256_ctr_hmac_sha1, setup, teardown),
- cmocka_unit_test_setup_teardown(torture_algorithms_aes256_ctr_hmac_sha2_256, setup, teardown),
- cmocka_unit_test_setup_teardown(torture_algorithms_aes256_ctr_hmac_sha2_512, setup, teardown),
- cmocka_unit_test_setup_teardown(torture_algorithms_3des_cbc_hmac_sha1, setup, teardown),
- cmocka_unit_test_setup_teardown(torture_algorithms_3des_cbc_hmac_sha2_256, setup, teardown),
- cmocka_unit_test_setup_teardown(torture_algorithms_3des_cbc_hmac_sha2_512, setup, teardown),
- cmocka_unit_test_setup_teardown(torture_algorithms_blowfish_cbc_hmac_sha1, setup, teardown),
- cmocka_unit_test_setup_teardown(torture_algorithms_blowfish_cbc_hmac_sha2_256, setup, teardown),
- cmocka_unit_test_setup_teardown(torture_algorithms_blowfish_cbc_hmac_sha2_512, setup, teardown),
- cmocka_unit_test_setup_teardown(torture_algorithms_zlib, setup, teardown),
- cmocka_unit_test_setup_teardown(torture_algorithms_zlib_openssh, setup, teardown),
- cmocka_unit_test_setup_teardown(torture_algorithms_dh_group1,setup,teardown),
+ cmocka_unit_test_setup_teardown(torture_algorithms_aes128_cbc_hmac_sha1,
+ session_setup,
+ session_teardown),
+ cmocka_unit_test_setup_teardown(torture_algorithms_aes128_cbc_hmac_sha2_256,
+ session_setup,
+ session_teardown),
+ cmocka_unit_test_setup_teardown(torture_algorithms_aes128_cbc_hmac_sha2_512,
+ session_setup,
+ session_teardown),
+ cmocka_unit_test_setup_teardown(torture_algorithms_aes192_cbc_hmac_sha1,
+ session_setup,
+ session_teardown),
+ cmocka_unit_test_setup_teardown(torture_algorithms_aes192_cbc_hmac_sha2_256,
+ session_setup,
+ session_teardown),
+ cmocka_unit_test_setup_teardown(torture_algorithms_aes192_cbc_hmac_sha2_512,
+ session_setup,
+ session_teardown),
+ cmocka_unit_test_setup_teardown(torture_algorithms_aes256_cbc_hmac_sha1,
+ session_setup,
+ session_teardown),
+ cmocka_unit_test_setup_teardown(torture_algorithms_aes256_cbc_hmac_sha2_256,
+ session_setup,
+ session_teardown),
+ cmocka_unit_test_setup_teardown(torture_algorithms_aes256_cbc_hmac_sha2_512,
+ session_setup,
+ session_teardown),
+ cmocka_unit_test_setup_teardown(torture_algorithms_aes128_ctr_hmac_sha1,
+ session_setup,
+ session_teardown),
+ cmocka_unit_test_setup_teardown(torture_algorithms_aes128_ctr_hmac_sha2_256,
+ session_setup,
+ session_teardown),
+ cmocka_unit_test_setup_teardown(torture_algorithms_aes128_ctr_hmac_sha2_512,
+ session_setup,
+ session_teardown),
+ cmocka_unit_test_setup_teardown(torture_algorithms_aes192_ctr_hmac_sha1,
+ session_setup,
+ session_teardown),
+ cmocka_unit_test_setup_teardown(torture_algorithms_aes192_ctr_hmac_sha2_256,
+ session_setup,
+ session_teardown),
+ cmocka_unit_test_setup_teardown(torture_algorithms_aes192_ctr_hmac_sha2_512,
+ session_setup,
+ session_teardown),
+ cmocka_unit_test_setup_teardown(torture_algorithms_aes256_ctr_hmac_sha1,
+ session_setup,
+ session_teardown),
+ cmocka_unit_test_setup_teardown(torture_algorithms_aes256_ctr_hmac_sha2_256,
+ session_setup,
+ session_teardown),
+ cmocka_unit_test_setup_teardown(torture_algorithms_aes256_ctr_hmac_sha2_512,
+ session_setup,
+ session_teardown),
+ cmocka_unit_test_setup_teardown(torture_algorithms_3des_cbc_hmac_sha1,
+ session_setup,
+ session_teardown),
+ cmocka_unit_test_setup_teardown(torture_algorithms_3des_cbc_hmac_sha2_256,
+ session_setup,
+ session_teardown),
+ cmocka_unit_test_setup_teardown(torture_algorithms_3des_cbc_hmac_sha2_512,
+ session_setup,
+ session_teardown),
+ cmocka_unit_test_setup_teardown(torture_algorithms_blowfish_cbc_hmac_sha1,
+ session_setup,
+ session_teardown),
+ cmocka_unit_test_setup_teardown(torture_algorithms_blowfish_cbc_hmac_sha2_256,
+ session_setup,
+ session_teardown),
+ cmocka_unit_test_setup_teardown(torture_algorithms_blowfish_cbc_hmac_sha2_512,
+ session_setup,
+ session_teardown),
+ cmocka_unit_test_setup_teardown(torture_algorithms_zlib,
+ session_setup,
+ session_teardown),
+ cmocka_unit_test_setup_teardown(torture_algorithms_zlib_openssh,
+ session_setup,
+ session_teardown),
+ cmocka_unit_test_setup_teardown(torture_algorithms_dh_group1,
+ session_setup,
+ session_teardown),
#if defined(HAVE_LIBCRYPTO) && defined(HAVE_ECC)
- cmocka_unit_test_setup_teardown(torture_algorithms_ecdh_sha2_nistp256,setup,teardown)
+ cmocka_unit_test_setup_teardown(torture_algorithms_ecdh_sha2_nistp256,
+ session_setup,
+ session_teardown),
#endif
};
- ssh_init();
torture_filter_tests(tests);
- rc = cmocka_run_group_tests(tests, NULL, NULL);
- ssh_finalize();
+ rc = cmocka_run_group_tests(tests, sshd_setup, sshd_teardown);
return rc;
}