Skip to content

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

Merged
jku merged 2 commits into
theupdateframework:developfrom
jku:verify-in-key
Jun 9, 2021
Merged

Metadata API: implement sig verification in Key, store id in key#1423
jku merged 2 commits into
theupdateframework:developfrom
jku:verify-in-key

Conversation

@jku

@jkujku commented May 28, 2021

Copy link
Copy Markdown
Member

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

@jkujku mentioned this pull request Jun 2, 2021
3 tasks

@sechkovasechkova left a comment

Copy link
Copy Markdown
Contributor

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.

Comment threadtuf/api/metadata.py Outdated
Comment threadtests/test_api.py
Comment threadtuf/api/metadata.py Outdated
@jku

jku commented Jun 3, 2021

Copy link
Copy Markdown
MemberAuthor

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

@joshuagljoshuagl left a comment

Copy link
Copy Markdown
Member

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

jku commented Jun 7, 2021

Copy link
Copy Markdown
MemberAuthor

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

@joshuagljoshuagl left a comment

Copy link
Copy Markdown
Member

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

jku commented Jun 8, 2021

Copy link
Copy Markdown
MemberAuthor

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:developJun 9, 2021
@jku
jku deleted the verify-in-key branch December 30, 2024 09:09
Sign up for freeto 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

@jku@joshuagl@sechkova