tests: Try PEM files with leading white spaces
This adds a reproducer for T123. Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
Этот коммит содержится в:
родитель
88d777e678
Коммит
c03c9b88d1
@ -199,6 +199,37 @@ static void torture_pki_dsa_import_privkey_base64_comment(void **state)
|
|||||||
SSH_KEY_FREE(key);
|
SSH_KEY_FREE(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void torture_pki_dsa_import_privkey_base64_whitespace(void **state)
|
||||||
|
{
|
||||||
|
int rc, file_str_len;
|
||||||
|
ssh_key key = NULL;
|
||||||
|
const char *passphrase = torture_get_testkey_passphrase();
|
||||||
|
const char *whitespace_str = " \n\t\t\t\t\t\n\n\n\n\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(whitespace_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", whitespace_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,
|
static int test_sign_verify_data(ssh_key key,
|
||||||
enum ssh_digest_e hash_type,
|
enum ssh_digest_e hash_type,
|
||||||
const unsigned char *input,
|
const unsigned char *input,
|
||||||
@ -867,6 +898,9 @@ int torture_run_tests(void)
|
|||||||
cmocka_unit_test_setup_teardown(torture_pki_dsa_import_privkey_base64_comment,
|
cmocka_unit_test_setup_teardown(torture_pki_dsa_import_privkey_base64_comment,
|
||||||
setup_dsa_key,
|
setup_dsa_key,
|
||||||
teardown),
|
teardown),
|
||||||
|
cmocka_unit_test_setup_teardown(torture_pki_dsa_import_privkey_base64_whitespace,
|
||||||
|
setup_dsa_key,
|
||||||
|
teardown),
|
||||||
cmocka_unit_test_setup_teardown(torture_pki_dsa_import_privkey_base64,
|
cmocka_unit_test_setup_teardown(torture_pki_dsa_import_privkey_base64,
|
||||||
setup_openssh_dsa_key,
|
setup_openssh_dsa_key,
|
||||||
teardown),
|
teardown),
|
||||||
|
@ -272,6 +272,38 @@ static void torture_pki_ecdsa_import_privkey_base64_comment(void **state)
|
|||||||
SSH_KEY_FREE(key);
|
SSH_KEY_FREE(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void torture_pki_ecdsa_import_privkey_base64_whitespace(void **state)
|
||||||
|
{
|
||||||
|
int rc, file_str_len;
|
||||||
|
const char *whitespace_str = " \n\t\t\t\t\t\n\n\n\n\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(whitespace_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", whitespace_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)
|
static void torture_pki_ecdsa_publickey_from_privatekey(void **state)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
@ -944,6 +976,15 @@ int torture_run_tests(void) {
|
|||||||
cmocka_unit_test_setup_teardown(torture_pki_ecdsa_import_privkey_base64_comment,
|
cmocka_unit_test_setup_teardown(torture_pki_ecdsa_import_privkey_base64_comment,
|
||||||
setup_ecdsa_key_521,
|
setup_ecdsa_key_521,
|
||||||
teardown),
|
teardown),
|
||||||
|
cmocka_unit_test_setup_teardown(torture_pki_ecdsa_import_privkey_base64_whitespace,
|
||||||
|
setup_ecdsa_key_521,
|
||||||
|
teardown),
|
||||||
|
cmocka_unit_test_setup_teardown(torture_pki_ecdsa_import_privkey_base64_whitespace,
|
||||||
|
setup_ecdsa_key_521,
|
||||||
|
teardown),
|
||||||
|
cmocka_unit_test_setup_teardown(torture_pki_ecdsa_import_privkey_base64_whitespace,
|
||||||
|
setup_ecdsa_key_521,
|
||||||
|
teardown),
|
||||||
cmocka_unit_test_setup_teardown(torture_pki_ecdsa_import_privkey_base64,
|
cmocka_unit_test_setup_teardown(torture_pki_ecdsa_import_privkey_base64,
|
||||||
setup_openssh_ecdsa_key_256,
|
setup_openssh_ecdsa_key_256,
|
||||||
teardown),
|
teardown),
|
||||||
|
@ -251,6 +251,44 @@ static void torture_pki_rsa_import_privkey_base64_comment(void **state)
|
|||||||
SSH_KEY_FREE(key);
|
SSH_KEY_FREE(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void torture_pki_rsa_import_privkey_base64_whitespace(void **state)
|
||||||
|
{
|
||||||
|
int rc, file_str_len;
|
||||||
|
const char *whitespace_str = " \n\t\t\t\t\t\n\n\n\n\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(whitespace_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", whitespace_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)
|
static void torture_pki_rsa_publickey_from_privatekey(void **state)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
@ -920,6 +958,9 @@ int torture_run_tests(void) {
|
|||||||
cmocka_unit_test_setup_teardown(torture_pki_rsa_import_privkey_base64_comment,
|
cmocka_unit_test_setup_teardown(torture_pki_rsa_import_privkey_base64_comment,
|
||||||
setup_rsa_key,
|
setup_rsa_key,
|
||||||
teardown),
|
teardown),
|
||||||
|
cmocka_unit_test_setup_teardown(torture_pki_rsa_import_privkey_base64_whitespace,
|
||||||
|
setup_rsa_key,
|
||||||
|
teardown),
|
||||||
cmocka_unit_test_setup_teardown(torture_pki_rsa_import_privkey_base64,
|
cmocka_unit_test_setup_teardown(torture_pki_rsa_import_privkey_base64,
|
||||||
setup_openssh_rsa_key,
|
setup_openssh_rsa_key,
|
||||||
teardown),
|
teardown),
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user