Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions tss-esapi/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2021 Contributors to the Parsec project.
// SPDX-License-Identifier: Apache-2.0
use semver::{Version, VersionReq};
use semver::{Version, VersionReq, Prerelease};

const TPM2_TSS_MINIMUM_VERSION: Version = Version::new(4, 1, 3);

Expand All @@ -13,7 +13,7 @@ fn main() {

// If documentation for Docs.rs is being built then the version is set
// to the minimum supported tpm2-tss version.
let tss_version = if std::env::var("DOCS_RS").is_ok() {
let mut tss_version = if std::env::var("DOCS_RS").is_ok() {
TPM2_TSS_MINIMUM_VERSION
} else {
let tss_version_string = std::env::var("DEP_TSS2_ESYS_VERSION")
Expand All @@ -23,9 +23,14 @@ fn main() {
.expect("Failed to parse the DEP_TSS2_ESYS_VERSION variable as a semver version")
};

// nuke any prerelease info, which probably is just a git repo/dirty flag
// like: 4.0.1-67-gb7bad346
tss_version.pre = Prerelease::EMPTY;

let supported_tss_version =
VersionReq::parse("<5.0.0, >=2.3.3").expect("Failed to parse supported TSS version");

//eprintln!("tss version: {} / {:?}", supported_tss_version, tss_version);
assert!(
supported_tss_version.matches(&tss_version),
"Unsupported TSS version {tss_version}"
Expand Down
4 changes: 2 additions & 2 deletions tss-esapi/src/abstraction/nv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{
};

use crate::{
constants::{tss::*, CapabilityType, PropertyTag},
constants::{tss::*, CapabilityType, PropertyTag, PrimitivePropertyTag},
handles::{AuthHandle, NvIndexHandle, NvIndexTpmHandle, TpmHandle},
interface_types::reserved_handles::NvAuth,
structures::{CapabilityData, MaxNvBuffer, Name, NvPublic},
Expand Down Expand Up @@ -155,7 +155,7 @@ impl NvOpenOptions {
/// Get the maximum buffer size for an NV space.
pub fn max_nv_buffer_size(ctx: &mut Context) -> Result<usize> {
Ok(ctx
.get_tpm_property(PropertyTag::NvBufferMax)?
.get_tpm_property(PropertyTag::PrimitivePropertyTag(PrimitivePropertyTag::NvBufferMax))?
.map(usize::try_from)
.transpose()
.map_err(|_| {
Expand Down
2 changes: 1 addition & 1 deletion tss-esapi/src/constants/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub use command_code::CommandCode;
pub use ecc::EccCurveIdentifier;
pub use nv_index_type::NvIndexType;
pub use pcr_property_tag::PcrPropertyTag;
pub use property_tag::PropertyTag;
pub use property_tag::{PropertyTag,PrimitivePropertyTag};
pub use return_code::{
BaseError, ReturnCodeLayer, TpmFormatOneError, TpmFormatZeroError, TpmFormatZeroWarning,
};
Expand Down
25 changes: 17 additions & 8 deletions tss-esapi/src/constants/property_tag.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// Copyright 2020 Contributors to the Parsec project.
// SPDX-License-Identifier: Apache-2.0
use crate::{constants::tss::*, tss2_esys::TPM2_PT, Error, Result, WrapperErrorKind};
use log::error;
use crate::{constants::tss::*, tss2_esys::TPM2_PT, Error, Result};
use num_derive::{FromPrimitive, ToPrimitive};
use num_traits::{FromPrimitive, ToPrimitive};
use std::convert::TryFrom;

#[derive(FromPrimitive, ToPrimitive, Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(u32)]
pub enum PropertyTag {
pub enum PrimitivePropertyTag {
None = TPM2_PT_NONE,
// Fixed
FamilyIndicator = TPM2_PT_FAMILY_INDICATOR,
Expand Down Expand Up @@ -81,19 +80,29 @@ pub enum PropertyTag {
AuditCounter1 = TPM2_PT_AUDIT_COUNTER_1,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum PropertyTag {
PrimitivePropertyTag(PrimitivePropertyTag),
Other(u32),
}


impl From<PropertyTag> for TPM2_PT {
fn from(property_tag: PropertyTag) -> TPM2_PT {
// The values are well defined so this cannot fail.
property_tag.to_u32().unwrap()
match property_tag {
PropertyTag::PrimitivePropertyTag(base) => { base.to_u32().unwrap() },
PropertyTag::Other(value) => { value },
}
}
}

impl TryFrom<TPM2_PT> for PropertyTag {
type Error = Error;
fn try_from(tpm_pt: TPM2_PT) -> Result<PropertyTag> {
PropertyTag::from_u32(tpm_pt).ok_or_else(|| {
error!("value = {} did not match any PropertyTag.", tpm_pt);
Error::local_error(WrapperErrorKind::InvalidParam)
})
match PrimitivePropertyTag::from_u32(tpm_pt) {
Some(x) => { Ok(PropertyTag::PrimitivePropertyTag(x)) },
None => { Ok(PropertyTag::Other(tpm_pt)) },
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ impl TryFrom<CreateCommandOutputHandler> for CreateKeyResult {

let creation_ticket_owned =
unsafe { take_from_esys(ffi_data_handler.ffi_creation_ticket_ptr)? };
ffi_data_handler.ffi_creation_ticket_ptr = null_mut();
//#[allow(unused_assignments)]
//ffi_data_handler.ffi_creation_ticket_ptr = null_mut();

Ok(CreateKeyResult {
out_private: Private::try_from(out_private_owned)?,
Expand Down
1 change: 1 addition & 0 deletions tss-esapi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
missing_copy_implementations,
rustdoc::broken_intra_doc_links,
)]
#![feature(stmt_expr_attributes)]

//! # TSS 2.0 Rust Wrapper over Enhanced System API
//! This crate exposes the functionality of the TCG Software Stack Enhanced System API to
Expand Down
1 change: 1 addition & 0 deletions tss-esapi/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ macro_rules! impl_mu_complex {

// Make the macros usable outside of the module.
pub(crate) use impl_marshall_trait;
#[allow(unused_imports)]
pub(crate) use impl_mu_aliases;
pub(crate) use impl_mu_complex;
pub(crate) use impl_mu_simple;
Expand Down
10 changes: 5 additions & 5 deletions tss-esapi/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//! type name. Unions are converted to Rust `enum`s by dropping the `TPMU` qualifier and appending
//! `Union`.
use crate::attributes::ObjectAttributesBuilder;
use crate::constants::PropertyTag;
use crate::constants::{PropertyTag,PrimitivePropertyTag};
use crate::interface_types::{
algorithm::{HashingAlgorithm, PublicAlgorithm},
ecc::EccCurve,
Expand Down Expand Up @@ -248,10 +248,10 @@ fn tpm_int_to_string(num: u32) -> String {
pub fn get_tpm_vendor(context: &mut Context) -> Result<String> {
// Retrieve the TPM property values
Ok([
PropertyTag::VendorString1,
PropertyTag::VendorString2,
PropertyTag::VendorString3,
PropertyTag::VendorString4,
PropertyTag::PrimitivePropertyTag(PrimitivePropertyTag::VendorString1),
PropertyTag::PrimitivePropertyTag(PrimitivePropertyTag::VendorString2),
PropertyTag::PrimitivePropertyTag(PrimitivePropertyTag::VendorString3),
PropertyTag::PrimitivePropertyTag(PrimitivePropertyTag::VendorString4),
]
.iter()
// Retrieve property values
Expand Down