Skip to content

Commit 5c581d4

Browse files
authored
Merge pull request #194 from ionut-arm/tcti-conf
Add TCTI configuration functionality
2 parents 6ca8010 + b79eadf commit 5c581d4

File tree

5 files changed

+45
-27
lines changed

5 files changed

+45
-27
lines changed

Cargo.lock

Lines changed: 10 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ log = { version = "0.4.8", features = ["serde"] }
3333
pkcs11 = { version = "0.4.0", optional = true }
3434
picky-asn1-der = { version = "0.2.2", optional = true }
3535
picky-asn1 = { version = "0.2.1", optional = true }
36-
tss-esapi = { version = "4.0.3-alpha.1", optional = true }
36+
tss-esapi = { version = "4.0.5-alpha.1", optional = true }
3737
bincode = "1.1.4"
3838
structopt = "0.3.5"
3939
derivative = "2.1.1"

config.toml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,16 @@ key_info_manager = "on-disk-manager"
7373
#[[provider]]
7474
#provider_type = "Tpm"
7575
#key_info_manager = "on-disk-manager"
76-
# (Required) TPM TCTI device to use with this provider. Options are:
77-
# - "device": uses the TPM device on /dev/tpm0
78-
# - "mssim": uses the simulation TPM with the socket
79-
# - "tabrmd": uses the TPM2 Access Broker & Resource Management Daemon
76+
# (Required) TPM TCTI device to use with this provider. The string can include configuration values - if no
77+
# configuration value is given, the defaults are used. Options are:
78+
# - "device": uses a TPM device available as a file node; path can be given as a configuration string,
79+
# e.g "device:/path/to/tpm"; the default path is /dev/tpm0
80+
# - "mssim": uses the TPM simulator server with the socket; server path and/or port can be given as configuration values,
81+
# e.g. "mssim:host=168.0.1.1,port=1234"; "host" can be set to IPv4, IPv6 or a hostname; default values are
82+
# "localhost" for "host" and 2321 for "port"
83+
# - "tabrmd": uses the TPM2 Access Broker & Resource Management Daemon; dbus name and type ("session" or
84+
# "system") can be given as parameters: e.g. "tabrmd:bus_name=some.bus.Name,bus_type=session"; default
85+
# values are "com.intel.tss2.Tabrmd" for "bus_name" and "system" for "bus_type"
8086
#tcti = "mssim"
8187
# (Required) Authentication value for performing operations on the TPM Owner Hierarchy. The string can
8288
# be empty, however we strongly suggest that you use a secure passcode.

e2e_tests/provider_cfg/tpm/config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ manager_type = "OnDisk"
1616
[[provider]]
1717
provider_type = "Tpm"
1818
key_info_manager = "on-disk-manager"
19-
tcti = "mssim"
19+
tcti = "mssim:host=127.0.0.1,port=2321"
2020
owner_hierarchy_auth = "hex:74706d5f70617373" # "tpm_pass" in hex

src/providers/tpm_provider/mod.rs

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use super::Provide;
88
use crate::authenticators::ApplicationName;
99
use crate::key_info_managers::ManageKeyInfo;
1010
use derivative::Derivative;
11-
use log::{error, info, trace};
11+
use log::{info, trace};
1212
use parsec_interface::operations::list_providers::ProviderInfo;
1313
use parsec_interface::operations::{
1414
psa_destroy_key, psa_export_public_key, psa_generate_key, psa_import_key, psa_sign_hash,
@@ -17,9 +17,10 @@ use parsec_interface::operations::{
1717
use parsec_interface::requests::{Opcode, ProviderID, ResponseStatus, Result};
1818
use std::collections::HashSet;
1919
use std::io::ErrorKind;
20+
use std::str::FromStr;
2021
use std::sync::{Arc, Mutex, RwLock};
2122
use tss_esapi::utils::algorithm_specifiers::Cipher;
22-
use tss_esapi::Tcti;
23+
use tss_esapi::utils::tcti::Tcti;
2324
use uuid::Uuid;
2425

2526
mod asym_sign;
@@ -154,7 +155,7 @@ impl Drop for TpmProvider {
154155
pub struct TpmProviderBuilder {
155156
#[derivative(Debug = "ignore")]
156157
key_info_store: Option<Arc<RwLock<dyn ManageKeyInfo + Send + Sync>>>,
157-
tcti: Option<Tcti>,
158+
tcti: Option<String>,
158159
owner_hierarchy_auth: Option<String>,
159160
}
160161

@@ -177,17 +178,7 @@ impl TpmProviderBuilder {
177178
}
178179

179180
pub fn with_tcti(mut self, tcti: &str) -> TpmProviderBuilder {
180-
// Convert from a String to the enum.
181-
self.tcti = match tcti {
182-
"device" => Some(Tcti::Device),
183-
"mssim" => Some(Tcti::Mssim),
184-
_ => {
185-
if crate::utils::GlobalConfig::log_error_details() {
186-
error!("The string {} does not match a TCTI device.", tcti);
187-
}
188-
None
189-
}
190-
};
181+
self.tcti = Some(tcti.to_owned());
191182

192183
self
193184
}
@@ -231,8 +222,15 @@ impl TpmProviderBuilder {
231222
unsafe fn find_default_context_cipher(&self) -> std::io::Result<Cipher> {
232223
let ciphers = [Cipher::aes_256_cfb(), Cipher::aes_128_cfb()];
233224
let mut ctx = tss_esapi::Context::new(
234-
self.tcti
235-
.ok_or_else(|| std::io::Error::new(ErrorKind::InvalidData, "missing TCTI"))?,
225+
Tcti::from_str(self.tcti.as_ref().ok_or_else(|| {
226+
std::io::Error::new(ErrorKind::InvalidData, "Invalid TCTI configuration string")
227+
})?)
228+
.or_else(|_| {
229+
Err(std::io::Error::new(
230+
ErrorKind::InvalidData,
231+
"Invalid TCTI configuration string",
232+
))
233+
})?,
236234
)
237235
.or_else(|e| {
238236
format_error!("Error when creating TSS Context", e);
@@ -264,9 +262,15 @@ impl TpmProviderBuilder {
264262
pub unsafe fn build(mut self) -> std::io::Result<TpmProvider> {
265263
let hierarchy_auth = self.get_hierarchy_auth()?;
266264
let default_cipher = self.find_default_context_cipher()?;
267-
let tcti = self
268-
.tcti
269-
.ok_or_else(|| std::io::Error::new(ErrorKind::InvalidData, "missing TCTI"))?;
265+
let tcti = Tcti::from_str(self.tcti.as_ref().ok_or_else(|| {
266+
std::io::Error::new(ErrorKind::InvalidData, "Invalid TCTI configuration string")
267+
})?)
268+
.or_else(|_| {
269+
Err(std::io::Error::new(
270+
ErrorKind::InvalidData,
271+
"Invalid TCTI configuration string",
272+
))
273+
})?;
270274
TpmProvider::new(
271275
self.key_info_store.ok_or_else(|| {
272276
std::io::Error::new(ErrorKind::InvalidData, "missing key info store")

0 commit comments

Comments
 (0)