aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAris Adamantiadis <aris@0xbadc0de.be>2010-04-27 23:48:18 +0200
committerAris Adamantiadis <aris@0xbadc0de.be>2010-04-27 23:48:18 +0200
commit696ef7aecc07d19bc23179504042617e21e11a44 (patch)
treec240bfb203f396bdcf7a40f742201ab95882a438
parent9603f2520bfe6f7a2cd3dd324fec80455552379b (diff)
downloadlibssh-696ef7aecc07d19bc23179504042617e21e11a44.tar.gz
libssh-696ef7aecc07d19bc23179504042617e21e11a44.tar.xz
libssh-696ef7aecc07d19bc23179504042617e21e11a44.zip
Added privatekey_from_file with passphrase test
-rw-r--r--tests/unittests/torture_keyfiles.c43
1 files changed, 42 insertions, 1 deletions
diff --git a/tests/unittests/torture_keyfiles.c b/tests/unittests/torture_keyfiles.c
index a1d903ef..200ea799 100644
--- a/tests/unittests/torture_keyfiles.c
+++ b/tests/unittests/torture_keyfiles.c
@@ -5,7 +5,7 @@
#define LIBSSH_RSA_TESTKEY "libssh_testkey.id_rsa"
#define LIBSSH_DSA_TESTKEY "libssh_testkey.id_dsa"
-
+#define LIBSSH_PASSPHRASE "libssh-rocks"
ssh_session session;
#if 0
@@ -40,6 +40,11 @@ static void setup_both_keys(void) {
setup_dsa_key();
}
+static void setup_both_keys_passphrase(void) {
+ system("ssh-keygen -t rsa -N " LIBSSH_PASSPHRASE " -f " LIBSSH_RSA_TESTKEY);
+ system("ssh-keygen -t dsa -N " LIBSSH_PASSPHRASE " -f " LIBSSH_DSA_TESTKEY);
+ session = ssh_new();
+}
static void teardown(void) {
unlink(LIBSSH_DSA_TESTKEY);
unlink(LIBSSH_DSA_TESTKEY ".pub");
@@ -184,6 +189,40 @@ START_TEST(torture_privatekey_from_file){
}
END_TEST
+/**
+ * @brief tests the privatekey_from_file function with passphrase
+ */
+START_TEST(torture_privatekey_from_file_passphrase){
+ ssh_private_key key=NULL;
+ key=privatekey_from_file(session, LIBSSH_RSA_TESTKEY, TYPE_RSA, LIBSSH_PASSPHRASE);
+ ck_assert(key != NULL);
+ if(key != NULL){
+ privatekey_free(key);
+ key=NULL;
+ }
+ key=privatekey_from_file(session, LIBSSH_DSA_TESTKEY, TYPE_DSS, LIBSSH_PASSPHRASE);
+ ck_assert(key != NULL);
+ if(key != NULL){
+ privatekey_free(key);
+ key=NULL;
+ }
+ /* test the automatic type discovery */
+ key=privatekey_from_file(session, LIBSSH_RSA_TESTKEY, 0, LIBSSH_PASSPHRASE);
+ ck_assert(key != NULL);
+ if(key != NULL){
+ privatekey_free(key);
+ key=NULL;
+ }
+ key=privatekey_from_file(session, LIBSSH_DSA_TESTKEY, 0, LIBSSH_PASSPHRASE);
+ ck_assert(key != NULL);
+ if(key != NULL){
+ privatekey_free(key);
+ key=NULL;
+ }
+
+}
+END_TEST
+
static Suite *torture_make_suite(void) {
Suite *s = suite_create("libssh_keyfiles");
@@ -193,6 +232,8 @@ static Suite *torture_make_suite(void) {
torture_pubkey_generate_from_privkey, setup_rsa_key, teardown);
torture_create_case_fixture(s, "torture_privkey_from_file",
torture_privatekey_from_file, setup_both_keys, teardown);
+ torture_create_case_fixture(s, "torture_privkey_from_file_passphrase",
+ torture_privatekey_from_file_passphrase, setup_both_keys_passphrase, teardown);
return s;
}