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

Metadata API: implement sig verification in Key, store id in key #1423

Merged
merged 2 commits into from
Jun 9, 2021

Conversation

jku
Copy link
Member

@jku jku commented May 28, 2021

Fixes #1417

Adding id to Key class simplifies life for API users as usually a key needs its identifier: this is visible in how Root.add_key() becomes simpler and in how verify_signature() is now possible to implement in key without an additional id argument.

Moving verification to Key arguably also makes the API cleaner because including both "verify myself" and "verify a delegate with threshold" can look awkward in Metadata, and because the somewhat ugly Securesystemslib integration is now Key class implementation detail (see e.g. call to format_metadata_to_key()).

Returning bool on verify failure was found to confuse API users (both me and Teodora misused it the first time) and was arguably not a pythonic way to handle it: Now an exception is raised.

There are two issues in this code that are still unresolved:

I intend to fix these in the next weeks

  • The code follows the Code Style Guidelines
  • Tests have been added for the bug fix or new feature
  • Docs have been added for the bug fix or new feature

@jku jku mentioned this pull request Jun 2, 2021
3 tasks
Copy link
Contributor

@sechkova sechkova left a comment

Choose a reason for hiding this comment

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

As already mentioned in the issue, I am in favour of these changes.
Left some thoughts/questions as comments.

tuf/api/metadata.py Outdated Show resolved Hide resolved
tests/test_api.py Show resolved Hide resolved
tuf/api/metadata.py Outdated Show resolved Hide resolved
@jku
Copy link
Member Author

jku commented Jun 3, 2021

Changes based on Teodoras review:

  • Added a bit of docstring on key id
  • Removed the call to securesystemslib.keys.format_metadata_to_key(), added Key.to_securesystemslib_key() and used that instead

Copy link
Member

@joshuagl joshuagl left a comment

Choose a reason for hiding this comment

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

I know that it feels a bit repetitive/redundant in the API, but given the consistent use of the term keyid in the specification and in the code (i.e. Key.__init__() and Key.from_dict() both take a keyid parameter), would it make sense to rename Key.id -> Key.keyid?

@jku
Copy link
Member Author

jku commented Jun 7, 2021

I know that it feels a bit repetitive/redundant in the API, but given the consistent use of the term keyid in the specification and in the code (i.e. Key.__init__() and Key.from_dict() both take a keyid parameter), would it make sense to rename Key.id -> Key.keyid?

I would have called the arguments id as well but that shadows the builtin id() which feels wrong... so I guess with the spec-consistency argument that means you have a point: consistent use of keyid would make most sense

Copy link
Member

@joshuagl joshuagl left a comment

Choose a reason for hiding this comment

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

Other than id -> keyid, this LGTM.

Jussi Kukkonen added 2 commits June 7, 2021 13:20
This simplifies life for API users as usually a key needs its
identifier: this is already visible in how update() becomes simpler
in the API.

The downside is that 'from_dict()' now has two arguments (so arguably
the name is not great anymore but it still does _mostly_ the same job
as other from_dicts).

This is an API change, if a minor one.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
This is likely not needed by users of the API (as they are interested
in the higher level functionality "verify delegate metadata with
threshold of signatures").

Moving verify to Key makes the API cleaner because including both
"verify myself" and "verify a delegate with threshold" can look awkward
in Metadata, and because the ugly Securesystemslib integration is now
Key class implementation detail (see Key.to_securesystemslib_key()).

Also raise on verify failure instead of returning false: this was found
to confuse API users (and was arguably not a pythonic way to handle it).

* Name the function verify_signature() to make it clear what is being
  verified.
* Assume only one signature per keyid exists: see theupdateframework#1422
* Raise only UnsignedMetadataError (when no signatures or verify failure),
  the remaining lower level errors will be handled in theupdateframework#1351
* Stop using a "keystore" in tests for the public keys: everything we
  need is in metadata already

This changes API, but also should not be something API users want to
call in the future when "verify a delegate with threshold" exists.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
@jku
Copy link
Member Author

jku commented Jun 8, 2021

oh forgot to metnion: the only changes in the latest force push are renaming "key.id" to "key.keyid"

@jku jku merged commit de78251 into theupdateframework:develop Jun 9, 2021
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.

Metadata API: implement verify in Key, store id in key
3 participants