aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAris Adamantiadis <aris@0xbadc0de.be>2015-01-21 14:21:52 +0100
committerAndreas Schneider <asn@cryptomilk.org>2015-02-02 14:45:52 +0100
commitb76d37b341c48ef9865183d6fe287bbf4029ccb6 (patch)
treea0a694a711b1093116815ed2e27f860ff1f2868c
parent423fa6818bcce491d4e4dafc8e5306905f5e5255 (diff)
downloadlibssh-b76d37b341c48ef9865183d6fe287bbf4029ccb6.tar.gz
libssh-b76d37b341c48ef9865183d6fe287bbf4029ccb6.tar.xz
libssh-b76d37b341c48ef9865183d6fe287bbf4029ccb6.zip
tests: Add ed25519 encrypted keys import
Signed-off-by: Aris Adamantiadis <aris@0xbadc0de.be> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
-rw-r--r--tests/torture.c18
-rw-r--r--tests/unittests/torture_pki.c18
2 files changed, 35 insertions, 1 deletions
diff --git a/tests/torture.c b/tests/torture.c
index b63826a7..bb7c926a 100644
--- a/tests/torture.c
+++ b/tests/torture.c
@@ -209,6 +209,16 @@ static const char torture_ed25519_testkey_pub[]=
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBWWnxuCYiOyvMYLtkgoEyEKlLV+klM+"
"BU6Nh3PmAiqX aris@kalix86";
+static const char torture_ed25519_testkey_pp[]=
+ "-----BEGIN OPENSSH PRIVATE KEY-----\n"
+ "b3BlbnNzaC1rZXktdjEAAAAACmFlczI1Ni1jYmMAAAAGYmNyeXB0AAAAGAAAABB3FWpQcE\n"
+ "KHKq6PcjkxjmKzAAAAEAAAAAEAAAAzAAAAC3NzaC1lZDI1NTE5AAAAIOGFVuOyZBL0T+NR\n"
+ "C7qEV9qr6QiGhz2XSXrxuQoU84FgAAAAkBlOVfS5U7FxtBEtxfxQhZjrZAj2z9d4OfGRPl\n"
+ "ZfCnAJNEM3BZ3XCabsujhMkqEs9eptRfj41X6NA8aSFs5JYT+JFVfg470FKtpyUmAibMIo\n"
+ "JzI41zAncFd1x7bAgO5HBDe3xNsV159D+sXRkWB9Tzk0l4F8SZvInheIS7VSbqH7t1+yDB\n"
+ "Y3GsmYTDstmicanQ==\n"
+ "-----END OPENSSH PRIVATE KEY-----\n";
+
static int verbosity = 0;
#ifndef _WIN32
@@ -585,24 +595,30 @@ static const char *torture_get_testkey_internal(enum ssh_keytypes_e type,
if (bits == 521) {
if (pubkey) {
return torture_ecdsa521_testkey_pub;
+ } else if (with_passphrase) {
+ return NULL;
}
return torture_ecdsa521_testkey;
} else if (bits == 384) {
if (pubkey) {
return torture_ecdsa384_testkey_pub;
+ } else if (with_passphrase){
+ return NULL;
}
return torture_ecdsa384_testkey;
}
if (pubkey) {
return torture_ecdsa256_testkey_pub;
+ } else if (with_passphrase){
+ return NULL;
}
return torture_ecdsa256_testkey;
case SSH_KEYTYPE_ED25519:
if (pubkey) {
return torture_ed25519_testkey_pub;
} else if (with_passphrase) {
- return NULL;
+ return torture_ed25519_testkey_pp;
}
return torture_ed25519_testkey;
case SSH_KEYTYPE_RSA1:
diff --git a/tests/unittests/torture_pki.c b/tests/unittests/torture_pki.c
index bd2c942f..a99f2084 100644
--- a/tests/unittests/torture_pki.c
+++ b/tests/unittests/torture_pki.c
@@ -350,6 +350,24 @@ static void torture_pki_import_privkey_base64_passphrase(void **state) {
assert_true(rc == -1);
#endif
+ /* same for ED25519 */
+
+ rc = ssh_pki_import_privkey_base64(torture_get_testkey(SSH_KEYTYPE_ED25519, 0, 1),
+ passphrase,
+ NULL,
+ NULL,
+ &key);
+ assert_true(rc == 0);
+ ssh_key_free(key);
+
+ /* test if it returns -1 if passphrase is wrong */
+ rc = ssh_pki_import_privkey_base64(torture_get_testkey(SSH_KEYTYPE_ED25519, 0, 1),
+ "wrong passphrase !!",
+ NULL,
+ NULL,
+ &key);
+ assert_true(rc == -1);
+
}
static void torture_pki_import_privkey_base64_ed25519(void **state){