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

Add a TPM provider #75

Merged
merged 1 commit into from
Dec 13, 2019
Merged

Add a TPM provider #75

merged 1 commit into from
Dec 13, 2019

Conversation

hug-dev
Copy link
Member

@hug-dev hug-dev commented Dec 6, 2019

This provider uses the tss-esapi crate to interface with a TSS 2.0
Enhanced System library.
Adds new configuration entries to select the TPM provider and which
TCTI device to use.
The TPM provider currently only supports RSA key, signing and verifying
operations.

Co-authored-by: Ionut Mihalcea ionut.mihalcea@arm.com
Signed-off-by: Hugues de Valon hugues.devalon@arm.com

@hug-dev hug-dev added the enhancement New feature or request label Dec 6, 2019
@hug-dev hug-dev requested a review from ionut-arm December 6, 2019 10:27
@hug-dev hug-dev self-assigned this Dec 6, 2019
@hug-dev
Copy link
Member Author

hug-dev commented Dec 6, 2019

The tss-esapi crate that is built by default, expect the TSS 2.0 to be installed on the system at a fixed location. For example the headers at /usr/local/include/tss2/, as per our build script.
That's why this PR fails on the CI, as TSS is not installed. It will also fail for users when they try to do a cargo build as the TPM Provider is a default feature.

Possible solutions that I see:

  1. remove the TPM providers as default features and make sure they all compile when they are selected individually. That would be a short term solution and is definitely needed (the second part).
  2. instead of linking TSS 2.0 at link time, we could dynamically load the library using libloading as it is done for PKCS 11. We would then have to write the interface by hand or maybe there is a way to use bindgen for that as well. The library path would be in the configuration as well.
  3. Execute the CI inside a Dockerfile that contains the needed file. We can have one Dockerfile that contains Mbed Crypto, PKCS 11 simulation and the TPM server.

I think 1. and 3. are definitely needed for now and we can look at 2. later.

@hug-dev
Copy link
Member Author

hug-dev commented Dec 6, 2019

#76 addresses point 1

@hug-dev
Copy link
Member Author

hug-dev commented Dec 6, 2019

Check rust-lang/rust-bindgen#1541 for point 2.

@hug-dev hug-dev force-pushed the tpm branch 3 times, most recently from ee2dd04 to 234df81 Compare December 12, 2019 16:59
@hug-dev
Copy link
Member Author

hug-dev commented Dec 12, 2019

Executed ./all.sh locally and all tests passed 😄 We will need to put tests on the CI as well!

Copy link
Member

@ionut-arm ionut-arm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏 Impressive

.expect("ESAPI Context lock poisoned");

let len = hash.len();
if len > 64 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally this should take into account the digest size of the hash algorithm that the key is created with - I think we actually have hash algorithms assigned to keys, maybe we can do something between the TPM crate and the provider to be able to get the public definition of the key and deduce from that the correct length

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for sign, of course

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, these checks could be left to the crate to do by itself (which it actually is doing atm)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is not it fine at the moment as we are supporting only one kind of hash algorithm?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about that! We actually support any hash algorithm, at least with Mbed Crypto; but it depends on what people want from us

.expect("ESAPI Context lock poisoned");

let (key_context, auth_value) = esapi_context
.create_rsa_signing_key(key_size, AUTH_VAL_LEN)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if creating an "RSA key definition structure" and passing that here is more sensible. We should be setting the hash algorithm, for example.

Maybe we could have a method like create_signing_key which takes in an enum (RSA or ECC) and the enum contains the other params as well... Don't know, really

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is fine for now as we are limiting the scope of things that we support.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. We'll have to see how to manage that for the TPM crate, though

This provider uses the tss-esapi crate to interface with a TSS 2.0
Enhanced System library.
Adds new configuration entries to select the TPM provider and which
TCTI device to use.
The TPM provider currently only supports RSA key, signing and verifying
operations.

Co-authored-by: Ionut Mihalcea <ionut.mihalcea@arm.com>
Signed-off-by: Hugues de Valon <hugues.devalon@arm.com>
key_triple: KeyTriple,
password_context: PasswordContext,
) -> Result<()> {
let error_storing = |e| {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!!! I actually believe this could be moved to be something surfaced by the KeyIdManager - apart from the text everything seems general, maybe the KIM could do this before returning to the providers?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for many of the or_else handlers in here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thing is that the KeyIDManager returns a String in its Err variant, so we would still need an or_else to convert it to ResponseStatus :/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but we could do that in the manager itself

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, got it now, that is a good idea!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will create an issue.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In #77

Copy link
Member

@ionut-arm ionut-arm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yay! Parsec with TPM finally working fo' real 👍

@hug-dev hug-dev merged commit faf801b into parallaxsecond:master Dec 13, 2019
@hug-dev hug-dev deleted the tpm branch December 13, 2019 11:07
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
Development

Successfully merging this pull request may close these issues.

2 participants