-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
20240604 506 create loaded #529
Draft
Firstyear
wants to merge
5
commits into
parallaxsecond:main
Choose a base branch
from
Firstyear:20240604-506-create-loaded
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+463
−8
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
tss-esapi/src/context/tpm_commands/object_commands/create_loaded_command_input.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// Copyright 2024 Contributors to the Parsec project. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use crate::{ | ||
ffi::data_zeroize::FfiDataZeroize, | ||
handles::KeyHandle, | ||
structures::{Auth, Public, SensitiveCreate, SensitiveData}, | ||
tss2_esys::{ESYS_TR, TPM2B_SENSITIVE_CREATE, TPM2B_TEMPLATE}, | ||
Result, | ||
}; | ||
use std::convert::TryInto; | ||
use zeroize::Zeroize; | ||
|
||
/// Struct that handles the input of the | ||
/// to the Esys_CreateLoaded command and zeroizes | ||
/// the data when it gets dropped. | ||
pub struct CreateLoadedCommandInputHandler { | ||
ffi_in_parent_handle: ESYS_TR, | ||
ffi_in_sensitive: TPM2B_SENSITIVE_CREATE, | ||
// Per Part 3 12.9.1 note 1: | ||
// In the general descriptions of TPM2_Create() and TPM2_CreatePrimary() the validations refer to a | ||
// TPMT_PUBLIC structure that is in inPublic. For TPM2_CreateLoaded(), inPublic is a | ||
// TPM2B_TEMPLATE that may contain a TPMT_PUBLIC that is used for object creation. For object | ||
// derivation, the unique field can contain a label and context that are used in the derivation process. | ||
// To allow both the TPMT_PUBLIC and the derivation variation, a TPM2B_TEMPLATE is used. When | ||
// referring to the checks in TPM2_Create() and TPM2_CreatePrimary(), TPM2B_TEMPLATE should | ||
// be assumed to contain a TPMT_PUBLIC. | ||
ffi_in_public: TPM2B_TEMPLATE, | ||
} | ||
|
||
impl CreateLoadedCommandInputHandler { | ||
/// Creates the CreateLoadedCommandInputHandler from the inputs | ||
/// of the 'create' [crate::Context] method. | ||
/// | ||
/// # Details | ||
/// Consumes the input parameters and converts them into their | ||
/// TSS counterpart and zeroizes all the data when dropped. | ||
/// | ||
/// # Arguments | ||
/// See the input arguments of 'crate' [crate::Context] method. | ||
/// | ||
/// # Returns | ||
/// The created CreateLoadedCommandInputHandler. | ||
/// | ||
/// # Errors | ||
/// WrapperErrors if the conversions to the TSS types fails. | ||
pub(crate) fn create( | ||
parent_handle: KeyHandle, | ||
auth_value: Option<Auth>, | ||
sensitive_data: Option<SensitiveData>, | ||
public: Public, | ||
) -> Result<Self> { | ||
Ok(Self { | ||
ffi_in_parent_handle: parent_handle.into(), | ||
ffi_in_sensitive: SensitiveCreate::new( | ||
auth_value.unwrap_or_default(), | ||
sensitive_data.unwrap_or_default(), | ||
) | ||
.try_into()?, | ||
ffi_in_public: public.try_into()?, | ||
}) | ||
} | ||
|
||
/// The 'parentHandle' input parameter | ||
pub const fn ffi_in_parent_handle(&self) -> ESYS_TR { | ||
self.ffi_in_parent_handle | ||
} | ||
|
||
/// The 'inSensitive' input parameter. | ||
pub const fn ffi_in_sensitive(&self) -> &TPM2B_SENSITIVE_CREATE { | ||
&self.ffi_in_sensitive | ||
} | ||
|
||
/// The 'inPublic' input parameter. | ||
pub const fn ffi_in_public(&self) -> &TPM2B_TEMPLATE { | ||
&self.ffi_in_public | ||
} | ||
} | ||
|
||
impl Zeroize for CreateLoadedCommandInputHandler { | ||
fn zeroize(&mut self) { | ||
self.ffi_in_parent_handle.zeroize(); | ||
self.ffi_in_sensitive.ffi_data_zeroize(); | ||
self.ffi_in_public.ffi_data_zeroize(); | ||
} | ||
} | ||
|
||
impl Drop for CreateLoadedCommandInputHandler { | ||
fn drop(&mut self) { | ||
self.zeroize(); | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
tss-esapi/src/context/tpm_commands/object_commands/create_loaded_command_output.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// Copyright 2024 Contributors to the Parsec project. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use crate::{ | ||
handles::ObjectHandle, | ||
structures::{CreateLoadedKeyResult, Private, Public}, | ||
tss2_esys::{ESYS_TR, TPM2B_PRIVATE, TPM2B_PUBLIC}, | ||
Error, Result, | ||
}; | ||
use std::convert::TryFrom; | ||
use std::ptr::null_mut; | ||
|
||
/// Struct that handles the output of the | ||
/// Create Esys_CreateLoaded command and zeroizes | ||
/// the FFI data. | ||
pub(crate) struct CreateLoadedCommandOutputHandler { | ||
ffi_out_object_handle: ESYS_TR, | ||
// object | ||
ffi_out_public_ptr: *mut TPM2B_PUBLIC, | ||
ffi_out_private_ptr: *mut TPM2B_PRIVATE, | ||
// name | ||
// ffi_out_name_ptr: *mut TPM2B_NAME, | ||
} | ||
|
||
/// Creates a new CreateLoadedCommandOutputHandler | ||
impl CreateLoadedCommandOutputHandler { | ||
pub(crate) fn new() -> Self { | ||
let ffi_out_object_handle = ObjectHandle::None.into(); | ||
Self { | ||
ffi_out_object_handle, | ||
ffi_out_public_ptr: null_mut(), | ||
ffi_out_private_ptr: null_mut(), | ||
// ffi_out_name_ptr: null_mut(), | ||
} | ||
} | ||
|
||
/// A reference to the where 'objectHandle' output parameter pointer shall be stored. | ||
pub fn ffi_out_object_handle(&mut self) -> &mut ESYS_TR { | ||
&mut self.ffi_out_object_handle | ||
} | ||
|
||
/// A reference to the where 'outPrivate' output parameter pointer shall be stored. | ||
pub fn ffi_out_private_ptr(&mut self) -> &mut *mut TPM2B_PRIVATE { | ||
&mut self.ffi_out_private_ptr | ||
} | ||
|
||
/// A reference to the where 'outPublic' output parameter pointer shall be stored. | ||
pub fn ffi_out_public_ptr(&mut self) -> &mut *mut TPM2B_PUBLIC { | ||
&mut self.ffi_out_public_ptr | ||
} | ||
|
||
/* | ||
/// A reference to the where 'name' output parameter pointer shall be stored. | ||
pub fn ffi_out_name_ptr(&mut self) -> &mut *mut TPM2B_NAME { | ||
&mut self.ffi_out_name_ptr | ||
} | ||
*/ | ||
} | ||
|
||
impl TryFrom<CreateLoadedCommandOutputHandler> for CreateLoadedKeyResult { | ||
type Error = Error; | ||
|
||
fn try_from( | ||
ffi_data_handler: CreateLoadedCommandOutputHandler, | ||
) -> Result<CreateLoadedKeyResult> { | ||
let object_handle = ObjectHandle::from(ffi_data_handler.ffi_out_object_handle); | ||
|
||
let out_private_owned = | ||
crate::ffi::to_owned_with_zeroized_source(ffi_data_handler.ffi_out_private_ptr); | ||
let out_public_owned = | ||
crate::ffi::to_owned_with_zeroized_source(ffi_data_handler.ffi_out_public_ptr); | ||
|
||
// let out_name_owned = | ||
// crate::ffi::to_owned_with_zeroized_source(ffi_data_handler.ffi_out_name_ptr); | ||
|
||
Ok(CreateLoadedKeyResult { | ||
object_handle, | ||
out_private: Private::try_from(out_private_owned)?, | ||
out_public: Public::try_from(out_public_owned)?, | ||
// out_name: Name::try_from(out_name_owned)?, | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really not my area of expertise but it seems to me as it is not as simple as setting the object attributes of the key. The kind of object you create will depend on the object attributes of its parent not only the object attributes of the object it self.
Look at
TCG TPM2, r1p59, Part3 Commands, Section 12.9.1
Hrmm but the error code suggests:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I did read that section. The problem I hit was that part 3 12.9.1 doesn't actually define a derivation parent - that's actually defined in part 1 4.19 as "loadable key used to derive other keys; a TPM_ALG_KEYEDHASH Parent Key" and part 1 25.1.5 table 24 states "Asymmetric keys and
symmetric keys with these attributes are Storage Parents, and hash objects with these attributes are
Derivation Parents. " where the attributes are sign=clear, decrypt=set, restricted=set.
I think the comment I wrote here needs to be updated to reflect this, but I still think the attributes I used on the key were correct :)