#Inconsistent Behavior with TPM Access: Standalone Executable vs. Library
6 messages · Page 1 of 1 (latest)
pub struct Tpm2Client {
pub context_handle: *mut c_void,
}
const TBS_CONTEXT: TBS_CONTEXT_PARAMS = TBS_CONTEXT_PARAMS {
version: TBS_CONTEXT_VERSION_TWO,
};
impl Tpm2Client {
pub fn new() -> Self {
Tpm2Client {
context_handle: null_mut(),
}
}
pub fn init(&mut self) -> u32 {
unsafe {
Tbsi_Context_Create(&TBS_CONTEXT, &mut self.context_handle)
}
}
pub fn close(&self) -> u32 {
unsafe { Tbsip_Context_Close(self.context_handle) }
}
}
mod tests {
use super::*;
#[test]
fn test_tpm2_client() {
let mut client = Tpm2Client::new();
let result = client.init();
assert_eq!(result, 0); // Fails due to TBS_E_TPM_NOT_FOUND
let result = client.close();
assert_eq!(result, 0);
}
}
Both snippets use the same TBS_CONTEXT_PARAMS configuration. The library is being included and called from another binary in the same manner as the standalone executable.
Has anyone encountered similar issues or have any suggestions on what might be causing this discrepancy? Could this behavior be related to how the Windows TPM Base Services (TBS) API behaves differently when called from a library versus an executable?
Any insights or advice would be greatly appreciated. Thank you!
the windows doc : https://learn.microsoft.com/en-us/windows/win32/api/tbs/nf-tbs-tbsi_context_create
the crate doc : https://docs.rs/windows-sys/0.52.0/windows_sys/Win32/System/TpmBaseServices/fn.Tbsi_Context_Create.html
API documentation for the Rust Tbsi_Context_Create fn in crate windows_sys.
ps: tested with widows and windows-sys crate