Skip to content

Commit

Permalink
tctildr: add libtss2-<name>.so.0 and libtss2-<name>.so to file loading
Browse files Browse the repository at this point in the history
The tctildr has a different file name than other tctis.
Normal tctis:
 * libtss2-tcti-<name>.so
Tctildr:
 * libtss2-tctildr.so

Enable loading the tctildr tcti module.

Signed-off-by: Johannes Holland <[email protected]>
  • Loading branch information
joholl committed Nov 11, 2023
1 parent c2f4ef0 commit be2dcbf
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 11 deletions.
2 changes: 2 additions & 0 deletions doc/tcti.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ Where:
1. `<child_name>`
2. `libtss2-tcti-<child_name>.so.0`
3. `libtss2-tcti-<child_name>.so`
4. `libtss2-<child_name>.so.0`
5. `libtss2-<child_name>.so`

**`child_conf`**

Expand Down
4 changes: 4 additions & 0 deletions src/tss2-tcti/tctildr-dl.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ handle_from_name(const char *file,
FMT_TCTI_PREFIX "%s" FMT_LIB_SUFFIX_0,
/* libtss2-tcti-<name>.so */
FMT_TCTI_PREFIX "%s" FMT_LIB_SUFFIX,
/* libtss2-<name>.so.0 */
FMT_TSS_PREFIX "%s" FMT_LIB_SUFFIX_0,
/* libtss2-<name>.so */
FMT_TSS_PREFIX "%s" FMT_LIB_SUFFIX,
};

if (handle == NULL) {
Expand Down
4 changes: 3 additions & 1 deletion src/tss2-tcti/tctildr.c
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,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"
" * <child_name>\n"
" * libtss2-tcti-<child_name>.so.0\n"
" * libtss2-tcti-<child_name>.so\n",
" * libtss2-tcti-<child_name>.so\n"
" * libtss2-<child_name>.so.0\n"
" * libtss2-<child_name>.so\n",
.init = Tss2_Tcti_TctiLdr_Init,
};

Expand Down
146 changes: 136 additions & 10 deletions test/unit/tctildr-dl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -152,41 +158,95 @@ 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);

rc = handle_from_name (TEST_TCTI_NAME, &handle);
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);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand All @@ -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");
Expand All @@ -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");
Expand All @@ -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");
Expand All @@ -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");
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit be2dcbf

Please sign in to comment.