From 175b14c4545d3e47c71f404ae869a8e487fd2a2f Mon Sep 17 00:00:00 2001 From: Takuma IMAMURA <209989118+hyperfinitism@users.noreply.github.com> Date: Sun, 15 Mar 2026 20:54:20 +0900 Subject: [PATCH] feat!: rename TPM2TOOLS_TCTI to RUST_TPM2_CLI_TCTI To prevent unintended conflicts between rust-tpm2-cli and tpm2-tools, rename the TCTI environment variable across the project. Signed-off-by: Takuma IMAMURA <209989118+hyperfinitism@users.noreply.github.com> --- README.md | 4 ++-- src/cli.rs | 4 ++-- src/raw_esys.rs | 6 +++--- src/tcti.rs | 6 +++--- tests/helpers.sh | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 4ef1289..86cb1b3 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ newgrp tss ls -l /dev/tpm* # Set TPM device path used by rust-tpm2-cli -export TPM2TOOLS_TCTI="device:/dev/tpm0" +export RUST_TPM2_CLI_TCTI="device:/dev/tpm0" ``` ### Set up swtpm (software TPM simulator) @@ -85,7 +85,7 @@ swtpm socket \ --flags startup-clear # In another terminal: -export TPM2TOOLS_TCTI="swtpm:host=localhost,port=2321" +export RUST_TPM2_CLI_TCTI="swtpm:host=localhost,port=2321" ``` ### Run integration tests diff --git a/src/cli.rs b/src/cli.rs index 50aa048..cf397fc 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -18,8 +18,8 @@ pub struct Cli { #[derive(Parser)] pub struct GlobalOpts { - /// TCTI configuration (e.g. device:/dev/tpm0, mssim:host=localhost,port=2321) - #[arg(short = 'T', long = "tcti", env = "TPM2TOOLS_TCTI")] + /// TCTI configuration (e.g. device:/dev/tpm0, swtpm:host=localhost,port=2321) + #[arg(short = 'T', long = "tcti", env = "RUST_TPM2_CLI_TCTI")] pub tcti: Option, /// Enable errata fixups diff --git a/src/raw_esys.rs b/src/raw_esys.rs index 192e582..4f12704 100644 --- a/src/raw_esys.rs +++ b/src/raw_esys.rs @@ -13,6 +13,8 @@ use std::ptr::{null, null_mut}; use anyhow::{Context, bail}; use tss_esapi::tss2_esys::*; +use crate::tcti::DEFAULT_TCTI; + // ----------------------------------------------------------------------- // Raw context helpers // ----------------------------------------------------------------------- @@ -27,9 +29,7 @@ impl RawEsysContext { pub(crate) fn new(tcti: Option<&str>) -> anyhow::Result { let tcti_str = match tcti { Some(s) => s.to_owned(), - None => { - std::env::var("TPM2TOOLS_TCTI").unwrap_or_else(|_| "device:/dev/tpm0".to_owned()) - } + None => std::env::var("RUST_TPM2_CLI_TCTI").unwrap_or_else(|_| DEFAULT_TCTI.to_owned()), }; let c_str = CString::new(tcti_str.as_str()).context("TCTI string contains NUL")?; diff --git a/src/tcti.rs b/src/tcti.rs index 649913d..e2023e6 100644 --- a/src/tcti.rs +++ b/src/tcti.rs @@ -14,12 +14,12 @@ pub(crate) const DEFAULT_DEVICE_PATH: &str = "/dev/tpm0"; /// Parse a TCTI configuration string into a [`TctiNameConf`]. /// -/// If `tcti` is `None`, falls back to the `TPM2TOOLS_TCTI` environment +/// If `tcti` is `None`, falls back to the `RUST_TPM2_CLI_TCTI` environment /// variable, then to `device:/dev/tpm0`. pub fn parse_tcti(tcti: Option<&str>) -> Result { let tcti_str = match tcti { Some(s) => s.to_owned(), - None => std::env::var("TPM2TOOLS_TCTI").unwrap_or_else(|_| DEFAULT_TCTI.to_owned()), + None => std::env::var("RUST_TPM2_CLI_TCTI").unwrap_or_else(|_| DEFAULT_TCTI.to_owned()), }; TctiNameConf::from_str(&tcti_str).map_err(|e| Tpm2Error::InvalidTcti(e.to_string())) } @@ -30,7 +30,7 @@ pub fn parse_tcti(tcti: Option<&str>) -> Result { pub(crate) fn extract_device_path(tcti: Option<&str>) -> String { let tcti_str = match tcti { Some(s) => s.to_owned(), - None => std::env::var("TPM2TOOLS_TCTI").unwrap_or_else(|_| DEFAULT_TCTI.to_owned()), + None => std::env::var("RUST_TPM2_CLI_TCTI").unwrap_or_else(|_| DEFAULT_TCTI.to_owned()), }; if let Some(rest) = tcti_str.strip_prefix("device:") { rest.to_owned() diff --git a/tests/helpers.sh b/tests/helpers.sh index 626b3aa..b8d0e1c 100644 --- a/tests/helpers.sh +++ b/tests/helpers.sh @@ -59,7 +59,7 @@ summary() { return 0 } -# Start an swtpm simulator and set TPM2TOOLS_TCTI. +# Start an swtpm simulator and set RUST_TPM2_CLI_TCTI. start_swtpm() { TEST_TMPDIR="$(mktemp -d)" export TEST_TMPDIR @@ -84,7 +84,7 @@ start_swtpm() { sleep 0.1 done - export TPM2TOOLS_TCTI="swtpm:host=localhost,port=${SWTPM_PORT}" + export RUST_TPM2_CLI_TCTI="swtpm:host=localhost,port=${SWTPM_PORT}" } # Stop swtpm and clean up.