aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2011-12-27 21:23:11 +0100
committerAndreas Schneider <asn@cryptomilk.org>2012-02-04 18:37:04 +0100
commitd44a79da9b92566d34a2da7eeb0d1deb2fda6508 (patch)
tree7a8de9b4bb18ef7d720607d3e536b2975e473e23 /tests
parentea74a12b70549113039ef61fc89ae84b08a05bcd (diff)
downloadlibssh-d44a79da9b92566d34a2da7eeb0d1deb2fda6508.tar.gz
libssh-d44a79da9b92566d34a2da7eeb0d1deb2fda6508.tar.xz
libssh-d44a79da9b92566d34a2da7eeb0d1deb2fda6508.zip
tests: Add test for reading ecdsa privkey.
Diffstat (limited to 'tests')
-rw-r--r--tests/unittests/torture_pki.c39
1 files changed, 39 insertions, 0 deletions
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),