diff options
author | Andreas Schneider <asn@cryptomilk.org> | 2018-04-25 16:25:32 +0200 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2018-04-25 16:25:32 +0200 |
commit | 816234350d45ad5743d4cedecc0ed48cc683ed4f (patch) | |
tree | 71bb97c2a8686b8da2b96f461355a9b11667ed8a /tests | |
parent | 4aeb0cfd9ce401dc0e3a8e71594a73e1b3b49da2 (diff) | |
download | libssh-816234350d45ad5743d4cedecc0ed48cc683ed4f.tar.gz libssh-816234350d45ad5743d4cedecc0ed48cc683ed4f.tar.xz libssh-816234350d45ad5743d4cedecc0ed48cc683ed4f.zip |
pki: Fix duplicating ed25519 public keys
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unittests/torture_pki_ed25519.c | 67 |
1 files changed, 66 insertions, 1 deletions
diff --git a/tests/unittests/torture_pki_ed25519.c b/tests/unittests/torture_pki_ed25519.c index 2d85197e..e397e50a 100644 --- a/tests/unittests/torture_pki_ed25519.c +++ b/tests/unittests/torture_pki_ed25519.c @@ -445,6 +445,69 @@ static void torture_pki_ed25519_import_privkey_base64_passphrase(void **state) ssh_key_free(key); } +static void torture_pki_ed25519_privkey_dup(void **state) +{ + const char *passphrase = torture_get_testkey_passphrase(); + ssh_key key = NULL; + ssh_key dup = NULL; + int rc; + + (void) state; /* unused */ + + rc = ssh_pki_import_privkey_base64(torture_get_testkey(SSH_KEYTYPE_ED25519, 0, 1), + passphrase, + NULL, + NULL, + &key); + assert_true(rc == 0); + + rc = ssh_key_is_private(key); + assert_true(rc == 1); + + dup = ssh_key_dup(key); + assert_non_null(dup); + + SAFE_FREE(key); + SAFE_FREE(dup); +} + +static void torture_pki_ed25519_pubkey_dup(void **state) +{ + ssh_key pubkey = NULL; + ssh_key dup = NULL; + const char *p = strchr(torture_get_testkey_pub(SSH_KEYTYPE_ED25519, 0), ' '); + char *pub_str = NULL; + char *q = NULL; + int rc; + + (void) state; /* unused */ + + pub_str = strdup(p + 1); + assert_non_null(pub_str); + + q = strchr(pub_str, ' '); + assert_non_null(q); + *q = '\0'; + + rc = ssh_pki_import_pubkey_base64(pub_str, + SSH_KEYTYPE_ED25519, + &pubkey); + assert_true(rc == 0); + + rc = ssh_key_is_public(pubkey); + assert_true(rc == 1); + + dup = ssh_key_dup(pubkey); + assert_non_null(dup); + + rc = ssh_key_is_public(dup); + assert_true(rc == 1); + + SAFE_FREE(pub_str); + SAFE_FREE(pubkey); + SAFE_FREE(dup); +} + int torture_run_tests(void) { int rc; const struct CMUnitTest tests[] = { @@ -467,7 +530,9 @@ int torture_run_tests(void) { cmocka_unit_test(torture_pki_ed25519_import_privkey_base64_passphrase), cmocka_unit_test(torture_pki_ed25519_sign), cmocka_unit_test(torture_pki_ed25519_verify), - cmocka_unit_test(torture_pki_ed25519_verify_bad) + cmocka_unit_test(torture_pki_ed25519_verify_bad), + cmocka_unit_test(torture_pki_ed25519_privkey_dup), + cmocka_unit_test(torture_pki_ed25519_pubkey_dup), }; ssh_init(); |