aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Jelen <jjelen@redhat.com>2018-09-13 13:46:45 +0200
committerAndreas Schneider <asn@cryptomilk.org>2018-09-18 09:53:49 +0200
commit39975fdd6d6f9baf030c024d587d617b14d67d1d (patch)
tree847712e4a4806bd34c4db8bea1ae7c84c3ea4b1d
parent1226de875b3bb419f8d0ad949156d6e1a2a153fa (diff)
downloadlibssh-39975fdd6d6f9baf030c024d587d617b14d67d1d.tar.gz
libssh-39975fdd6d6f9baf030c024d587d617b14d67d1d.tar.xz
libssh-39975fdd6d6f9baf030c024d587d617b14d67d1d.zip
tests: Verify we can read public key from OpenSSH container
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
-rw-r--r--tests/unittests/torture_pki_dsa.c36
-rw-r--r--tests/unittests/torture_pki_ecdsa.c48
-rw-r--r--tests/unittests/torture_pki_ed25519.c36
-rw-r--r--tests/unittests/torture_pki_rsa.c18
4 files changed, 138 insertions, 0 deletions
diff --git a/tests/unittests/torture_pki_dsa.c b/tests/unittests/torture_pki_dsa.c
index 6343f6da..6a5331ba 100644
--- a/tests/unittests/torture_pki_dsa.c
+++ b/tests/unittests/torture_pki_dsa.c
@@ -70,6 +70,36 @@ static int teardown_dsa_key(void **state)
return 0;
}
+static void torture_pki_dsa_import_pubkey_file(void **state)
+{
+ ssh_key pubkey = NULL;
+ int rc;
+
+ (void)state;
+
+ /* The key doesn't have the hostname as comment after the key */
+ rc = ssh_pki_import_pubkey_file(LIBSSH_DSA_TESTKEY ".pub", &pubkey);
+ assert_return_code(rc, errno);
+ assert_non_null(pubkey);
+
+ ssh_key_free(pubkey);
+}
+
+static void torture_pki_dsa_import_pubkey_from_openssh_privkey(void **state)
+{
+ ssh_key pubkey = NULL;
+ int rc;
+
+ (void)state;
+
+ /* The key doesn't have the hostname as comment after the key */
+ rc = ssh_pki_import_pubkey_file(LIBSSH_DSA_TESTKEY_PASSPHRASE, &pubkey);
+ assert_return_code(rc, errno);
+ assert_non_null(pubkey);
+
+ ssh_key_free(pubkey);
+}
+
static void torture_pki_dsa_import_privkey_base64(void **state)
{
int rc;
@@ -542,6 +572,12 @@ int torture_run_tests(void)
{
int rc;
struct CMUnitTest tests[] = {
+ cmocka_unit_test_setup_teardown(torture_pki_dsa_import_pubkey_file,
+ setup_dsa_key,
+ teardown_dsa_key),
+ cmocka_unit_test_setup_teardown(torture_pki_dsa_import_pubkey_from_openssh_privkey,
+ setup_openssh_dsa_key,
+ teardown_dsa_key),
cmocka_unit_test_setup_teardown(torture_pki_dsa_import_privkey_base64,
setup_dsa_key,
teardown_dsa_key),
diff --git a/tests/unittests/torture_pki_ecdsa.c b/tests/unittests/torture_pki_ecdsa.c
index 5c66d81a..2f2245ed 100644
--- a/tests/unittests/torture_pki_ecdsa.c
+++ b/tests/unittests/torture_pki_ecdsa.c
@@ -109,6 +109,36 @@ static int teardown(void **state)
return 0;
}
+static void torture_pki_ecdsa_import_pubkey_file(void **state)
+{
+ ssh_key pubkey = NULL;
+ int rc;
+
+ (void)state;
+
+ /* The key doesn't have the hostname as comment after the key */
+ rc = ssh_pki_import_pubkey_file(LIBSSH_ECDSA_TESTKEY ".pub", &pubkey);
+ assert_return_code(rc, errno);
+ assert_non_null(pubkey);
+
+ ssh_key_free(pubkey);
+}
+
+static void torture_pki_ecdsa_import_pubkey_from_openssh_privkey(void **state)
+{
+ ssh_key pubkey = NULL;
+ int rc;
+
+ (void)state;
+
+ /* The key doesn't have the hostname as comment after the key */
+ rc = ssh_pki_import_pubkey_file(LIBSSH_ECDSA_TESTKEY_PASSPHRASE, &pubkey);
+ assert_return_code(rc, errno);
+ assert_non_null(pubkey);
+
+ ssh_key_free(pubkey);
+}
+
static void torture_pki_ecdsa_import_privkey_base64(void **state)
{
int rc;
@@ -496,6 +526,24 @@ static void torture_pki_ecdsa_name521(void **state)
int torture_run_tests(void) {
int rc;
struct CMUnitTest tests[] = {
+ cmocka_unit_test_setup_teardown(torture_pki_ecdsa_import_pubkey_file,
+ setup_ecdsa_key_256,
+ teardown),
+ cmocka_unit_test_setup_teardown(torture_pki_ecdsa_import_pubkey_file,
+ setup_ecdsa_key_384,
+ teardown),
+ cmocka_unit_test_setup_teardown(torture_pki_ecdsa_import_pubkey_file,
+ setup_ecdsa_key_521,
+ teardown),
+ cmocka_unit_test_setup_teardown(torture_pki_ecdsa_import_pubkey_from_openssh_privkey,
+ setup_openssh_ecdsa_key_256,
+ teardown),
+ cmocka_unit_test_setup_teardown(torture_pki_ecdsa_import_pubkey_from_openssh_privkey,
+ setup_openssh_ecdsa_key_384,
+ teardown),
+ cmocka_unit_test_setup_teardown(torture_pki_ecdsa_import_pubkey_file,
+ setup_openssh_ecdsa_key_521,
+ teardown),
cmocka_unit_test_setup_teardown(torture_pki_ecdsa_import_privkey_base64,
setup_ecdsa_key_256,
teardown),
diff --git a/tests/unittests/torture_pki_ed25519.c b/tests/unittests/torture_pki_ed25519.c
index b21641b9..be3efbcd 100644
--- a/tests/unittests/torture_pki_ed25519.c
+++ b/tests/unittests/torture_pki_ed25519.c
@@ -50,6 +50,36 @@ static int teardown(void **state) {
return 0;
}
+static void torture_pki_ed25519_import_pubkey_file(void **state)
+{
+ ssh_key pubkey = NULL;
+ int rc;
+
+ (void)state;
+
+ /* The key doesn't have the hostname as comment after the key */
+ rc = ssh_pki_import_pubkey_file(LIBSSH_ED25519_TESTKEY ".pub", &pubkey);
+ assert_return_code(rc, errno);
+ assert_non_null(pubkey);
+
+ ssh_key_free(pubkey);
+}
+
+static void torture_pki_ed25519_import_pubkey_from_openssh_privkey(void **state)
+{
+ ssh_key pubkey = NULL;
+ int rc;
+
+ (void)state;
+
+ /* The key doesn't have the hostname as comment after the key */
+ rc = ssh_pki_import_pubkey_file(LIBSSH_ED25519_TESTKEY_PASSPHRASE, &pubkey);
+ assert_return_code(rc, errno);
+ assert_non_null(pubkey);
+
+ ssh_key_free(pubkey);
+}
+
static void torture_pki_ed25519_import_privkey_base64(void **state)
{
int rc;
@@ -531,6 +561,12 @@ static void torture_pki_ed25519_pubkey_dup(void **state)
int torture_run_tests(void) {
int rc;
const struct CMUnitTest tests[] = {
+ cmocka_unit_test_setup_teardown(torture_pki_ed25519_import_pubkey_file,
+ setup_ed25519_key,
+ teardown),
+ cmocka_unit_test_setup_teardown(torture_pki_ed25519_import_pubkey_from_openssh_privkey,
+ setup_ed25519_key,
+ teardown),
cmocka_unit_test_setup_teardown(torture_pki_ed25519_import_privkey_base64,
setup_ed25519_key,
teardown),
diff --git a/tests/unittests/torture_pki_rsa.c b/tests/unittests/torture_pki_rsa.c
index 9025495c..34f76040 100644
--- a/tests/unittests/torture_pki_rsa.c
+++ b/tests/unittests/torture_pki_rsa.c
@@ -87,6 +87,21 @@ static void torture_pki_rsa_import_pubkey_file(void **state)
ssh_key_free(pubkey);
}
+static void torture_pki_rsa_import_pubkey_from_openssh_privkey(void **state)
+{
+ ssh_key pubkey = NULL;
+ int rc;
+
+ (void)state;
+
+ /* The key doesn't have the hostname as comment after the key */
+ rc = ssh_pki_import_pubkey_file(LIBSSH_RSA_TESTKEY_PASSPHRASE, &pubkey);
+ assert_return_code(rc, errno);
+ assert_non_null(pubkey);
+
+ ssh_key_free(pubkey);
+}
+
static void torture_pki_rsa_import_privkey_base64_NULL_key(void **state)
{
int rc;
@@ -641,6 +656,9 @@ int torture_run_tests(void) {
cmocka_unit_test_setup_teardown(torture_pki_rsa_import_pubkey_file,
setup_rsa_key,
teardown),
+ cmocka_unit_test_setup_teardown(torture_pki_rsa_import_pubkey_from_openssh_privkey,
+ setup_rsa_openssh_key,
+ teardown),
cmocka_unit_test_setup_teardown(torture_pki_rsa_import_privkey_base64_NULL_key,
setup_rsa_key,
teardown),