From fe4011d07a58182dd1c8dcf8ccfb536c3accf9d8 Mon Sep 17 00:00:00 2001 From: Johannes Holland Date: Sun, 8 Oct 2023 11:45:47 +0200 Subject: [PATCH] tctildr: add libtss2-.so.0 and libtss2-.so to file loading The tctildr has a different file name than other tctis. Normal tctis: * libtss2-tcti-.so Tctildr: * libtss2-tctildr.so Enable loading the tctildr tcti module. Signed-off-by: Johannes Holland --- doc/tcti.md | 2 + src/tss2-tcti/tctildr-dl.c | 4 + src/tss2-tcti/tctildr.c | 4 +- test/unit/tctildr-dl.c | 146 ++++++++++++++++++++++++++++++++++--- 4 files changed, 145 insertions(+), 11 deletions(-) diff --git a/doc/tcti.md b/doc/tcti.md index 90c029805..3643a75ae 100644 --- a/doc/tcti.md +++ b/doc/tcti.md @@ -107,6 +107,8 @@ Where: 1. `` 2. `libtss2-tcti-.so.0` 3. `libtss2-tcti-.so` + 4. `libtss2-.so.0` + 5. `libtss2-.so` **`child_conf`** diff --git a/src/tss2-tcti/tctildr-dl.c b/src/tss2-tcti/tctildr-dl.c index 491d404bc..9d93c4c0e 100644 --- a/src/tss2-tcti/tctildr-dl.c +++ b/src/tss2-tcti/tctildr-dl.c @@ -87,6 +87,10 @@ handle_from_name(const char *file, FMT_TCTI_PREFIX "%s" FMT_LIB_SUFFIX_0, /* libtss2-tcti-.so */ FMT_TCTI_PREFIX "%s" FMT_LIB_SUFFIX, + /* libtss2-.so.0 */ + FMT_TSS_PREFIX "%s" FMT_LIB_SUFFIX_0, + /* libtss2-.so */ + FMT_TSS_PREFIX "%s" FMT_LIB_SUFFIX, }; if (handle == NULL) { diff --git a/src/tss2-tcti/tctildr.c b/src/tss2-tcti/tctildr.c index 1a4180afb..f553cdf88 100644 --- a/src/tss2-tcti/tctildr.c +++ b/src/tss2-tcti/tctildr.c @@ -599,7 +599,9 @@ const TSS2_TCTI_INFO tss2_tcti_info = { "Where child_name: if not empty, tctildr will try to dynamically load the child tcti library in the following order:\n" " * \n" " * libtss2-tcti-.so.0\n" - " * libtss2-tcti-.so\n", + " * libtss2-tcti-.so\n" + " * libtss2-.so.0\n" + " * libtss2-.so\n", .init = Tss2_Tcti_TctiLdr_Init, }; diff --git a/test/unit/tctildr-dl.c b/test/unit/tctildr-dl.c index ab62aa74b..bcfc96d83 100644 --- a/test/unit/tctildr-dl.c +++ b/test/unit/tctildr-dl.c @@ -135,15 +135,21 @@ test_handle_from_name_null_handle (void **state) TSS2_RC rc = handle_from_name (NULL, NULL); assert_int_equal (rc, TSS2_TCTI_RC_BAD_REFERENCE); } -#define TEST_TCTI_NAME "test-tcti" -#define TEST_TCTI_CONF "test-conf" +#define TEST_TCTI_NAME "testname" +#define TEST_TCTI_CONF "testconf" +/* see documentation at tcti.md */ +#define TEST_TCTI_TRY_A TEST_TCTI_NAME +#define TEST_TCTI_TRY_B "libtss2-tcti-" TEST_TCTI_NAME ".so.0" +#define TEST_TCTI_TRY_C "libtss2-tcti-" TEST_TCTI_NAME ".so" +#define TEST_TCTI_TRY_D "libtss2-" TEST_TCTI_NAME ".so.0" +#define TEST_TCTI_TRY_E "libtss2-" TEST_TCTI_NAME ".so" static void test_handle_from_name_first_dlopen_success (void **state) { TSS2_RC rc; void *handle = NULL; - expect_string(__wrap_dlopen, filename, TEST_TCTI_NAME); + expect_string(__wrap_dlopen, filename, TEST_TCTI_TRY_A); expect_value(__wrap_dlopen, flags, RTLD_NOW); will_return(__wrap_dlopen, TEST_HANDLE); @@ -152,18 +158,17 @@ test_handle_from_name_first_dlopen_success (void **state) assert_int_equal (handle, TEST_HANDLE); } -#define TEST_TCTI_NAME_SO_0 FMT_TCTI_PREFIX TEST_TCTI_NAME""FMT_LIB_SUFFIX_0 static void test_handle_from_name_second_dlopen_success (void **state) { TSS2_RC rc; void *handle = NULL; - expect_string(__wrap_dlopen, filename, TEST_TCTI_NAME); + expect_string(__wrap_dlopen, filename, TEST_TCTI_TRY_A); expect_value(__wrap_dlopen, flags, RTLD_NOW); will_return(__wrap_dlopen, NULL); - expect_string(__wrap_dlopen, filename, TEST_TCTI_NAME_SO_0); + expect_string(__wrap_dlopen, filename, TEST_TCTI_TRY_B); expect_value(__wrap_dlopen, flags, RTLD_NOW); will_return(__wrap_dlopen, TEST_HANDLE); @@ -171,22 +176,77 @@ test_handle_from_name_second_dlopen_success (void **state) assert_int_equal (rc, TSS2_RC_SUCCESS); assert_int_equal (handle, TEST_HANDLE); } -#define TEST_TCTI_NAME_SO FMT_TCTI_PREFIX TEST_TCTI_NAME""FMT_LIB_SUFFIX static void test_handle_from_name_third_dlopen_success (void **state) { TSS2_RC rc; void *handle = NULL; - expect_string(__wrap_dlopen, filename, TEST_TCTI_NAME); + expect_string(__wrap_dlopen, filename, TEST_TCTI_TRY_A); expect_value(__wrap_dlopen, flags, RTLD_NOW); will_return(__wrap_dlopen, NULL); - expect_string(__wrap_dlopen, filename, TEST_TCTI_NAME_SO_0); + expect_string(__wrap_dlopen, filename, TEST_TCTI_TRY_B); expect_value(__wrap_dlopen, flags, RTLD_NOW); will_return(__wrap_dlopen, NULL); - expect_string(__wrap_dlopen, filename, TEST_TCTI_NAME_SO); + expect_string(__wrap_dlopen, filename, TEST_TCTI_TRY_C); + expect_value(__wrap_dlopen, flags, RTLD_NOW); + will_return(__wrap_dlopen, TEST_HANDLE); + + rc = handle_from_name (TEST_TCTI_NAME, &handle); + assert_int_equal (rc, TSS2_RC_SUCCESS); + assert_int_equal (handle, TEST_HANDLE); +} +static void +test_handle_from_name_fourth_dlopen_success (void **state) +{ + TSS2_RC rc; + void *handle = NULL; + + expect_string(__wrap_dlopen, filename, TEST_TCTI_TRY_A); + expect_value(__wrap_dlopen, flags, RTLD_NOW); + will_return(__wrap_dlopen, NULL); + + expect_string(__wrap_dlopen, filename, TEST_TCTI_TRY_B); + expect_value(__wrap_dlopen, flags, RTLD_NOW); + will_return(__wrap_dlopen, NULL); + + expect_string(__wrap_dlopen, filename, TEST_TCTI_TRY_C); + expect_value(__wrap_dlopen, flags, RTLD_NOW); + will_return(__wrap_dlopen, NULL); + + expect_string(__wrap_dlopen, filename, TEST_TCTI_TRY_D); + expect_value(__wrap_dlopen, flags, RTLD_NOW); + will_return(__wrap_dlopen, TEST_HANDLE); + + rc = handle_from_name (TEST_TCTI_NAME, &handle); + assert_int_equal (rc, TSS2_RC_SUCCESS); + assert_int_equal (handle, TEST_HANDLE); +} +static void +test_handle_from_name_fifth_dlopen_success (void **state) +{ + TSS2_RC rc; + void *handle = NULL; + + expect_string(__wrap_dlopen, filename, TEST_TCTI_TRY_A); + expect_value(__wrap_dlopen, flags, RTLD_NOW); + will_return(__wrap_dlopen, NULL); + + expect_string(__wrap_dlopen, filename, TEST_TCTI_TRY_B); + expect_value(__wrap_dlopen, flags, RTLD_NOW); + will_return(__wrap_dlopen, NULL); + + expect_string(__wrap_dlopen, filename, TEST_TCTI_TRY_C); + expect_value(__wrap_dlopen, flags, RTLD_NOW); + will_return(__wrap_dlopen, NULL); + + expect_string(__wrap_dlopen, filename, TEST_TCTI_TRY_D); + expect_value(__wrap_dlopen, flags, RTLD_NOW); + will_return(__wrap_dlopen, NULL); + + expect_string(__wrap_dlopen, filename, TEST_TCTI_TRY_E); expect_value(__wrap_dlopen, flags, RTLD_NOW); will_return(__wrap_dlopen, TEST_HANDLE); @@ -229,6 +289,14 @@ test_get_info_default_success (void **state) expect_value(__wrap_dlopen, flags, RTLD_NOW); will_return(__wrap_dlopen, NULL); + expect_string(__wrap_dlopen, filename, "libtss2-libtss2-tcti-default.so.so.0"); + expect_value(__wrap_dlopen, flags, RTLD_NOW); + will_return(__wrap_dlopen, NULL); + + expect_string(__wrap_dlopen, filename, "libtss2-libtss2-tcti-default.so.so"); + expect_value(__wrap_dlopen, flags, RTLD_NOW); + will_return(__wrap_dlopen, NULL); + expect_string(__wrap_dlopen, filename, "libtss2-tcti-tabrmd.so.0"); expect_value(__wrap_dlopen, flags, RTLD_NOW); will_return(__wrap_dlopen, HANDLE); @@ -261,6 +329,14 @@ test_get_info_default_info_fail (void **state) expect_value(__wrap_dlopen, flags, RTLD_NOW); will_return(__wrap_dlopen, NULL); + expect_string(__wrap_dlopen, filename, "libtss2-libtss2-tcti-default.so.so.0"); + expect_value(__wrap_dlopen, flags, RTLD_NOW); + will_return(__wrap_dlopen, NULL); + + expect_string(__wrap_dlopen, filename, "libtss2-libtss2-tcti-default.so.so"); + expect_value(__wrap_dlopen, flags, RTLD_NOW); + will_return(__wrap_dlopen, NULL); + expect_string(__wrap_dlopen, filename, "libtss2-tcti-tabrmd.so.0"); expect_value(__wrap_dlopen, flags, RTLD_NOW); will_return(__wrap_dlopen, HANDLE); @@ -413,6 +489,12 @@ test_tcti_fail_all (void **state) expect_string(__wrap_dlopen, filename, "libtss2-tcti-libtss2-tcti-default.so.so"); expect_value(__wrap_dlopen, flags, RTLD_NOW); will_return(__wrap_dlopen, NULL); + expect_string(__wrap_dlopen, filename, "libtss2-libtss2-tcti-default.so.so.0"); + expect_value(__wrap_dlopen, flags, RTLD_NOW); + will_return(__wrap_dlopen, NULL); + expect_string(__wrap_dlopen, filename, "libtss2-libtss2-tcti-default.so.so"); + expect_value(__wrap_dlopen, flags, RTLD_NOW); + will_return(__wrap_dlopen, NULL); /* Skip over libtss2-tcti-tabrmd.so */ expect_string(__wrap_dlopen, filename, "libtss2-tcti-tabrmd.so.0"); @@ -424,6 +506,12 @@ test_tcti_fail_all (void **state) expect_string(__wrap_dlopen, filename, "libtss2-tcti-libtss2-tcti-tabrmd.so.0.so"); expect_value(__wrap_dlopen, flags, RTLD_NOW); will_return(__wrap_dlopen, NULL); + expect_string(__wrap_dlopen, filename, "libtss2-libtss2-tcti-tabrmd.so.0.so.0"); + expect_value(__wrap_dlopen, flags, RTLD_NOW); + will_return(__wrap_dlopen, NULL); + expect_string(__wrap_dlopen, filename, "libtss2-libtss2-tcti-tabrmd.so.0.so"); + expect_value(__wrap_dlopen, flags, RTLD_NOW); + will_return(__wrap_dlopen, NULL); /* Skip over libtss2-tcti-device.so, /dev/tpmrm0 */ expect_string(__wrap_dlopen, filename, "libtss2-tcti-device.so.0"); @@ -435,6 +523,12 @@ test_tcti_fail_all (void **state) expect_string(__wrap_dlopen, filename, "libtss2-tcti-libtss2-tcti-device.so.0.so"); expect_value(__wrap_dlopen, flags, RTLD_NOW); will_return(__wrap_dlopen, NULL); + expect_string(__wrap_dlopen, filename, "libtss2-libtss2-tcti-device.so.0.so.0"); + expect_value(__wrap_dlopen, flags, RTLD_NOW); + will_return(__wrap_dlopen, NULL); + expect_string(__wrap_dlopen, filename, "libtss2-libtss2-tcti-device.so.0.so"); + expect_value(__wrap_dlopen, flags, RTLD_NOW); + will_return(__wrap_dlopen, NULL); /* Skip over libtss2-tcti-device.so, /dev/tpm0 */ expect_string(__wrap_dlopen, filename, "libtss2-tcti-device.so.0"); @@ -446,6 +540,12 @@ test_tcti_fail_all (void **state) expect_string(__wrap_dlopen, filename, "libtss2-tcti-libtss2-tcti-device.so.0.so"); expect_value(__wrap_dlopen, flags, RTLD_NOW); will_return(__wrap_dlopen, NULL); + expect_string(__wrap_dlopen, filename, "libtss2-libtss2-tcti-device.so.0.so.0"); + expect_value(__wrap_dlopen, flags, RTLD_NOW); + will_return(__wrap_dlopen, NULL); + expect_string(__wrap_dlopen, filename, "libtss2-libtss2-tcti-device.so.0.so"); + expect_value(__wrap_dlopen, flags, RTLD_NOW); + will_return(__wrap_dlopen, NULL); /* Skip over libtss2-tcti-swtpm.so */ expect_string(__wrap_dlopen, filename, "libtss2-tcti-swtpm.so.0"); @@ -457,6 +557,12 @@ test_tcti_fail_all (void **state) expect_string(__wrap_dlopen, filename, "libtss2-tcti-libtss2-tcti-swtpm.so.0.so"); expect_value(__wrap_dlopen, flags, RTLD_NOW); will_return(__wrap_dlopen, NULL); + expect_string(__wrap_dlopen, filename, "libtss2-libtss2-tcti-swtpm.so.0.so.0"); + expect_value(__wrap_dlopen, flags, RTLD_NOW); + will_return(__wrap_dlopen, NULL); + expect_string(__wrap_dlopen, filename, "libtss2-libtss2-tcti-swtpm.so.0.so"); + expect_value(__wrap_dlopen, flags, RTLD_NOW); + will_return(__wrap_dlopen, NULL); /* Skip over libtss2-tcti-mssim.so */ expect_string(__wrap_dlopen, filename, "libtss2-tcti-mssim.so.0"); @@ -468,6 +574,12 @@ test_tcti_fail_all (void **state) expect_string(__wrap_dlopen, filename, "libtss2-tcti-libtss2-tcti-mssim.so.0.so"); expect_value(__wrap_dlopen, flags, RTLD_NOW); will_return(__wrap_dlopen, NULL); + expect_string(__wrap_dlopen, filename, "libtss2-libtss2-tcti-mssim.so.0.so.0"); + expect_value(__wrap_dlopen, flags, RTLD_NOW); + will_return(__wrap_dlopen, NULL); + expect_string(__wrap_dlopen, filename, "libtss2-libtss2-tcti-mssim.so.0.so"); + expect_value(__wrap_dlopen, flags, RTLD_NOW); + will_return(__wrap_dlopen, NULL); TSS2_RC r; TSS2_TCTI_CONTEXT *tcti; @@ -496,6 +608,12 @@ test_info_from_name_handle_fail (void **state) expect_string(__wrap_dlopen, filename, "libtss2-tcti-foo.so"); expect_value(__wrap_dlopen, flags, RTLD_NOW); will_return(__wrap_dlopen, NULL); + expect_string(__wrap_dlopen, filename, "libtss2-foo.so.0"); + expect_value(__wrap_dlopen, flags, RTLD_NOW); + will_return(__wrap_dlopen, NULL); + expect_string(__wrap_dlopen, filename, "libtss2-foo.so"); + expect_value(__wrap_dlopen, flags, RTLD_NOW); + will_return(__wrap_dlopen, NULL); TSS2_RC rc = info_from_name ("foo", &info, &data); assert_int_equal (rc, TSS2_TCTI_RC_NOT_SUPPORTED); @@ -612,6 +730,12 @@ test_tctildr_get_info_from_name (void **state) expect_string(__wrap_dlopen, filename, "libtss2-tcti-foo.so"); expect_value(__wrap_dlopen, flags, RTLD_NOW); will_return(__wrap_dlopen, NULL); + expect_string(__wrap_dlopen, filename, "libtss2-foo.so.0"); + expect_value(__wrap_dlopen, flags, RTLD_NOW); + will_return(__wrap_dlopen, NULL); + expect_string(__wrap_dlopen, filename, "libtss2-foo.so"); + expect_value(__wrap_dlopen, flags, RTLD_NOW); + will_return(__wrap_dlopen, NULL); TSS2_RC rc = tctildr_get_info ("foo", &info, &data); assert_int_equal (rc, TSS2_TCTI_RC_NOT_SUPPORTED); @@ -659,6 +783,8 @@ main(void) cmocka_unit_test(test_handle_from_name_first_dlopen_success), cmocka_unit_test(test_handle_from_name_second_dlopen_success), cmocka_unit_test(test_handle_from_name_third_dlopen_success), + cmocka_unit_test(test_handle_from_name_fourth_dlopen_success), + cmocka_unit_test(test_handle_from_name_fifth_dlopen_success), cmocka_unit_test(test_fail_null), cmocka_unit_test(test_tcti_from_file_null_tcti), #ifndef ESYS_TCTI_DEFAULT_MODULE