-
Notifications
You must be signed in to change notification settings - Fork 58
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
Implements TPM vendor check function #113
Conversation
This change implements a means to check the vendor of the TPM. The main use for this function is to establish if we are using a software based TPM and in turn warn that no hardware root of trust is available
src/tpm.rs
Outdated
use tss_esapi::tss2_esys::{ESYS_TR, ESYS_TR_NONE, ESYS_TR_RH_OWNER}; | ||
use tss_esapi::Context; | ||
use tss_esapi::Tcti; | ||
|
||
fn int_to_str(num: u32) -> String { |
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.
Function name
This is really moving to a String
rather than str
fn int_to_str(num: u32) -> String { | |
fn int_to_string(num: u32) -> String { |
Possibly simpler implementation
fn int_to_string(num: u32) -> String {
num.to_string()
}
Or directly using to_string()
😄
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.
Well, it's not really a standard integer-to-string operation. It's basically parsing every byte in a u32
(i.e. up to 4 bytes) as a different ascii character. Because that's how TPM does strings.
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.
(Renaming to int_to_string
is reasonable though)
} | ||
} | ||
|
||
let mut vend_strs: String = [ |
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.
nit: My brain turns to mush when I see many map/filter/etc.. statements on something. Consider adding a comment explaining what's going on here for folks like me 😆.
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.
Yeah, sorry. Let me explain what's going on, so Luke can add comments.
This basically first uses a set of constants (TPM2_PT_VENDOR_STRING_{1,2,3,4}
) as lookup indexes into allprops
, to get all the values from there where they're set. After that, it removes the values that don't exist (is_some
), removes the Option<_>
wrappers (unwrap()
), removes the items that are actually a value (i.e. != && 0
), then puts the individual parts to a different through int_to_str
to get a Vec<String>
with the parts, and then makes a single string from them (.join("")
).
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.
I added comments. in time we can move this into a helper function (if they all need the some manipulation)
src/tpm.rs
Outdated
* software TPM as opposed to hardware TPM. | ||
*/ | ||
pub fn get_tpm_vendor() -> Result<String, tss_esapi::Error> { | ||
let mut ctx = get_tpm2_ctx()?; |
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.
I think you want to get the context in main()
and pass that one through to here as &mut Context
.
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.
LGTM other than the rust format warning in CI
After speaking with @puiterwijk , I will close this and he will follow up with a patch implementing the same, but using his new error code contained within PR #121 |
This change implements a means to check the vendor of the TPM.
The main use for this function is to establish if we are using
a software based TPM and in turn warn that no hardware root of
trust is available