Skip to content

Commit 2763ce4

Browse files
uglyoldbobFirstyear
authored andcommitted
Update documentation
Update bundled documentation and include macos support Signed-off-by: William Brown <[email protected]>
1 parent 17478d9 commit 2763ce4

File tree

4 files changed

+112
-16
lines changed

4 files changed

+112
-16
lines changed

Diff for: tss-esapi-sys/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ cfg-if = "1.0.0"
2222
semver = "1.0.7"
2323

2424
[target.'cfg(windows)'.build-dependencies]
25-
msbuild = { git = "https://github.com/uglyoldbob/msbuild.git", optional = true }
25+
msbuild = { version = "0.1.0", optional = true }
2626
winreg = {version = "0.52", optional = true }
2727

2828
[features]

Diff for: tss-esapi-sys/README.md

+57-4
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ interface to Rust to [TSS](https://github.com/tpm2-software/tpm2-tss).
1313

1414
This crate exposes an interface for the TSS Enhanced System API and thus
1515
links to libraries that expose this interface. In order to allow proper use
16-
of the ESAPI, this FFI layer includes bindings to TCTI and MU headers, and
16+
of the ESAPI, this FFI layer includes bindings to TCTI and MU headers, and
1717
must therefore link to all of them at build time.
1818

1919
The paths to the libraries are discovered using `pkg-config` - make sure they
20-
are discoverable in this way on your system. Our build script looks for
21-
`tss2-esys`, `tss2-tctildr` and `tss2-mu`. A minimum version of `3.2.2` is
20+
are discoverable in this way on your system. Our build script looks for
21+
`tss2-esys`, `tss2-tctildr` and `tss2-mu`. A minimum version of `3.2.2` is
2222
required for all of them.
2323

2424
Having installed the open-source implementation libraries at `/usr/local/lib` (by default), it
@@ -41,9 +41,62 @@ available, feel free to raise a Pull Request to add it or to use build-time
4141
generation of bindings. All the committed bindings **MUST** be generated from
4242
the library version found under the `vendor` submodule.
4343

44+
## Bundling TPM-TSS
45+
46+
tpm-tss is used by this library to communicate with TPMs. If this library
47+
is not available on your system you may optionally bundle (vendor) tpm-tss
48+
during builds. tpm-tss can be provided from a local source path with the
49+
environment variable `TPM_TSS_SOURCE_PATH` or it will be retrieved from
50+
github during the build.
51+
52+
To enable this feature:
53+
54+
```bash
55+
cargo build --features=bundled
56+
```
57+
58+
```bash
59+
TPM_TSS_SOURCE_PATH=/path/to/tpm-tss cargo build --features=bundled
60+
```
61+
62+
If using this feature from an external project
63+
64+
```
65+
tss-esapi-sys = { version = "...", features = "bundled" }
66+
```
67+
68+
### Windows
69+
70+
Compiling for windows requires a bit of setup to work with the bundled feature.
71+
72+
* Openssl must be installed to a non-standard location at C:\OpenSSL-v11-Win64
73+
* Visual studio 2017 must be installed with the Clang/C2 experimental component,
74+
and windows sdk 10.0.17134.0.
75+
76+
### MacOS
77+
78+
Compiling on MacOS requires the bundling feature. This requires dependencies
79+
from brew.
80+
81+
```bashbre
82+
brew install autoconf autoconf-archive automake json-c libtool m4 pkg-config
83+
```
84+
85+
Optionally you may require these libraries for certain classes of TPM transport
86+
87+
```
88+
brew install libftdi
89+
```
90+
91+
### OpenSUSE / SUSE
92+
93+
```
94+
sudo zypper in autoconf autoconf-archive automake libjson-c-devel libtool libtpms-devel gawk make
95+
```
96+
4497
## Cross compiling
4598

46-
Cross-compilation can be done as long as you have on your build system the TSS
99+
Cross-compilation can be done as long as you have on your build system the TSS
47100
libraries compiled for your target system of choice. We rely on `pkg-config` to
48101
identify the libraries which we link against. Installing `tpm2-tss` does yield
49102
`.pc` files which can be used for this purpose, but depending on the exact build

Diff for: tss-esapi-sys/build.rs

+50-11
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ pub mod target {
4343
match (target.architecture, target.operating_system) {
4444
(Architecture::Arm(_), OperatingSystem::Linux)
4545
| (Architecture::Aarch64(_), OperatingSystem::Linux)
46+
| (Architecture::Aarch64(_), OperatingSystem::Darwin)
4647
| (Architecture::X86_64, OperatingSystem::Darwin)
4748
| (Architecture::X86_64, OperatingSystem::Linux) => {}
4849
(arch, os) => {
@@ -77,15 +78,20 @@ pub mod tpm2_tss {
7778
}
7879

7980
impl Installation {
81+
/// Return an optional list of clang arguments that are platform specific
82+
#[cfg(feature = "bundled")]
8083
fn platform_args() -> Option<Vec<String>> {
8184
cfg_if::cfg_if! {
8285
if #[cfg(windows)] {
8386
let mut clang_args: Vec<String> = Vec::new();
8487
let hklm = winreg::RegKey::predef(winreg::enums::HKEY_LOCAL_MACHINE);
88+
// Find the windows sdk path from the windows registry
8589
let sdk_entry = hklm.open_subkey("SOFTWARE\\WOW6432Node\\Microsoft\\Microsoft SDKs\\Windows\\v10.0").unwrap();
90+
// add relevant paths to get to the windows 10.0.17134.0 sdk, which tpm2-tss uses on windows.
8691
let installation_path: String = sdk_entry.get_value("InstallationFolder").unwrap();
8792
let ip_pb = PathBuf::from(installation_path).join("Include");
8893
let windows_sdk = ip_pb.join("10.0.17134.0");
94+
// Add paths required for bindgen to find all required headers
8995
clang_args.push(format!("-I{}", windows_sdk.join("ucrt").display()));
9096
clang_args.push(format!("-I{}", windows_sdk.join("um").display()));
9197
clang_args.push(format!("-I{}", windows_sdk.join("shared").display()));
@@ -125,32 +131,63 @@ pub mod tpm2_tss {
125131
repo_path
126132
}
127133

128-
#[cfg(feature = "bundled")]
134+
#[cfg(all(feature = "bundled", not(windows)))]
129135
fn compile_with_autotools(p: PathBuf) -> PathBuf {
130136
let output1 = std::process::Command::new("./bootstrap")
131137
.current_dir(&p)
132138
.output()
133139
.expect("bootstrap script failed");
134140
let status = output1.status;
135141
if !status.success() {
136-
panic!("bootstrap script failed with {}:\n{:?}", status, output1);
142+
panic!(
143+
"{:?}/bootstrap script failed with {}:\n{:?}",
144+
p, status, output1
145+
);
137146
}
138147

139148
let mut config = autotools::Config::new(p);
140-
config.fast_build(true).reconf("-ivf").build()
149+
config
150+
// Force configuration of the autotools env
151+
.reconf("-fiv")
152+
// skip ./configure if no parameter changes are made
153+
.fast_build(true)
154+
.enable("esys", None)
155+
// Disable fapi as we only use esys
156+
.disable("fapi", None)
157+
.disable("fapi-async-tests", None)
158+
// Disable integration tests
159+
.disable("integration", None)
160+
// Don't allow weak crypto
161+
.disable("weakcrypto", None)
162+
.build()
141163
}
142164

143165
#[cfg(feature = "bundled")]
144166
/// Uses a bundled build for an installation
145167
pub fn bundled() -> Self {
146168
use std::io::Write;
147169
let out_path = std::env::var("OUT_DIR").expect("No output directory given");
148-
let source_path = Self::fetch_source(
149-
out_path,
150-
"tpm2-tss",
151-
"https://github.com/tpm2-software/tpm2-tss.git",
152-
MINIMUM_VERSION,
153-
);
170+
let source_path = if let Ok(tpm_tss_source) = std::env::var("TPM_TSS_SOURCE_PATH") {
171+
eprintln!("using local tpm2-tss from {}", tpm_tss_source);
172+
let Ok(source_path) = PathBuf::from(tpm_tss_source).canonicalize() else {
173+
panic!(
174+
"Unable to canonicalize tpm2-tss source path. Does the source path exist?"
175+
);
176+
};
177+
178+
source_path
179+
} else {
180+
eprintln!(
181+
"using remote tpm2-tss from https://github.com/tpm2-software/tpm2-tss.git"
182+
);
183+
Self::fetch_source(
184+
out_path,
185+
"tpm2-tss",
186+
"https://github.com/tpm2-software/tpm2-tss.git",
187+
MINIMUM_VERSION,
188+
)
189+
};
190+
154191
let version_file_name = source_path.join("VERSION");
155192
let mut version_file = std::fs::File::create(version_file_name)
156193
.expect("Unable to create version file for tpm2-tss");
@@ -298,11 +335,14 @@ pub mod tpm2_tss {
298335
.clang_arg(tss2_tcti_tbs.include_dir_arg())
299336
.header(tss2_tcti_tbs.header_file_arg());
300337
}
338+
339+
#[cfg(feature = "bundled")]
301340
if let Some(clang_args) = Self::platform_args() {
302341
for arg in clang_args {
303342
builder = builder.clang_arg(arg);
304343
}
305344
}
345+
306346
builder
307347
}
308348
}
@@ -332,7 +372,7 @@ pub mod tpm2_tss {
332372
let build_string = match profile.as_str() {
333373
"debug" => "Debug",
334374
"release" => "Release",
335-
_ => panic!("Unknown cargo profile:"),
375+
_ => panic!("Unknown cargo profile: {}", profile),
336376
};
337377
let mut source_path = self
338378
.tss2_esys
@@ -342,7 +382,6 @@ pub mod tpm2_tss {
342382
source_path.pop();
343383
source_path.pop();
344384
source_path.pop();
345-
println!("Source path is {}", source_path.display());
346385
println!(
347386
"cargo:rustc-link-search=dylib={}",
348387
source_path.join("x64").join(build_string).display()

Diff for: tss-esapi/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ time using the headers identified on the system.
1717

1818
Our end-goal is to achieve a fully Rust-native interface that offers strong safety and security guarantees. Check out our [documentation](https://docs.rs/tss-esapi/*/tss_esapi/#notes-on-code-safety) for an overview of our code safety approach.
1919

20+
## Integration Tests
21+
22+
See the [integration tests](https://github.com/parallaxsecond/rust-tss-esapi/tree/main/tss-esapi/tests)
23+
2024
## Cargo Features
2125

2226
The crate currently offers the following features:

0 commit comments

Comments
 (0)