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 duplication example #460

Conversation

Firstyear
Copy link
Contributor

This adds an example of duplication.

As usual - it's broken. I can't seem to work out why, and I was literally copy-pasting as much as possible from this projects own test cases. So any assistance to get this sorted out and over the line would be great.

@ionut-arm
Copy link
Member

I believe @wiktor-k might have some working examples or abstractions built to handle something like this - hope I'm not remembering wrong!

@wiktor-k
Copy link
Collaborator

wiktor-k commented Oct 18, 2023

Yep, you're right Ionut. I think one example is right in the doctests of the duplicate function. If there are any problems digging it out I'll take a look tomorrow morning.

@wiktor-k
Copy link
Collaborator

Btw, check out this tiny example (that should be working).

@Firstyear
Copy link
Contributor Author

I think this example is pretty much the same as the one I copied from in the duplication tests (except that the test uses ecc not rsa https://github.com/parallaxsecond/rust-tss-esapi/blob/main/tss-esapi/tests/integration_tests/context_tests/tpm_commands/duplication_commands_tests.rs ). But it has a significant flaw, an that is that you are duplicating from a primary to the same primary. It's not actually testing or demonstrating moving between two separate keys.

Additionally, the example I'm trying to make is mean to be for simulating or demonstrating if you have a specific duplication key below a primary, rather than duplicating between the primaries.

So that's part of why I want to get this example to work - Because it certainly looks like it's exposing some bugs or flaws in functions like new_restricted_decryption_key ( https://github.com/parallaxsecond/rust-tss-esapi/pull/460/files#diff-aee362f84ca982e9226800f9ca6cec55b4c53d5e846af0bb475beb7d109bc74dR180 ) which per the docs state: "Create parameters for a restricted decryption key (i.e. a storage key)" (https://github.com/parallaxsecond/rust-tss-esapi/blob/main/tss-esapi/src/structures/tagged/public/ecc.rs#L37)

@wiktor-k
Copy link
Collaborator

Just out of curiosity have you tried using RSA keys instead of ECC to see if the example passes? EC keys may have additional requirements for restricted decryption (like KDF specification). I mean: just to take the new_restricted_decryption_key out of the test and see if you can progress. And if so, then fixing new_restricted_decryption_key.

@Firstyear
Copy link
Contributor Author

Firstyear commented Oct 20, 2023

Okay, I sorted out the restricted decryption key issues - turns out it was my own silly fault!

Anyway, just down to the policy failure with duplication now. Going to re-read your examples to check but I think they're correct.

EDIT: The policy I was using was correct and the same as the duplication test, but your example uses an authValue based policy instead (which I actually prefer!). So I have adapted my code to use this, but it still fails in the same way.

⚠️ TSS Layer: TPM, Code: 0x0000099D, Message: A policy check failed (associated with session number 1).

@Firstyear
Copy link
Contributor Author

@wiktor-k Can I get a re-review on this? Still stuck here with the duplication key :(

@wiktor-k
Copy link
Collaborator

@wiktor-k Can I get a re-review on this? Still stuck here with the duplication key :(

Sorry for the delay, you know how it is in free-time open-source side-projects 😅

I'll try to take a look early next week and thanks for the ping! 🙏

@Firstyear
Copy link
Contributor Author

@wiktor-k Can I get a re-review on this? Still stuck here with the duplication key :(

Sorry for the delay, you know how it is in free-time open-source side-projects 😅

Very much so 😅

I'll try to take a look early next week and thanks for the ping! 🙏

Thank you so much for your help!

@Firstyear Firstyear force-pushed the 20231018-add-key-duplication-example branch from 38ca201 to 0e84703 Compare January 4, 2024 03:12
@Firstyear Firstyear force-pushed the 20231018-add-key-duplication-example branch from 0e84703 to 2d859d9 Compare April 3, 2024 03:33
@Firstyear
Copy link
Contributor Author

@wiktor-k Okay I re-read your comments multiple times, I've been reading section 23 about duplication of the spec and I still can not get this to work. I'm completely stumped now what I have done wrong here. I think I really need you or someone else to send me a diff or PR on what to change because I think this is beyond my ability :(

@Firstyear Firstyear force-pushed the 20231018-add-key-duplication-example branch from 2d859d9 to 1188c6d Compare April 8, 2024 02:44
@Firstyear
Copy link
Contributor Author

@ionut-arm @wiktor-k @Superhepper Okay, after lots of help from all of you this example now works! Thank you all so much!

I have rebased to main, squashed and signed off. I have also updated the duplication example to be "with_encrypted_duplication(true)" and for bonus, I added a second example which is duplication using inner wrappers only showing how to duplicate against TPM2_RH_NULL.

@Firstyear Firstyear force-pushed the 20231018-add-key-duplication-example branch from 1188c6d to f4b2b41 Compare April 8, 2024 02:48
This adds two examples demonstrating encrypted duplication and secret (inner) wrapper
duplication only. As usual these examples are well commented and tested. They wouldn't
have been possible without a lot of help from the community ❤️

Signed-off-by: William Brown <william.brown@suse.com>
@Firstyear Firstyear force-pushed the 20231018-add-key-duplication-example branch from f4b2b41 to 1ed2ded Compare April 8, 2024 03:04
Copy link
Collaborator

@Superhepper Superhepper left a comment

Choose a reason for hiding this comment

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

Excellent work!

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.

🚀

@ionut-arm ionut-arm merged commit fde17bb into parallaxsecond:main Apr 8, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants