diff options
author | Andreas Schneider <asn@cryptomilk.org> | 2011-12-29 11:08:01 +0100 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2012-02-04 18:37:04 +0100 |
commit | 14bb23ae3b2545ce1ee4aef3829dc6da1e341ee2 (patch) | |
tree | 1ab748579b6a99068bc3c790f436ec31344eee97 /tests/unittests/torture_pki.c | |
parent | 0e1992a9cccab655be345c115fc586ab9acbd404 (diff) | |
download | libssh-14bb23ae3b2545ce1ee4aef3829dc6da1e341ee2.tar.gz libssh-14bb23ae3b2545ce1ee4aef3829dc6da1e341ee2.tar.xz libssh-14bb23ae3b2545ce1ee4aef3829dc6da1e341ee2.zip |
tests: Add ecdsa pubkey_from_privkey test.
Diffstat (limited to 'tests/unittests/torture_pki.c')
-rw-r--r-- | tests/unittests/torture_pki.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/unittests/torture_pki.c b/tests/unittests/torture_pki.c index 6e380851..761ef1d0 100644 --- a/tests/unittests/torture_pki.c +++ b/tests/unittests/torture_pki.c @@ -577,6 +577,47 @@ static void torture_generate_pubkey_from_privkey_dsa(void **state) { ssh_key_free(pubkey); } +static void torture_generate_pubkey_from_privkey_ecdsa(void **state) { + char pubkey_original[4096] = {0}; + char pubkey_generated[4096] = {0}; + ssh_key privkey; + ssh_key pubkey; + int rc; + + (void) state; /* unused */ + + rc = torture_read_one_line(LIBSSH_ECDSA_TESTKEY ".pub", + pubkey_original, + sizeof(pubkey_original)); + assert_true(rc == 0); + + /* remove the public key, generate it from the private key and write it. */ + unlink(LIBSSH_ECDSA_TESTKEY ".pub"); + + rc = ssh_pki_import_privkey_file(LIBSSH_ECDSA_TESTKEY, + NULL, + NULL, + NULL, + &privkey); + assert_true(rc == 0); + + rc = ssh_pki_export_privkey_to_pubkey(privkey, &pubkey); + assert_true(rc == SSH_OK); + + rc = ssh_pki_export_pubkey_file(pubkey, LIBSSH_ECDSA_TESTKEY ".pub"); + assert_true(rc == 0); + + rc = torture_read_one_line(LIBSSH_ECDSA_TESTKEY ".pub", + pubkey_generated, + sizeof(pubkey_generated)); + assert_true(rc == 0); + + assert_string_equal(pubkey_original, pubkey_generated); + + ssh_key_free(privkey); + ssh_key_free(pubkey); +} + static void torture_pki_duplicate_key_rsa(void **state) { int rc; @@ -851,6 +892,9 @@ int torture_run_tests(void) { unit_test_setup_teardown(torture_generate_pubkey_from_privkey_dsa, setup_dsa_key, teardown), + unit_test_setup_teardown(torture_generate_pubkey_from_privkey_ecdsa, + setup_ecdsa_key, + teardown), unit_test_setup_teardown(torture_generate_pubkey_from_privkey_rsa, setup_rsa_key, teardown), |