diff options
Diffstat (limited to 'tests/unittests/torture_pki_rsa.c')
-rw-r--r-- | tests/unittests/torture_pki_rsa.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/unittests/torture_pki_rsa.c b/tests/unittests/torture_pki_rsa.c index b1dd97d0..54e459f9 100644 --- a/tests/unittests/torture_pki_rsa.c +++ b/tests/unittests/torture_pki_rsa.c @@ -12,6 +12,7 @@ #include "pki.c" #define LIBSSH_RSA_TESTKEY "libssh_testkey.id_rsa" +#define LIBSSH_RSA_TESTKEY_PASSPHRASE "libssh_testkey_passphrase.id_rsa" const unsigned char RSA_HASH[] = "12345678901234567890"; @@ -20,11 +21,14 @@ static int setup_rsa_key(void **state) (void) state; /* unused */ unlink(LIBSSH_RSA_TESTKEY); + unlink(LIBSSH_RSA_TESTKEY_PASSPHRASE); unlink(LIBSSH_RSA_TESTKEY ".pub"); unlink(LIBSSH_RSA_TESTKEY "-cert.pub"); torture_write_file(LIBSSH_RSA_TESTKEY, torture_get_testkey(SSH_KEYTYPE_RSA, 0, 0)); + torture_write_file(LIBSSH_RSA_TESTKEY_PASSPHRASE, + torture_get_testkey(SSH_KEYTYPE_RSA, 0, 1)); torture_write_file(LIBSSH_RSA_TESTKEY ".pub", torture_get_testkey_pub(SSH_KEYTYPE_RSA, 0)); torture_write_file(LIBSSH_RSA_TESTKEY "-cert.pub", @@ -37,6 +41,7 @@ static int teardown(void **state) { (void) state; /* unused */ unlink(LIBSSH_RSA_TESTKEY); + unlink(LIBSSH_RSA_TESTKEY_PASSPHRASE); unlink(LIBSSH_RSA_TESTKEY ".pub"); unlink(LIBSSH_RSA_TESTKEY "-cert.pub"); @@ -452,6 +457,43 @@ static void torture_pki_rsa_write_privkey(void **state) ssh_key_free(origkey); ssh_key_free(privkey); + + /* Test with passphrase */ + rc = ssh_pki_import_privkey_file(LIBSSH_RSA_TESTKEY_PASSPHRASE, + torture_get_testkey_passphrase(), + NULL, + NULL, + &origkey); + assert_true(rc == 0); + + unlink(LIBSSH_RSA_TESTKEY_PASSPHRASE); + rc = ssh_pki_export_privkey_file(origkey, + torture_get_testkey_passphrase(), + NULL, + NULL, + LIBSSH_RSA_TESTKEY_PASSPHRASE); + assert_true(rc == 0); + + /* Test with invalid passphrase */ + rc = ssh_pki_import_privkey_file(LIBSSH_RSA_TESTKEY_PASSPHRASE, + "invalid secret", + NULL, + NULL, + &privkey); + assert_true(rc == SSH_ERROR); + + rc = ssh_pki_import_privkey_file(LIBSSH_RSA_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 /* HAVE_LIBCRYPTO */ |