Skip to content
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

[Improvement] Provide access to the Esys_TR_* methods. #47

Closed
Superhepper opened this issue Mar 20, 2020 · 10 comments · Fixed by #48
Closed

[Improvement] Provide access to the Esys_TR_* methods. #47

Superhepper opened this issue Mar 20, 2020 · 10 comments · Fixed by #48
Labels
enhancement New feature or request
Milestone

Comments

@Superhepper
Copy link
Collaborator

Superhepper commented Mar 20, 2020

I am trying to get the name from the object handle returned by LoadExternal. Normally I would do this by using Esys_TR_GetName. But that interface needs an esys_context and the esys_contetx is a private member of the tss_esapi::Context struct.

So it would be nice if there could be a way that I could access it by usng the tss_esapi construct struct.

One suggestion could be create a functions like thiis one:

pub fn tr_get_name(&mut self, handle: ESYS_TR) -> Result<TPM2B_NAME> {
    let mut name = null_mut();
    let ret = unsafe { 
        Esys_TR_GetName(
            self.mut_context(), 
            handle, 
            &mut name) 
    };
    let ret = Error::from_tss_rc(ret);
    if ret.is_success() {
        let name = unsafe { MBox::<TPM2B_NAME>::from_raw(name) };
        Ok(*name)
    } else {
        error!("Error in getting name: {}.", ret);
        Err(ret)
    }
}

But there might be draw backs with this that I have not considered.

@ionut-arm
Copy link
Member

Hi!

Indeed, not having access to the inner context could prove problematic for a while until a more comprehensive set of primitives is wrapped up in nice Rust code... Maybe we should make that publicly available for now, so that we don't become a bottleneck for low-level usage of the context.

Alternatively, that method looks good - if you want you can raise a PR and we'll get it merged and published relatively quickly :)

Or both!

@ionut-arm ionut-arm added the enhancement New feature or request label Mar 20, 2020
@ionut-arm ionut-arm added this to the Rustification milestone Mar 20, 2020
@ionut-arm
Copy link
Member

ionut-arm commented Mar 20, 2020

Looking at the code, I think the drawback would be that if access is given to the inner context, the user becomes responsible for explicitly destroying all resources it owns before dropping the context. Either that or we unwrap the context completely with something like

impl From<Context> for ESYS_CONTEXT {
    fn from(ctx: Context) -> Self {
        ...
    }
}

Not sure if it's possible, though, since what's kept inside Context is a *mut ESYS_CONTEXT, but maybe it's do-able. Or simply implementing that From for Mbox<ESYS_CONTEXT>, that would probably be safer.

@Superhepper
Copy link
Collaborator Author

Personally right now I do not have the need to access the inner context. I am just in need of getting access to the extra Esys_TR_* functions. I will see if I have the time to make a PR.

@ionut-arm
Copy link
Member

Is Esys_TR_GetName the only one on your mind? I have some time to make the PR today, let me know if you need other methods too

@Superhepper
Copy link
Collaborator Author

I do not have permissions to create a pr.

@Superhepper
Copy link
Collaborator Author

I am looking at some other methods as well. Would be nice to add while I am at it.

@ionut-arm
Copy link
Member

ionut-arm commented Mar 20, 2020

I do not have permissions to create a pr.

No permission to create PR or to push branches to this repo? We work with forks - you create a PR using a branch from your own fork of the repo

This was linked to pull requests Mar 20, 2020
@ionut-arm
Copy link
Member

I've also raised #49 to allow you to use the underlying ESYS_CONTEXT, however be aware that:

  • you have to also keep track of the TSS2_TCTI_CONTEXT, otherwise you'll lose connection to the TPM
  • it's advised (but not strictly necessary) to close the contexts once you're done with them

@ionut-arm
Copy link
Member

Just FYI, I'll tag another version and publish it to crates.io once my PR gets merged as well :)

Thank you for the change!

@Superhepper
Copy link
Collaborator Author

Nice that will be awsome.

tgonzalezorlandoarm pushed a commit to tgonzalezorlandoarm/rust-tss-esapi that referenced this issue Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
2 participants