aboutsummaryrefslogtreecommitdiff
path: root/tests/unittests
diff options
context:
space:
mode:
authorAlan Dunn <amdunn@gmail.com>2014-03-12 08:34:01 -0500
committerAndreas Schneider <asn@cryptomilk.org>2014-03-27 10:01:01 +0100
commit577840d7f72a3c69c09f2cb477b2c46eb2831f81 (patch)
tree7e71894ae3eebc24baf9d4b656136453007dd75f /tests/unittests
parent3d9b1693ebc1655563324ad8d890beb2a23d937b (diff)
downloadlibssh-577840d7f72a3c69c09f2cb477b2c46eb2831f81.tar.gz
libssh-577840d7f72a3c69c09f2cb477b2c46eb2831f81.tar.xz
libssh-577840d7f72a3c69c09f2cb477b2c46eb2831f81.zip
tests: Add test case for bug #147
Signed-off-by: Alan Dunn <amdunn@gmail.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
Diffstat (limited to 'tests/unittests')
-rw-r--r--tests/unittests/torture_pki.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/unittests/torture_pki.c b/tests/unittests/torture_pki.c
index 5de0f44d..6fede44a 100644
--- a/tests/unittests/torture_pki.c
+++ b/tests/unittests/torture_pki.c
@@ -766,6 +766,37 @@ static void torture_pki_duplicate_key_ecdsa(void **state)
ssh_string_free_char(b64_key);
ssh_string_free_char(b64_key_gen);
}
+
+/* Test case for bug #147: Private ECDSA key duplication did not carry
+ * over parts of the key that then caused subsequent key demotion to
+ * fail.
+ */
+static void torture_pki_ecdsa_duplicate_then_demote(void **state)
+{
+ ssh_key pubkey;
+ ssh_key privkey;
+ ssh_key privkey_dup;
+ int rc;
+
+ (void) state;
+
+ rc = ssh_pki_import_privkey_file(LIBSSH_ECDSA_TESTKEY,
+ NULL,
+ NULL,
+ NULL,
+ &privkey);
+ assert_true(rc == 0);
+
+ privkey_dup = ssh_key_dup(privkey);
+ assert_true(privkey_dup != NULL);
+
+ rc = ssh_pki_export_privkey_to_pubkey(privkey_dup, &pubkey);
+ assert_true(rc == 0);
+
+ ssh_key_free(pubkey);
+ ssh_key_free(privkey);
+ ssh_key_free(privkey_dup);
+}
#endif
static void torture_pki_generate_key_rsa(void **state)
@@ -1109,6 +1140,9 @@ int torture_run_tests(void) {
unit_test_setup_teardown(torture_pki_publickey_from_privatekey_ECDSA,
setup_ecdsa_key,
teardown),
+ unit_test_setup_teardown(torture_pki_ecdsa_duplicate_then_demote,
+ setup_ecdsa_key,
+ teardown),
#endif
/* public key */
unit_test_setup_teardown(torture_pki_publickey_dsa_base64,