1
1

tests: Add test for reading ecdsa privkey.

Этот коммит содержится в:
Andreas Schneider 2011-12-27 21:23:11 +01:00
родитель ea74a12b70
Коммит d44a79da9b

Просмотреть файл

@ -7,6 +7,7 @@
#define LIBSSH_RSA_TESTKEY "libssh_testkey.id_rsa"
#define LIBSSH_DSA_TESTKEY "libssh_testkey.id_dsa"
#define LIBSSH_ECDSA_TESTKEY "libssh_testkey.id_ecdsa"
#define LIBSSH_PASSPHRASE "libssh-rocks"
const unsigned char HASH[] = "12345678901234567890";
@ -34,6 +35,20 @@ static void setup_dsa_key(void **state) {
assert_true(rc == 0);
}
#ifdef HAVE_OPENSSL_ECC
static void setup_ecdsa_key(void **state) {
int rc;
(void) state; /* unused */
unlink(LIBSSH_ECDSA_TESTKEY);
unlink(LIBSSH_ECDSA_TESTKEY ".pub");
rc = system("ssh-keygen -t ecdsa -q -N \"\" -f " LIBSSH_ECDSA_TESTKEY);
assert_true(rc == 0);
}
#endif
static void setup_both_keys(void **state) {
(void) state; /* unused */
@ -61,6 +76,9 @@ static void teardown(void **state) {
unlink(LIBSSH_RSA_TESTKEY);
unlink(LIBSSH_RSA_TESTKEY ".pub");
unlink(LIBSSH_ECDSA_TESTKEY);
unlink(LIBSSH_ECDSA_TESTKEY ".pub");
}
static char *read_file(const char *filename) {
@ -227,6 +245,24 @@ static void torture_pki_import_privkey_base64_DSA(void **state) {
ssh_key_free(key);
}
static void torture_pki_import_privkey_base64_ECDSA(void **state) {
int rc;
char *key_str;
ssh_key key;
const char *passphrase = LIBSSH_PASSPHRASE;
(void) state; /* unused */
key_str = read_file(LIBSSH_ECDSA_TESTKEY);
assert_true(key_str != NULL);
rc = ssh_pki_import_privkey_base64(key_str, passphrase, NULL, NULL, &key);
assert_true(rc == 0);
free(key_str);
ssh_key_free(key);
}
static void torture_pki_import_privkey_base64_passphrase(void **state) {
int rc;
char *key_str;
@ -725,6 +761,9 @@ int torture_run_tests(void) {
unit_test_setup_teardown(torture_pki_import_privkey_base64_DSA,
setup_dsa_key,
teardown),
unit_test_setup_teardown(torture_pki_import_privkey_base64_ECDSA,
setup_ecdsa_key,
teardown),
unit_test_setup_teardown(torture_pki_import_privkey_base64_passphrase,
setup_both_keys_passphrase,
teardown),