torture_pki_ed25519: Add tests for private key with passphrase
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Этот коммит содержится в:
родитель
9086d5ca33
Коммит
e9073a6bdb
@ -10,6 +10,7 @@
|
||||
#include <fcntl.h>
|
||||
|
||||
#define LIBSSH_ED25519_TESTKEY "libssh_testkey.id_ed25519"
|
||||
#define LIBSSH_ED25519_TESTKEY_PASSPHRASE "libssh_testkey_passphrase.id_ed25519"
|
||||
|
||||
const unsigned char HASH[] = "12345678901234567890";
|
||||
const uint8_t ref_signature[ED25519_SIG_LEN]=
|
||||
@ -23,10 +24,13 @@ static int setup_ed25519_key(void **state)
|
||||
(void) state; /* unused */
|
||||
|
||||
unlink(LIBSSH_ED25519_TESTKEY);
|
||||
unlink(LIBSSH_ED25519_TESTKEY_PASSPHRASE);
|
||||
unlink(LIBSSH_ED25519_TESTKEY ".pub");
|
||||
|
||||
torture_write_file(LIBSSH_ED25519_TESTKEY,
|
||||
torture_get_testkey(SSH_KEYTYPE_ED25519, 0,0));
|
||||
torture_write_file(LIBSSH_ED25519_TESTKEY_PASSPHRASE,
|
||||
torture_get_testkey(SSH_KEYTYPE_ED25519, 0,0));
|
||||
|
||||
torture_write_file(LIBSSH_ED25519_TESTKEY ".pub",
|
||||
torture_get_testkey_pub(SSH_KEYTYPE_ED25519,0));
|
||||
@ -38,6 +42,8 @@ static int teardown(void **state) {
|
||||
(void) state; /* unused */
|
||||
|
||||
unlink(LIBSSH_ED25519_TESTKEY);
|
||||
unlink(LIBSSH_ED25519_TESTKEY_PASSPHRASE);
|
||||
unlink(LIBSSH_ED25519_TESTKEY ".pub");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -274,6 +280,43 @@ static void torture_pki_ed25519_write_privkey(void **state)
|
||||
|
||||
ssh_key_free(origkey);
|
||||
ssh_key_free(privkey);
|
||||
|
||||
/* Test with passphrase */
|
||||
rc = ssh_pki_import_privkey_file(LIBSSH_ED25519_TESTKEY_PASSPHRASE,
|
||||
torture_get_testkey_passphrase(),
|
||||
NULL,
|
||||
NULL,
|
||||
&origkey);
|
||||
assert_true(rc == 0);
|
||||
|
||||
unlink(LIBSSH_ED25519_TESTKEY_PASSPHRASE);
|
||||
rc = ssh_pki_export_privkey_file(origkey,
|
||||
torture_get_testkey_passphrase(),
|
||||
NULL,
|
||||
NULL,
|
||||
LIBSSH_ED25519_TESTKEY_PASSPHRASE);
|
||||
assert_true(rc == 0);
|
||||
|
||||
/* Test with invalid passphrase */
|
||||
rc = ssh_pki_import_privkey_file(LIBSSH_ED25519_TESTKEY_PASSPHRASE,
|
||||
"invalid secret",
|
||||
NULL,
|
||||
NULL,
|
||||
&privkey);
|
||||
assert_true(rc == SSH_ERROR);
|
||||
|
||||
rc = ssh_pki_import_privkey_file(LIBSSH_ED25519_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);
|
||||
}
|
||||
|
||||
static void torture_pki_ed25519_sign(void **state){
|
||||
|
Загрузка…
Ссылка в новой задаче
Block a user