-
Notifications
You must be signed in to change notification settings - Fork 278
Improve verification results #2551
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
Improve verification results #2551
Conversation
This is an API break as VerificationResult changes: * Now contains threshold * Now contains Keys and not just keyids Note that there is a small edge case functionality change: * if the role does not have a key for the keyid, then we no longer include that key in "unsigned" I think that is an acceptable change. Signed-off-by: Jussi Kukkonen <[email protected]>
This is a thin wrapper over two VerificationResults: useful when verifying root signatures. Now the API for getting verification results for root and the API for getting the results for other metadata is different. Client use cases can continue using verify_delegate() so should not be affected. Signed-off-by: Jussi Kukkonen <[email protected]>
Changes are * expected result changes (like the handling of keyids without keys) * test refactoring to have access to the Key * Removal of union test * use the fact that VerificationResult is Truthy in asserts (to get 1 more line of coverage) Signed-off-by: Jussi Kukkonen <[email protected]>
This does much the same tests as test_signed_get_verification_result() above it does, just using two root roles. Signed-off-by: Jussi Kukkonen <[email protected]>
505e6d1
to
cd0fd5c
Compare
Still wondering if it would be useful for the two result types to have a common base type, instead of being just duck typed to feel similar. The way I see a signing tool or repository UI using these is this:
So maybe it is fine for the app to have something like
I would maybe rather not create some complicated inheritance (and inevitably large classes) when the dataclasses look like they might just work like that... |
dict unions are only supported in 3.9. Signed-off-by: Jussi Kukkonen <[email protected]>
Now that VerificationResult has threshold, this can be simpler. Signed-off-by: Jussi Kukkonen <[email protected]>
Pull Request Test Coverage Report for Build 7785217570
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks very helpful. Let me try it in RSTUF and see if it really is.
WIP in theupdateframework/python-tuf#2551 There is still a bit of annoying work to do to get only those keys that will decrease the missing signatures count (see `keys_to_use`), or to deduplicate individual results (see `results_to_show`) but I am not sure if python-tuf can provide generally useful API for this. Signed-off-by: Lukas Puehringer <[email protected]>
WIP in theupdateframework/python-tuf#2551 Replaces clunky _validate_signature and _validate_threshold methods. This works nicely! Signed-off-by: Lukas Puehringer <[email protected]>
bb011ef
to
16f91eb
Compare
This is an example of using the verification resutls in a repository. The only remaining tricky part is in _get_verification_result(): * has to figure out the delegating metadata (something we currently cannot provide in repository.Repository for the general case) * Needs a special case for first root Signed-off-by: Jussi Kukkonen <[email protected]>
16f91eb
to
b8dbe30
Compare
I tried this in RSTUF and found it very helpful. I think adding a common base class would be okay. The inheritance model could look something like this. class VerificationResult:
verified: bool
signed: dict[str, Key]
unsigned: dict[str, Key]
class Single(VerificationResult):
threshold: int
class Combined(VerificationResult):
first: Single
second: Single But this does not add much value. The more interesting question is, if we want to provide other common behavior. Two things that I would have found useful:
|
Change the "other" argument to optional "previous" and handle the None case in code. Signed-off-by: Jussi Kukkonen <[email protected]>
Signed-off-by: Jussi Kukkonen <[email protected]>
The common base class probably looks more complicated: because Combined wants to override |
I'm not completely sold on these because :
We could add this to
|
Signed-off-by: Jussi Kukkonen <[email protected]>
This is helper to tell how many signatures are still required. Also change the order of Roots given to RootVerificationResult (this way first is version N, second is version N+1). Signed-off-by: Jussi Kukkonen <[email protected]>
Change tests so the previous root version is what the code expects. Signed-off-by: Jussi Kukkonen <[email protected]>
Signed-off-by: Jussi Kukkonen <[email protected]>
|
||
for keyid in role.keyids: | ||
try: | ||
key = self.get_key(keyid) | ||
except ValueError: | ||
unsigned.add(keyid) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. This means that in the new VerificationResult there might be role keyids that are neither in signed nor unsigned. That's probably okay. But should we mention it somewhere. Maybe in the PR description?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it is a change -- I think I mentioned it in the first commit message , can add to PR decription.
I was also considering just raising at this point (because clearly the role is in a bad state)... but then that sounds like punishing the delegated role signing for delegator metadata error -- an error that can still leave the delegated role capable of signing.
WIP in theupdateframework/python-tuf#2551 There is still a bit of annoying work to do to get only those keys that will decrease the missing signatures count (see `keys_to_use`), or to deduplicate individual results (see `results_to_show`) but I am not sure if python-tuf can provide generally useful API for this. Signed-off-by: Lukas Puehringer <[email protected]>
This is an attempt at fixing the verification result handling that has been found to not work well. This API is useful mostly to repository implementations: clients should likely keep using
verify_delegate()
Modify VerificationResult
union()
: this is now handled by the new RootVerificationResultdict[str, Key]
instead ofset[str]
for signed and unsignedAdd RootVerificationResult
Root.get_root_verification_result()
is provided as a straightforward way to get oneNote that
RootVerificationResult.signed
andRootVerificationResult.unsigned
assume that there are no keyid collisions between the two verifying roles (same keyid is not used for two different keys): This does not affectverified
status in any way (only thesigned
andunsigned
lists) so I think this is totally acceptable.So far the usage looks quite nice but I think we want to try to use this in an app or two to avoid redoing the mistake of the first VerificationResult...
Fixes #2544