summaryrefslogtreecommitdiffstats
path: root/libssh/tests/unittests/torture_pki.c
diff options
context:
space:
mode:
Diffstat (limited to 'libssh/tests/unittests/torture_pki.c')
-rw-r--r--libssh/tests/unittests/torture_pki.c517
1 files changed, 408 insertions, 109 deletions
diff --git a/libssh/tests/unittests/torture_pki.c b/libssh/tests/unittests/torture_pki.c
index 7324177e..efcbb01b 100644
--- a/libssh/tests/unittests/torture_pki.c
+++ b/libssh/tests/unittests/torture_pki.c
@@ -8,64 +8,65 @@
#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";
static void setup_rsa_key(void **state) {
- int rc;
-
(void) state; /* unused */
unlink(LIBSSH_RSA_TESTKEY);
unlink(LIBSSH_RSA_TESTKEY ".pub");
- rc = system("ssh-keygen -t rsa -q -N \"\" -f " LIBSSH_RSA_TESTKEY);
- assert_true(rc == 0);
+ torture_write_file(LIBSSH_RSA_TESTKEY,
+ torture_get_testkey(SSH_KEYTYPE_RSA, 0, 0));
+ torture_write_file(LIBSSH_RSA_TESTKEY ".pub",
+ torture_get_testkey_pub(SSH_KEYTYPE_RSA, 0));
}
static void setup_dsa_key(void **state) {
- int rc;
-
(void) state; /* unused */
unlink(LIBSSH_DSA_TESTKEY);
unlink(LIBSSH_DSA_TESTKEY ".pub");
- rc = system("ssh-keygen -t dsa -q -N \"\" -f " LIBSSH_DSA_TESTKEY);
- assert_true(rc == 0);
+ torture_write_file(LIBSSH_DSA_TESTKEY,
+ torture_get_testkey(SSH_KEYTYPE_DSS, 0, 0));
+ torture_write_file(LIBSSH_DSA_TESTKEY ".pub",
+ torture_get_testkey_pub(SSH_KEYTYPE_DSS, 0));
}
#ifdef HAVE_OPENSSL_ECC
-static void setup_ecdsa_key(void **state) {
- int rc;
+static void setup_ecdsa_key(void **state, int ecdsa_bits) {
(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);
+ torture_write_file(LIBSSH_ECDSA_TESTKEY,
+ torture_get_testkey(SSH_KEYTYPE_ECDSA, ecdsa_bits, 0));
+ torture_write_file(LIBSSH_ECDSA_TESTKEY ".pub",
+ torture_get_testkey_pub(SSH_KEYTYPE_ECDSA, ecdsa_bits));
}
-#endif
-static void setup_both_keys(void **state) {
- (void) state; /* unused */
+static void setup_ecdsa_key_521(void **state) {
+ setup_ecdsa_key(state, 521);
+}
- setup_rsa_key(state);
- setup_dsa_key(state);
+static void setup_ecdsa_key_384(void **state) {
+ setup_ecdsa_key(state, 384);
}
-static void setup_both_keys_passphrase(void **state) {
- int rc;
+static void setup_ecdsa_key_256(void **state) {
+ setup_ecdsa_key(state, 256);
+}
+#endif
+static void setup_both_keys(void **state) {
(void) state; /* unused */
- rc = system("ssh-keygen -t rsa -q -N " LIBSSH_PASSPHRASE " -f " LIBSSH_RSA_TESTKEY);
- assert_true(rc == 0);
-
- rc = system("ssh-keygen -t dsa -q -N " LIBSSH_PASSPHRASE " -f " LIBSSH_DSA_TESTKEY);
- assert_true(rc == 0);
+ setup_rsa_key(state);
+ setup_dsa_key(state);
}
static void teardown(void **state) {
@@ -111,24 +112,40 @@ static char *read_file(const char *filename) {
static int torture_read_one_line(const char *filename, char *buffer, size_t len) {
FILE *fp;
- size_t rc;
+ size_t nmemb;
fp = fopen(filename, "r");
if (fp == NULL) {
return -1;
}
- rc = fread(buffer, len, 1, fp);
- if (rc != 0 || ferror(fp)) {
+ nmemb = fread(buffer, len - 2, 1, fp);
+ if (nmemb != 0 || ferror(fp)) {
fclose(fp);
return -1;
}
+ buffer[len - 1] = '\0';
fclose(fp);
return 0;
}
+/** @internal
+ * returns the character len of a public key string, omitting the comment part
+ */
+static int torture_pubkey_len(const char *pubkey){
+ const char *ptr;
+ ptr=strchr(pubkey, ' ');
+ if (ptr != NULL){
+ ptr = strchr(ptr + 1, ' ');
+ if (ptr != NULL){
+ return ptr - pubkey;
+ }
+ }
+ return 0;
+}
+
static void torture_pki_keytype(void **state) {
enum ssh_keytypes_e type;
const char *type_c;
@@ -167,7 +184,7 @@ static void torture_pki_import_privkey_base64_RSA(void **state) {
int rc;
char *key_str;
ssh_key key;
- const char *passphrase = LIBSSH_PASSPHRASE;
+ const char *passphrase = torture_get_testkey_passphrase();
enum ssh_keytypes_e type;
(void) state; /* unused */
@@ -190,60 +207,48 @@ static void torture_pki_import_privkey_base64_RSA(void **state) {
static void torture_pki_import_privkey_base64_NULL_key(void **state) {
int rc;
- char *key_str;
- ssh_key key;
- const char *passphrase = LIBSSH_PASSPHRASE;
+ const char *passphrase = torture_get_testkey_passphrase();
(void) state; /* unused */
- key_str = read_file(LIBSSH_RSA_TESTKEY);
- assert_true(key_str != NULL);
-
- key = ssh_key_new();
- assert_true(key != NULL);
-
/* test if it returns -1 if key is NULL */
- rc = ssh_pki_import_privkey_base64(key_str, passphrase, NULL, NULL, NULL);
+ rc = ssh_pki_import_privkey_base64(torture_get_testkey(SSH_KEYTYPE_RSA, 0, 0),
+ passphrase,
+ NULL,
+ NULL,
+ NULL);
assert_true(rc == -1);
- free(key_str);
- ssh_key_free(key);
}
static void torture_pki_import_privkey_base64_NULL_str(void **state) {
int rc;
- char *key_str;
ssh_key key = NULL;
- const char *passphrase = LIBSSH_PASSPHRASE;
+ const char *passphrase = torture_get_testkey_passphrase();
(void) state; /* unused */
- key_str = read_file(LIBSSH_RSA_TESTKEY);
- assert_true(key_str != NULL);
-
/* test if it returns -1 if key_str is NULL */
rc = ssh_pki_import_privkey_base64(NULL, passphrase, NULL, NULL, &key);
assert_true(rc == -1);
- free(key_str);
ssh_key_free(key);
}
static void torture_pki_import_privkey_base64_DSA(void **state) {
int rc;
- char *key_str;
ssh_key key;
- const char *passphrase = LIBSSH_PASSPHRASE;
+ const char *passphrase = torture_get_testkey_passphrase();
(void) state; /* unused */
- key_str = read_file(LIBSSH_DSA_TESTKEY);
- assert_true(key_str != NULL);
-
- rc = ssh_pki_import_privkey_base64(key_str, passphrase, NULL, NULL, &key);
+ rc = ssh_pki_import_privkey_base64(torture_get_testkey(SSH_KEYTYPE_DSS, 0, 0),
+ passphrase,
+ NULL,
+ NULL,
+ &key);
assert_true(rc == 0);
- free(key_str);
ssh_key_free(key);
}
@@ -252,7 +257,7 @@ static void torture_pki_import_privkey_base64_ECDSA(void **state) {
int rc;
char *key_str;
ssh_key key;
- const char *passphrase = LIBSSH_PASSPHRASE;
+ const char *passphrase = torture_get_testkey_passphrase();
(void) state; /* unused */
@@ -269,97 +274,110 @@ static void torture_pki_import_privkey_base64_ECDSA(void **state) {
static void torture_pki_import_privkey_base64_passphrase(void **state) {
int rc;
- char *key_str;
ssh_key key = NULL;
- const char *passphrase = LIBSSH_PASSPHRASE;
+ const char *passphrase = torture_get_testkey_passphrase();
(void) state; /* unused */
- key_str = read_file(LIBSSH_RSA_TESTKEY);
- assert_true(key_str != NULL);
- rc = ssh_pki_import_privkey_base64(key_str, passphrase, NULL, NULL, &key);
+ rc = ssh_pki_import_privkey_base64(torture_get_testkey(SSH_KEYTYPE_RSA, 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(key_str, "wrong passphrase !!", NULL,
- NULL, &key);
+ rc = ssh_pki_import_privkey_base64(torture_get_testkey(SSH_KEYTYPE_RSA, 0, 1),
+ "wrong passphrase !!",
+ NULL,
+ NULL,
+ &key);
assert_true(rc == -1);
#ifndef HAVE_LIBCRYPTO
/* test if it returns -1 if passphrase is NULL */
/* libcrypto asks for a passphrase, so skip this test */
- rc = ssh_pki_import_privkey_base64(key_str, NULL, NULL, NULL, &key);
+ rc = ssh_pki_import_privkey_base64(torture_get_testkey(SSH_KEYTYPE_RSA, 0, 1),
+ NULL,
+ NULL,
+ NULL,
+ &key);
assert_true(rc == -1);
#endif
- free(key_str);
-
/* same for DSA */
- key_str = read_file(LIBSSH_DSA_TESTKEY);
- assert_true(key_str != NULL);
- rc = ssh_pki_import_privkey_base64(key_str, passphrase, NULL, NULL, &key);
+ rc = ssh_pki_import_privkey_base64(torture_get_testkey(SSH_KEYTYPE_DSS, 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(key_str, "wrong passphrase !!", NULL, NULL, &key);
+ rc = ssh_pki_import_privkey_base64(torture_get_testkey(SSH_KEYTYPE_DSS, 0, 1),
+ "wrong passphrase !!",
+ NULL,
+ NULL,
+ &key);
assert_true(rc == -1);
#ifndef HAVE_LIBCRYPTO
/* test if it returns -1 if passphrase is NULL */
/* libcrypto asks for a passphrase, so skip this test */
- rc = ssh_pki_import_privkey_base64(key_str, NULL, NULL, NULL, &key);
+ rc = ssh_pki_import_privkey_base64(torture_get_testkey(SSH_KEYTYPE_DSS, 0, 1),
+ NULL,
+ NULL,
+ NULL,
+ &key);
assert_true(rc == -1);
#endif
- free(key_str);
}
static void torture_pki_pki_publickey_from_privatekey_RSA(void **state) {
int rc;
- char *key_str;
ssh_key key;
ssh_key pubkey;
const char *passphrase = NULL;
(void) state; /* unused */
- key_str = read_file(LIBSSH_RSA_TESTKEY);
- assert_true(key_str != NULL);
-
- rc = ssh_pki_import_privkey_base64(key_str, passphrase, NULL, NULL, &key);
+ rc = ssh_pki_import_privkey_base64(torture_get_testkey(SSH_KEYTYPE_RSA, 0, 0),
+ passphrase,
+ NULL,
+ NULL,
+ &key);
assert_true(rc == 0);
rc = ssh_pki_export_privkey_to_pubkey(key, &pubkey);
assert_true(rc == SSH_OK);
- free(key_str);
ssh_key_free(key);
ssh_key_free(pubkey);
}
static void torture_pki_pki_publickey_from_privatekey_DSA(void **state) {
int rc;
- char *key_str;
ssh_key key;
ssh_key pubkey;
const char *passphrase = NULL;
(void) state; /* unused */
- key_str = read_file(LIBSSH_DSA_TESTKEY);
- assert_true(key_str != NULL);
-
- rc = ssh_pki_import_privkey_base64(key_str, passphrase, NULL, NULL, &key);
+ rc = ssh_pki_import_privkey_base64(torture_get_testkey(SSH_KEYTYPE_DSS, 0, 0),
+ passphrase,
+ NULL,
+ NULL,
+ &key);
assert_true(rc == 0);
rc = ssh_pki_export_privkey_to_pubkey(key, &pubkey);
assert_true(rc == SSH_OK);
- free(key_str);
ssh_key_free(key);
ssh_key_free(pubkey);
}
@@ -399,7 +417,7 @@ static void torture_pki_publickey_dsa_base64(void **state)
(void) state; /* unused */
- key_buf = read_file(LIBSSH_DSA_TESTKEY ".pub");
+ key_buf = strdup(torture_get_testkey_pub(SSH_KEYTYPE_DSS, 0));
assert_true(key_buf != NULL);
q = p = key_buf;
@@ -475,7 +493,7 @@ static void torture_pki_publickey_rsa_base64(void **state)
(void) state; /* unused */
- key_buf = read_file(LIBSSH_RSA_TESTKEY ".pub");
+ key_buf = strdup(torture_get_testkey_pub(SSH_KEYTYPE_RSA, 0));
assert_true(key_buf != NULL);
q = p = key_buf;
@@ -504,19 +522,14 @@ static void torture_pki_publickey_rsa_base64(void **state)
}
static void torture_generate_pubkey_from_privkey_rsa(void **state) {
- char pubkey_original[4096] = {0};
char pubkey_generated[4096] = {0};
ssh_key privkey;
ssh_key pubkey;
int rc;
+ int len;
(void) state; /* unused */
- rc = torture_read_one_line(LIBSSH_RSA_TESTKEY ".pub",
- pubkey_original,
- sizeof(pubkey_original));
- assert_true(rc == 0);
-
/* remove the public key, generate it from the private key and write it. */
unlink(LIBSSH_RSA_TESTKEY ".pub");
@@ -538,26 +551,24 @@ static void torture_generate_pubkey_from_privkey_rsa(void **state) {
sizeof(pubkey_generated));
assert_true(rc == 0);
- assert_string_equal(pubkey_original, pubkey_generated);
+ len = torture_pubkey_len(torture_get_testkey_pub(SSH_KEYTYPE_RSA, 0));
+ assert_memory_equal(torture_get_testkey_pub(SSH_KEYTYPE_RSA, 0),
+ pubkey_generated,
+ len);
ssh_key_free(privkey);
ssh_key_free(pubkey);
}
static void torture_generate_pubkey_from_privkey_dsa(void **state) {
- char pubkey_original[4096] = {0};
char pubkey_generated[4096] = {0};
ssh_key privkey;
ssh_key pubkey;
+ int len;
int rc;
(void) state; /* unused */
- rc = torture_read_one_line(LIBSSH_DSA_TESTKEY ".pub",
- pubkey_original,
- sizeof(pubkey_original));
- assert_true(rc == 0);
-
/* remove the public key, generate it from the private key and write it. */
unlink(LIBSSH_DSA_TESTKEY ".pub");
@@ -579,7 +590,10 @@ static void torture_generate_pubkey_from_privkey_dsa(void **state) {
sizeof(pubkey_generated));
assert_true(rc == 0);
- assert_string_equal(pubkey_original, pubkey_generated);
+ len = torture_pubkey_len(torture_get_testkey_pub(SSH_KEYTYPE_DSS, 0));
+ assert_memory_equal(torture_get_testkey_pub(SSH_KEYTYPE_DSS, 0),
+ pubkey_generated,
+ len);
ssh_key_free(privkey);
ssh_key_free(pubkey);
@@ -592,6 +606,7 @@ static void torture_generate_pubkey_from_privkey_ecdsa(void **state) {
ssh_key privkey;
ssh_key pubkey;
int rc;
+ int len;
(void) state; /* unused */
@@ -620,8 +635,8 @@ static void torture_generate_pubkey_from_privkey_ecdsa(void **state) {
pubkey_generated,
sizeof(pubkey_generated));
assert_true(rc == 0);
-
- assert_string_equal(pubkey_original, pubkey_generated);
+ len = torture_pubkey_len(pubkey_original);
+ assert_int_equal(strncmp(pubkey_original, pubkey_generated, len), 0);
ssh_key_free(privkey);
ssh_key_free(pubkey);
@@ -766,6 +781,39 @@ static void torture_pki_duplicate_key_ecdsa(void **state)
ssh_string_free_char(b64_key);
ssh_string_free_char(b64_key_gen);
}
+
+/* Test case for bug #147: Private ECDSA key duplication did not carry
+ * over parts of the key that then caused subsequent key demotion to
+ * fail.
+ */
+static void torture_pki_ecdsa_duplicate_then_demote(void **state)
+{
+ ssh_key pubkey;
+ ssh_key privkey;
+ ssh_key privkey_dup;
+ int rc;
+
+ (void) state;
+
+ rc = ssh_pki_import_privkey_file(LIBSSH_ECDSA_TESTKEY,
+ NULL,
+ NULL,
+ NULL,
+ &privkey);
+ assert_true(rc == 0);
+
+ privkey_dup = ssh_key_dup(privkey);
+ assert_true(privkey_dup != NULL);
+ assert_int_equal(privkey->ecdsa_nid, privkey_dup->ecdsa_nid);
+
+ rc = ssh_pki_export_privkey_to_pubkey(privkey_dup, &pubkey);
+ assert_true(rc == 0);
+ assert_int_equal(pubkey->ecdsa_nid, privkey->ecdsa_nid);
+
+ ssh_key_free(pubkey);
+ ssh_key_free(privkey);
+ ssh_key_free(privkey_dup);
+}
#endif
static void torture_pki_generate_key_rsa(void **state)
@@ -906,6 +954,9 @@ static void torture_pki_generate_key_ecdsa(void **state)
int rc;
ssh_key key;
ssh_signature sign;
+ enum ssh_keytypes_e type = SSH_KEYTYPE_UNKNOWN;
+ const char *type_char = NULL;
+ const char *etype_char = NULL;
ssh_session session=ssh_new();
(void) state;
@@ -916,6 +967,13 @@ static void torture_pki_generate_key_ecdsa(void **state)
assert_true(sign != NULL);
rc = pki_signature_verify(session,sign,key,HASH,20);
assert_true(rc == SSH_OK);
+ type = ssh_key_type(key);
+ assert_true(type == SSH_KEYTYPE_ECDSA);
+ type_char = ssh_key_type_to_char(type);
+ assert_true(strcmp(type_char, "ssh-ecdsa") == 0);
+ etype_char = ssh_pki_key_ecdsa_name(key);
+ assert_true(strcmp(etype_char, "ecdsa-sha2-nistp256") == 0);
+
ssh_signature_free(sign);
ssh_key_free(key);
key=NULL;
@@ -927,6 +985,13 @@ static void torture_pki_generate_key_ecdsa(void **state)
assert_true(sign != NULL);
rc = pki_signature_verify(session,sign,key,HASH,20);
assert_true(rc == SSH_OK);
+ type = ssh_key_type(key);
+ assert_true(type == SSH_KEYTYPE_ECDSA);
+ type_char = ssh_key_type_to_char(type);
+ assert_true(strcmp(type_char, "ssh-ecdsa") == 0);
+ etype_char =ssh_pki_key_ecdsa_name(key);
+ assert_true(strcmp(etype_char, "ecdsa-sha2-nistp384") == 0);
+
ssh_signature_free(sign);
ssh_key_free(key);
key=NULL;
@@ -938,6 +1003,13 @@ static void torture_pki_generate_key_ecdsa(void **state)
assert_true(sign != NULL);
rc = pki_signature_verify(session,sign,key,HASH,20);
assert_true(rc == SSH_OK);
+ type = ssh_key_type(key);
+ assert_true(type == SSH_KEYTYPE_ECDSA);
+ type_char = ssh_key_type_to_char(type);
+ assert_true(strcmp(type_char, "ssh-ecdsa") == 0);
+ etype_char =ssh_pki_key_ecdsa_name(key);
+ assert_true(strcmp(etype_char, "ecdsa-sha2-nistp521") == 0);
+
ssh_signature_free(sign);
ssh_key_free(key);
key=NULL;
@@ -946,6 +1018,166 @@ static void torture_pki_generate_key_ecdsa(void **state)
}
#endif
+#ifdef HAVE_LIBCRYPTO
+static void torture_pki_write_privkey_rsa(void **state)
+{
+ ssh_key origkey;
+ ssh_key privkey;
+ int rc;
+
+ (void) state; /* unused */
+
+ ssh_set_log_level(5);
+
+ rc = ssh_pki_import_privkey_file(LIBSSH_RSA_TESTKEY,
+ NULL,
+ NULL,
+ NULL,
+ &origkey);
+ assert_true(rc == 0);
+
+ unlink(LIBSSH_RSA_TESTKEY);
+
+ rc = ssh_pki_export_privkey_file(origkey,
+ "",
+ NULL,
+ NULL,
+ LIBSSH_RSA_TESTKEY);
+ assert_true(rc == 0);
+
+ rc = ssh_pki_import_privkey_file(LIBSSH_RSA_TESTKEY,
+ NULL,
+ 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_write_privkey_dsa(void **state)
+{
+ ssh_key origkey;
+ ssh_key privkey;
+ int rc;
+
+ (void) state; /* unused */
+
+ ssh_set_log_level(5);
+
+ rc = ssh_pki_import_privkey_file(LIBSSH_DSA_TESTKEY,
+ NULL,
+ NULL,
+ NULL,
+ &origkey);
+ assert_true(rc == 0);
+
+ unlink(LIBSSH_DSA_TESTKEY);
+
+ rc = ssh_pki_export_privkey_file(origkey,
+ "",
+ NULL,
+ NULL,
+ LIBSSH_DSA_TESTKEY);
+ assert_true(rc == 0);
+
+ rc = ssh_pki_import_privkey_file(LIBSSH_DSA_TESTKEY,
+ NULL,
+ 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);
+}
+
+#ifdef HAVE_ECC
+static void torture_pki_write_privkey_ecdsa(void **state)
+{
+ ssh_key origkey;
+ ssh_key privkey;
+ int rc;
+
+ (void) state; /* unused */
+
+ ssh_set_log_level(5);
+
+ rc = ssh_pki_import_privkey_file(LIBSSH_ECDSA_TESTKEY,
+ NULL,
+ NULL,
+ NULL,
+ &origkey);
+ assert_true(rc == 0);
+
+ unlink(LIBSSH_ECDSA_TESTKEY);
+
+ rc = ssh_pki_export_privkey_file(origkey,
+ "",
+ NULL,
+ NULL,
+ LIBSSH_ECDSA_TESTKEY);
+ assert_true(rc == 0);
+
+ rc = ssh_pki_import_privkey_file(LIBSSH_ECDSA_TESTKEY,
+ NULL,
+ 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
+#endif /* HAVE_LIBCRYPTO */
+
+#ifdef HAVE_ECC
+static void torture_pki_ecdsa_name(void **state, const char *expected_name)
+{
+ int rc;
+ ssh_key key;
+ const char *etype_char = NULL;
+
+ (void) state; /* unused */
+
+ ssh_set_log_level(5);
+
+ rc = ssh_pki_import_privkey_file(LIBSSH_ECDSA_TESTKEY, NULL, NULL, NULL, &key);
+ assert_true(rc == 0);
+
+ etype_char =ssh_pki_key_ecdsa_name(key);
+ assert_true(strcmp(etype_char, expected_name) == 0);
+
+ ssh_key_free(key);
+}
+
+static void torture_pki_ecdsa_name256(void **state)
+{
+ torture_pki_ecdsa_name(state, "ecdsa-sha2-nistp256");
+}
+
+static void torture_pki_ecdsa_name384(void **state)
+{
+ torture_pki_ecdsa_name(state, "ecdsa-sha2-nistp384");
+}
+
+static void torture_pki_ecdsa_name521(void **state)
+{
+ torture_pki_ecdsa_name(state, "ecdsa-sha2-nistp521");
+}
+#endif
+
int torture_run_tests(void) {
int rc;
const UnitTest tests[] = {
@@ -968,12 +1200,16 @@ int torture_run_tests(void) {
teardown),
#ifdef HAVE_ECC
unit_test_setup_teardown(torture_pki_import_privkey_base64_ECDSA,
- setup_ecdsa_key,
+ setup_ecdsa_key_256,
teardown),
-#endif
- unit_test_setup_teardown(torture_pki_import_privkey_base64_passphrase,
- setup_both_keys_passphrase,
+ unit_test_setup_teardown(torture_pki_import_privkey_base64_ECDSA,
+ setup_ecdsa_key_384,
+ teardown),
+ unit_test_setup_teardown(torture_pki_import_privkey_base64_ECDSA,
+ setup_ecdsa_key_521,
teardown),
+#endif
+ unit_test(torture_pki_import_privkey_base64_passphrase),
/* ssh_pki_export_privkey_to_pubkey */
unit_test_setup_teardown(torture_pki_pki_publickey_from_privatekey_RSA,
setup_rsa_key,
@@ -983,7 +1219,22 @@ int torture_run_tests(void) {
teardown),
#ifdef HAVE_ECC
unit_test_setup_teardown(torture_pki_publickey_from_privatekey_ECDSA,
- setup_ecdsa_key,
+ setup_ecdsa_key_256,
+ teardown),
+ unit_test_setup_teardown(torture_pki_publickey_from_privatekey_ECDSA,
+ setup_ecdsa_key_384,
+ teardown),
+ unit_test_setup_teardown(torture_pki_publickey_from_privatekey_ECDSA,
+ setup_ecdsa_key_521,
+ teardown),
+ unit_test_setup_teardown(torture_pki_ecdsa_duplicate_then_demote,
+ setup_ecdsa_key_256,
+ teardown),
+ unit_test_setup_teardown(torture_pki_ecdsa_duplicate_then_demote,
+ setup_ecdsa_key_384,
+ teardown),
+ unit_test_setup_teardown(torture_pki_ecdsa_duplicate_then_demote,
+ setup_ecdsa_key_521,
teardown),
#endif
/* public key */
@@ -995,7 +1246,13 @@ int torture_run_tests(void) {
teardown),
#ifdef HAVE_ECC
unit_test_setup_teardown(torture_pki_publickey_ecdsa_base64,
- setup_ecdsa_key,
+ setup_ecdsa_key_256,
+ teardown),
+ unit_test_setup_teardown(torture_pki_publickey_ecdsa_base64,
+ setup_ecdsa_key_384,
+ teardown),
+ unit_test_setup_teardown(torture_pki_publickey_ecdsa_base64,
+ setup_ecdsa_key_521,
teardown),
#endif
@@ -1007,7 +1264,13 @@ int torture_run_tests(void) {
teardown),
#ifdef HAVE_ECC
unit_test_setup_teardown(torture_generate_pubkey_from_privkey_ecdsa,
- setup_ecdsa_key,
+ setup_ecdsa_key_256,
+ teardown),
+ unit_test_setup_teardown(torture_generate_pubkey_from_privkey_ecdsa,
+ setup_ecdsa_key_384,
+ teardown),
+ unit_test_setup_teardown(torture_generate_pubkey_from_privkey_ecdsa,
+ setup_ecdsa_key_521,
teardown),
#endif
@@ -1019,7 +1282,13 @@ int torture_run_tests(void) {
teardown),
#ifdef HAVE_ECC
unit_test_setup_teardown(torture_pki_duplicate_key_ecdsa,
- setup_ecdsa_key,
+ setup_ecdsa_key_256,
+ teardown),
+ unit_test_setup_teardown(torture_pki_duplicate_key_ecdsa,
+ setup_ecdsa_key_384,
+ teardown),
+ unit_test_setup_teardown(torture_pki_duplicate_key_ecdsa,
+ setup_ecdsa_key_521,
teardown),
#endif
unit_test(torture_pki_generate_key_rsa),
@@ -1028,6 +1297,36 @@ int torture_run_tests(void) {
#ifdef HAVE_ECC
unit_test(torture_pki_generate_key_ecdsa),
#endif
+#ifdef HAVE_LIBCRYPTO
+ unit_test_setup_teardown(torture_pki_write_privkey_rsa,
+ setup_rsa_key,
+ teardown),
+ unit_test_setup_teardown(torture_pki_write_privkey_dsa,
+ setup_dsa_key,
+ teardown),
+#ifdef HAVE_ECC
+ unit_test_setup_teardown(torture_pki_write_privkey_ecdsa,
+ setup_ecdsa_key_256,
+ teardown),
+ unit_test_setup_teardown(torture_pki_write_privkey_ecdsa,
+ setup_ecdsa_key_384,
+ teardown),
+ unit_test_setup_teardown(torture_pki_write_privkey_ecdsa,
+ setup_ecdsa_key_521,
+ teardown),
+#endif
+#endif /* HAVE_LIBCRYPTO */
+#ifdef HAVE_ECC
+ unit_test_setup_teardown(torture_pki_ecdsa_name256,
+ setup_ecdsa_key_256,
+ teardown),
+ unit_test_setup_teardown(torture_pki_ecdsa_name384,
+ setup_ecdsa_key_384,
+ teardown),
+ unit_test_setup_teardown(torture_pki_ecdsa_name521,
+ setup_ecdsa_key_521,
+ teardown),
+#endif
};
(void)setup_both_keys;