Skip to content

Commit

Permalink
Adds a TBS TctiNameConf.
Browse files Browse the repository at this point in the history
When parallaxsecond#477 got merged it became possible to build
using a path to the ```tpm2-tss``` installation
instead of depending on ```pkg-config```.

This made it possible to build under Windows. To
further increase the support for the windows
platform this commit moves the option for TBS
TCTI that is being introduced in parallaxsecond#523 into a
separate commit.

This commit also updates the documentation
regarding building using an installation
folder.

Co-authored-by: Thomas Epperson <thomas.epperson@gmail.com>
Signed-off-by: Jesper Brynolf <jesper.brynolf@gmail.com>
  • Loading branch information
Superhepper and uglyoldbob committed Sep 13, 2024
1 parent 8ec8381 commit 7732d39
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tss-esapi-sys/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,26 @@ wrapper script around `pkg-config` can be seen
Be advised that in some cases the linker used might need to be set manually in
`.cargo/config`.

## Locally built tpm2-tss
It is now possible to specify an installation path when building the crate. This will
make the build process trying to find all the libraries and header files it needs from
installation path instead of using `pkg-config`.

The `TPM2_TSS_PATH` environment variable name is used to specify the path to the installation.
The installation is required to have a specific layout.

```md
Installation folder
├── bin (Optional)
│ ├── tss2-*.dll (Windows)
├── include (Required)
│ ├── tss2
│ │ ├── tss2_*.h
├── lib (Required)
│ ├── tss2-*.lib (Windows)
│ ├── tss2-*.so (Nix)
│ ├── tss2-*.pdb (Windows)
└── VERSION (Required)
```

*Copyright 2021 Contributors to the Parsec project.*
15 changes: 15 additions & 0 deletions tss-esapi/src/tcti_ldr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const DEVICE: &str = "device";
const MSSIM: &str = "mssim";
const SWTPM: &str = "swtpm";
const TABRMD: &str = "tabrmd";
const TBS: &str = "tbs";

/// TCTI Context created via a TCTI Loader Library.
/// Wrapper around the TSS2_TCTI_CONTEXT structure.
Expand Down Expand Up @@ -143,6 +144,10 @@ pub enum TctiNameConf {
///
/// For more information about configuration, see [this page](https://www.mankier.com/3/Tss2_Tcti_Tabrmd_Init)
Tabrmd(TabrmdConfig),
/// Connect to the tpm using the Trusted Platform Module (TPM) Base Services (TBS) on Windows.
///
/// For more information about TBS, see [this page](https://learn.microsoft.com/en-us/windows/win32/tbs/about-tbs)
Tbs,
}

impl TctiNameConf {
Expand Down Expand Up @@ -174,6 +179,7 @@ impl TryFrom<TctiNameConf> for CString {
TctiNameConf::Mssim(..) => MSSIM,
TctiNameConf::Swtpm(..) => SWTPM,
TctiNameConf::Tabrmd(..) => TABRMD,
TctiNameConf::Tbs => TBS,
};

let tcti_conf = match tcti {
Expand Down Expand Up @@ -204,6 +210,7 @@ impl TryFrom<TctiNameConf> for CString {
TctiNameConf::Tabrmd(config) => {
format!("bus_name={},bus_type={}", config.bus_name, config.bus_type)
}
TctiNameConf::Tbs => String::new(),
};

if tcti_conf.is_empty() {
Expand Down Expand Up @@ -247,6 +254,10 @@ impl FromStr for TctiNameConf {
)?));
}

if config_str.trim() == TBS {
return Ok(TctiNameConf::Tbs);
}

Err(Error::WrapperError(WrapperErrorKind::InvalidParam))
}
}
Expand Down Expand Up @@ -327,6 +338,10 @@ fn validate_from_str_tcti() {

let tcti = TctiNameConf::from_str("tabrmd").unwrap();
assert_eq!(tcti, TctiNameConf::Tabrmd(Default::default()));

let tcti_tbs = TctiNameConf::from_str("tbs")
.expect("It should be possible to convert the string 'tbs' into a TctiNameConf object.");
assert_eq!(tcti_tbs, TctiNameConf::Tbs);
}

/// Configuration for a Device TCTI context
Expand Down

0 comments on commit 7732d39

Please sign in to comment.