From d44a79da9b92566d34a2da7eeb0d1deb2fda6508 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 27 Dec 2011 21:23:11 +0100 Subject: tests: Add test for reading ecdsa privkey. --- tests/unittests/torture_pki.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'tests/unittests/torture_pki.c') diff --git a/tests/unittests/torture_pki.c b/tests/unittests/torture_pki.c index ca6e04b2..17903cc4 100644 --- a/tests/unittests/torture_pki.c +++ b/tests/unittests/torture_pki.c @@ -7,6 +7,7 @@ #define LIBSSH_RSA_TESTKEY "libssh_testkey.id_rsa" #define LIBSSH_DSA_TESTKEY "libssh_testkey.id_dsa" +#define LIBSSH_ECDSA_TESTKEY "libssh_testkey.id_ecdsa" #define LIBSSH_PASSPHRASE "libssh-rocks" const unsigned char HASH[] = "12345678901234567890"; @@ -34,6 +35,20 @@ static void setup_dsa_key(void **state) { assert_true(rc == 0); } +#ifdef HAVE_OPENSSL_ECC +static void setup_ecdsa_key(void **state) { + int rc; + + (void) state; /* unused */ + + unlink(LIBSSH_ECDSA_TESTKEY); + unlink(LIBSSH_ECDSA_TESTKEY ".pub"); + + rc = system("ssh-keygen -t ecdsa -q -N \"\" -f " LIBSSH_ECDSA_TESTKEY); + assert_true(rc == 0); +} +#endif + static void setup_both_keys(void **state) { (void) state; /* unused */ @@ -61,6 +76,9 @@ static void teardown(void **state) { unlink(LIBSSH_RSA_TESTKEY); unlink(LIBSSH_RSA_TESTKEY ".pub"); + + unlink(LIBSSH_ECDSA_TESTKEY); + unlink(LIBSSH_ECDSA_TESTKEY ".pub"); } static char *read_file(const char *filename) { @@ -227,6 +245,24 @@ static void torture_pki_import_privkey_base64_DSA(void **state) { ssh_key_free(key); } +static void torture_pki_import_privkey_base64_ECDSA(void **state) { + int rc; + char *key_str; + ssh_key key; + const char *passphrase = LIBSSH_PASSPHRASE; + + (void) state; /* unused */ + + key_str = read_file(LIBSSH_ECDSA_TESTKEY); + assert_true(key_str != NULL); + + rc = ssh_pki_import_privkey_base64(key_str, passphrase, NULL, NULL, &key); + assert_true(rc == 0); + + free(key_str); + ssh_key_free(key); +} + static void torture_pki_import_privkey_base64_passphrase(void **state) { int rc; char *key_str; @@ -725,6 +761,9 @@ int torture_run_tests(void) { unit_test_setup_teardown(torture_pki_import_privkey_base64_DSA, setup_dsa_key, teardown), + unit_test_setup_teardown(torture_pki_import_privkey_base64_ECDSA, + setup_ecdsa_key, + teardown), unit_test_setup_teardown(torture_pki_import_privkey_base64_passphrase, setup_both_keys_passphrase, teardown), -- cgit v1.2.3