aboutsummaryrefslogtreecommitdiff
path: root/tests/unittests
diff options
context:
space:
mode:
authorJakub Jelen <jjelen@redhat.com>2019-06-19 15:09:00 +0200
committerJakub Jelen <jjelen@redhat.com>2019-06-19 18:01:36 +0200
commitd5095a55b99198d7fa2fc4b8f1a1ca587b50ce9a (patch)
tree7e911d2f8b2f4fbc315c49fd56a509444acc5d5c /tests/unittests
parentd627cba47610f68afc4df54b683fc73d2b43a67a (diff)
downloadlibssh-d5095a55b99198d7fa2fc4b8f1a1ca587b50ce9a.tar.gz
libssh-d5095a55b99198d7fa2fc4b8f1a1ca587b50ce9a.tar.xz
libssh-d5095a55b99198d7fa2fc4b8f1a1ca587b50ce9a.zip
tests: Add reproducer for T76
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
Diffstat (limited to 'tests/unittests')
-rw-r--r--tests/unittests/torture_pki_dsa.c34
-rw-r--r--tests/unittests/torture_pki_ecdsa.c40
-rw-r--r--tests/unittests/torture_pki_rsa.c41
3 files changed, 115 insertions, 0 deletions
diff --git a/tests/unittests/torture_pki_dsa.c b/tests/unittests/torture_pki_dsa.c
index f1fd9bf9..bb86c513 100644
--- a/tests/unittests/torture_pki_dsa.c
+++ b/tests/unittests/torture_pki_dsa.c
@@ -168,6 +168,37 @@ static void torture_pki_dsa_import_privkey_base64(void **state)
SSH_KEY_FREE(key);
}
+static void torture_pki_dsa_import_privkey_base64_comment(void **state)
+{
+ int rc, file_str_len;
+ ssh_key key = NULL;
+ const char *passphrase = torture_get_testkey_passphrase();
+ const char *comment_str = "#this is line-comment\n#this is another\n";
+ const char *key_str = NULL;
+ char *file_str = NULL;
+
+ (void) state; /* unused */
+
+ key_str = torture_get_testkey(SSH_KEYTYPE_DSS, 0);
+ assert_non_null(key_str);
+
+ file_str_len = strlen(comment_str) + strlen(key_str) + 1;
+ file_str = malloc(file_str_len);
+ assert_non_null(file_str);
+ rc = snprintf(file_str, file_str_len, "%s%s", comment_str, key_str);
+ assert_int_equal(rc, file_str_len - 1);
+
+ rc = ssh_pki_import_privkey_base64(file_str,
+ passphrase,
+ NULL,
+ NULL,
+ &key);
+ assert_true(rc == 0);
+
+ free(file_str);
+ SSH_KEY_FREE(key);
+}
+
static int test_sign_verify_data(ssh_key key,
enum ssh_digest_e hash_type,
const unsigned char *input,
@@ -833,6 +864,9 @@ int torture_run_tests(void)
cmocka_unit_test_setup_teardown(torture_pki_dsa_import_privkey_base64,
setup_dsa_key,
teardown),
+ cmocka_unit_test_setup_teardown(torture_pki_dsa_import_privkey_base64_comment,
+ setup_dsa_key,
+ teardown),
cmocka_unit_test_setup_teardown(torture_pki_dsa_import_privkey_base64,
setup_openssh_dsa_key,
teardown),
diff --git a/tests/unittests/torture_pki_ecdsa.c b/tests/unittests/torture_pki_ecdsa.c
index 959c714e..13b2a895 100644
--- a/tests/unittests/torture_pki_ecdsa.c
+++ b/tests/unittests/torture_pki_ecdsa.c
@@ -241,6 +241,37 @@ static void torture_pki_ecdsa_import_privkey_base64(void **state)
SSH_KEY_FREE(key);
}
+static void torture_pki_ecdsa_import_privkey_base64_comment(void **state)
+{
+ int rc, file_str_len;
+ const char *comment_str = "#this is line-comment\n#this is another\n";
+ char *key_str = NULL, *file_str = NULL;
+ ssh_key key = NULL;
+ const char *passphrase = torture_get_testkey_passphrase();
+
+ (void) state; /* unused */
+
+ key_str = torture_pki_read_file(LIBSSH_ECDSA_TESTKEY);
+ assert_non_null(key_str);
+
+ file_str_len = strlen(comment_str) + strlen(key_str) + 1;
+ file_str = malloc(file_str_len);
+ assert_non_null(file_str);
+ rc = snprintf(file_str, file_str_len, "%s%s", comment_str, key_str);
+ assert_int_equal(rc, file_str_len - 1);
+
+ rc = ssh_pki_import_privkey_base64(file_str, passphrase, NULL, NULL, &key);
+ assert_true(rc == 0);
+ assert_non_null(key);
+
+ rc = ssh_key_is_private(key);
+ assert_true(rc == 1);
+
+ free(key_str);
+ free(file_str);
+ SSH_KEY_FREE(key);
+}
+
static void torture_pki_ecdsa_publickey_from_privatekey(void **state)
{
int rc;
@@ -904,6 +935,15 @@ int torture_run_tests(void) {
cmocka_unit_test_setup_teardown(torture_pki_ecdsa_import_privkey_base64,
setup_ecdsa_key_521,
teardown),
+ cmocka_unit_test_setup_teardown(torture_pki_ecdsa_import_privkey_base64_comment,
+ setup_ecdsa_key_256,
+ teardown),
+ cmocka_unit_test_setup_teardown(torture_pki_ecdsa_import_privkey_base64_comment,
+ setup_ecdsa_key_384,
+ teardown),
+ cmocka_unit_test_setup_teardown(torture_pki_ecdsa_import_privkey_base64_comment,
+ setup_ecdsa_key_521,
+ teardown),
cmocka_unit_test_setup_teardown(torture_pki_ecdsa_import_privkey_base64,
setup_openssh_ecdsa_key_256,
teardown),
diff --git a/tests/unittests/torture_pki_rsa.c b/tests/unittests/torture_pki_rsa.c
index 24094302..fd596b2f 100644
--- a/tests/unittests/torture_pki_rsa.c
+++ b/tests/unittests/torture_pki_rsa.c
@@ -213,6 +213,44 @@ static void torture_pki_rsa_import_privkey_base64(void **state)
SSH_KEY_FREE(key);
}
+static void torture_pki_rsa_import_privkey_base64_comment(void **state)
+{
+ int rc, file_str_len;
+ const char *comment_str = "#this is line-comment\n#this is another\n";
+ char *key_str = NULL, *file_str = NULL;
+ ssh_key key = NULL;
+ const char *passphrase = torture_get_testkey_passphrase();
+ enum ssh_keytypes_e type;
+
+ (void) state; /* unused */
+
+ key_str = torture_pki_read_file(LIBSSH_RSA_TESTKEY);
+ assert_non_null(key_str);
+
+ file_str_len = strlen(comment_str) + strlen(key_str) + 1;
+ file_str = malloc(file_str_len);
+ assert_non_null(file_str);
+ rc = snprintf(file_str, file_str_len, "%s%s", comment_str, key_str);
+ assert_int_equal(rc, file_str_len - 1);
+
+ rc = ssh_pki_import_privkey_base64(file_str, passphrase, NULL, NULL, &key);
+ assert_true(rc == 0);
+ assert_non_null(key);
+
+ type = ssh_key_type(key);
+ assert_true(type == SSH_KEYTYPE_RSA);
+
+ rc = ssh_key_is_private(key);
+ assert_true(rc == 1);
+
+ rc = ssh_key_is_public(key);
+ assert_true(rc == 1);
+
+ free(key_str);
+ free(file_str);
+ SSH_KEY_FREE(key);
+}
+
static void torture_pki_rsa_publickey_from_privatekey(void **state)
{
int rc;
@@ -877,6 +915,9 @@ int torture_run_tests(void) {
cmocka_unit_test_setup_teardown(torture_pki_rsa_import_privkey_base64,
setup_rsa_key,
teardown),
+ cmocka_unit_test_setup_teardown(torture_pki_rsa_import_privkey_base64_comment,
+ setup_rsa_key,
+ teardown),
cmocka_unit_test_setup_teardown(torture_pki_rsa_import_privkey_base64,
setup_openssh_rsa_key,
teardown),