aboutsummaryrefslogtreecommitdiff
path: root/tests/unittests
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2018-01-10 21:24:32 +0100
committerAndreas Schneider <asn@cryptomilk.org>2018-01-10 22:31:02 +0100
commitf9b1dece418ec418493fb063ec5b70d52b06b2c2 (patch)
treedcbab6fdd588b5df470ad19879e22771bb8c4aed /tests/unittests
parentf7a2330de7fe7a83b5f8971ccb747e8c31b35a5b (diff)
downloadlibssh-f9b1dece418ec418493fb063ec5b70d52b06b2c2.tar.gz
libssh-f9b1dece418ec418493fb063ec5b70d52b06b2c2.tar.xz
libssh-f9b1dece418ec418493fb063ec5b70d52b06b2c2.zip
torture_pki_dsa: Add tests for private key with passphrase
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Diffstat (limited to 'tests/unittests')
-rw-r--r--tests/unittests/torture_pki_dsa.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/unittests/torture_pki_dsa.c b/tests/unittests/torture_pki_dsa.c
index 1bfdb894..836b2538 100644
--- a/tests/unittests/torture_pki_dsa.c
+++ b/tests/unittests/torture_pki_dsa.c
@@ -12,6 +12,7 @@
#include "pki.c"
#define LIBSSH_DSA_TESTKEY "libssh_testkey.id_dsa"
+#define LIBSSH_DSA_TESTKEY_PASSPHRASE "libssh_testkey_passphrase.id_dsa"
const unsigned char DSA_HASH[] = "12345678901234567890";
@@ -20,11 +21,14 @@ static int setup_dsa_key(void **state)
(void) state; /* unused */
unlink(LIBSSH_DSA_TESTKEY);
+ unlink(LIBSSH_DSA_TESTKEY_PASSPHRASE);
unlink(LIBSSH_DSA_TESTKEY ".pub");
unlink(LIBSSH_DSA_TESTKEY "-cert.pub");
torture_write_file(LIBSSH_DSA_TESTKEY,
torture_get_testkey(SSH_KEYTYPE_DSS, 0, 0));
+ torture_write_file(LIBSSH_DSA_TESTKEY_PASSPHRASE,
+ torture_get_testkey(SSH_KEYTYPE_DSS, 0, 0));
torture_write_file(LIBSSH_DSA_TESTKEY ".pub",
torture_get_testkey_pub(SSH_KEYTYPE_DSS, 0));
torture_write_file(LIBSSH_DSA_TESTKEY "-cert.pub",
@@ -38,6 +42,7 @@ static int teardown_dsa_key(void **state)
(void)state;
unlink(LIBSSH_DSA_TESTKEY);
+ unlink(LIBSSH_DSA_TESTKEY_PASSPHRASE);
unlink(LIBSSH_DSA_TESTKEY ".pub");
unlink(LIBSSH_DSA_TESTKEY "-cert.pub");
@@ -99,6 +104,43 @@ static void torture_pki_dsa_write_privkey(void **state)
ssh_key_free(origkey);
ssh_key_free(privkey);
+
+ /* Test with passphrase */
+ rc = ssh_pki_import_privkey_file(LIBSSH_DSA_TESTKEY_PASSPHRASE,
+ torture_get_testkey_passphrase(),
+ NULL,
+ NULL,
+ &origkey);
+ assert_true(rc == 0);
+
+ unlink(LIBSSH_DSA_TESTKEY_PASSPHRASE);
+ rc = ssh_pki_export_privkey_file(origkey,
+ torture_get_testkey_passphrase(),
+ NULL,
+ NULL,
+ LIBSSH_DSA_TESTKEY_PASSPHRASE);
+ assert_true(rc == 0);
+
+ /* Test with invalid passphrase */
+ rc = ssh_pki_import_privkey_file(LIBSSH_DSA_TESTKEY_PASSPHRASE,
+ "invalid secret",
+ NULL,
+ NULL,
+ &privkey);
+ assert_true(rc == SSH_ERROR);
+
+ rc = ssh_pki_import_privkey_file(LIBSSH_DSA_TESTKEY_PASSPHRASE,
+ torture_get_testkey_passphrase(),
+ NULL,
+ NULL,
+ &privkey);
+ assert_true(rc == 0);
+
+ rc = ssh_key_cmp(origkey, privkey, SSH_KEY_CMP_PRIVATE);
+ assert_true(rc == 0);
+
+ ssh_key_free(origkey);
+ ssh_key_free(privkey);
}
#endif