1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-07-29 13:01:13 +03:00

tests: Call disable_secmem() before ssh_init()

ssh_init calls ssh_crypto_init() which initializes the secure memory of
gcrypt. Those should actually be just called by the application once.
Lets do that.

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
This commit is contained in:
Andreas Schneider
2024-12-03 13:40:32 +01:00
parent 867630750c
commit 2966a4a33c

View File

@ -133,10 +133,9 @@ static int teardown(void **state) {
return 0;
}
static int disable_secmem(void **state)
static void
disable_secmem(void)
{
(void) state; /*unused*/
#if defined(HAVE_LIBGCRYPT)
/* gcrypt currently is configured to use only 4kB of locked secmem
* (see ssh_crypto_init() in src/libcrypt.c)
@ -145,23 +144,10 @@ static int disable_secmem(void **state)
* To avoid the expected warning, disable the secure memory.
* */
gcry_control (GCRYCTL_SUSPEND_SECMEM_WARN);
gcry_control(GCRYCTL_SUSPEND_SECMEM_WARN);
gcry_control(GCRYCTL_DISABLE_SECMEM);
gcry_control(GCRYCTL_INITIALIZATION_FINISHED, 0);
#endif
return 0;
}
static int enable_secmem(void **state)
{
(void) state; /*unused*/
#if defined(HAVE_LIBGCRYPT)
/* Re-enable secmem */
gcry_control(GCRYCTL_INIT_SECMEM, 4096);
gcry_control(GCRYCTL_RESUME_SECMEM_WARN);
#endif
return 0;
}
static void *thread_pki_rsa_import_pubkey_file(void *threadid)
@ -784,9 +770,7 @@ int torture_run_tests(void)
cmocka_unit_test_setup_teardown(torture_pki_rsa_duplicate_key,
setup_rsa_key,
teardown),
cmocka_unit_test_setup_teardown(torture_pki_rsa_generate_key,
disable_secmem,
enable_secmem),
cmocka_unit_test(torture_pki_rsa_generate_key),
cmocka_unit_test_setup_teardown(torture_mixed, setup_rsa_key, teardown),
};
@ -802,6 +786,7 @@ int torture_run_tests(void)
* If the library is statically linked, ssh_init() is not called
* automatically
*/
disable_secmem();
ssh_init();
torture_filter_tests(tests);
rc = cmocka_run_group_tests(tests, NULL, NULL);