Allow to change TCS hostname

This commit is contained in:
наб 2020-10-27 15:40:07 +01:00
parent f8bb6174c3
commit a558ca5b48
No known key found for this signature in database
GPG Key ID: BCFD0B018D2658F1
2 changed files with 10 additions and 2 deletions

@ -2,7 +2,8 @@
### TPM selection
The tzpfms suite always connects to a local tcsd(8) process (at `localhost:30003`).
The tzpfms suite connects to a local tcsd(8) process (at `localhost:30003`) by default.
Use the environment variable `TZPFMS_TPM1X` to specify a remote TCS hostname.
The TrouSerS tcsd(8) daemon will try `/dev/tpm0`, then `/udev/tpm0`, then `/dev/tpm`;
by occupying one of the earlier ones with, for example, shell redirection, a later one can be selected.

@ -31,7 +31,14 @@ template <class F>
int with_tpm1x_session(F && func) {
TSS_HCONTEXT ctx{}; // All memory lives as long as this does
TRY_TPM1X("create TPM context", Tspi_Context_Create(&ctx));
TRY_TPM1X("connect TPM context to TPM", Tspi_Context_Connect(ctx, nullptr));
{
UNICODE * tcs_address{};
quickscope_wrapper tcs_address_deleter{[&] { free(tcs_address); }};
if(auto addr = getenv("TZPFMS_TPM1X"))
tcs_address = reinterpret_cast<UNICODE *>(TRY_PTR("allocate remote TPM address", Trspi_Native_To_UNICODE(reinterpret_cast<BYTE *>(addr), nullptr)));
TRY_TPM1X("connect TPM context to TPM", Tspi_Context_Connect(ctx, tcs_address));
}
quickscope_wrapper ctx_deleter{[&] {
Trspi_Error_String(Tspi_Context_FreeMemory(ctx, nullptr));
Trspi_Error_String(Tspi_Context_Close(ctx));