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

fix tpm2_ptool destroy command failures #883

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Vasu77df
Copy link

@Vasu77df Vasu77df commented Feb 1, 2025

The current tpm2_ptool destroy command does not work as intended and does not remove the persistent object

Current behavior:

❯ sudo tpm2_ptool init
action: Created
id: 1

❯ sudo tpm2_ptool destroy --pid=1
This will delete the primary object of id "1" and all associated data from db under "/root/.tpm2_pkcs11" [y/N] y
Traceback (most recent call last):
  File "/usr/bin/tpm2_ptool", line 33, in <module>
    sys.exit(load_entry_point('tpm2-pkcs11-tools==1.33.7', 'console_scripts', 'tpm2_ptool')())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/tpm2_pkcs11/tpm2_ptool.py", line 26, in main
    commandlet.init('A tool for manipulating the tpm2-pkcs11 database')
  File "/usr/lib/python3/dist-packages/tpm2_pkcs11/command.py", line 102, in init
    commandlet.get()[d['which']](d)
  File "/usr/lib/python3/dist-packages/tpm2_pkcs11/commandlets_store.py", line 202, in __call__
    tr_file = bytes_to_file(pobj['handle'], d)
                            ~~~~^^^^^^^^^^
IndexError: No item with that key

Updated behavior with this PR:

❯ sudo tpm2_ptool destroy --pid=1
This will delete the primary object of id "1" and all associated data from db under "/root/.tpm2_pkcs11" [y/N] y
❯ echo $?
0

This fixes two issues:

  • bytes_to_file function is replaced by get_pobject
  • and we introduce a new evictcontrol method to handle removing of the persistent object
    • With the current logic tpm2_evictcontrol was passed an object and a handle even for a remove action.
    • We introduce a new method evictcontrol_remove to handle just removing persistent objects
      • I am not too familiar with this code, and TPM2, just in the process of learning my way around, please let me know if there's a better approach.

Thank you!

Signed-off-by: vasuper <vasu3797@gmail.com>
@Vasu77df
Copy link
Author

quick bump for a review

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.

1 participant