-
Notifications
You must be signed in to change notification settings - Fork 281
ngclient rollback improvements #1524
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
Merged
jku
merged 4 commits into
theupdateframework:develop
from
jku:ngclient-rollback-improvements
Aug 24, 2021
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -178,6 +178,10 @@ def update_root(self, data: bytes): | |||||||
def update_timestamp(self, data: bytes): | ||||||||
"""Verifies and loads 'data' as new timestamp metadata. | ||||||||
|
||||||||
Note that an expired intermediate timestamp is considered valid so it | ||||||||
can be used for rollback checks on newer, final timestamp. Expiry is | ||||||||
only checked for the final timestamp in update_snapshot(). | ||||||||
|
||||||||
Args: | ||||||||
data: unverified new timestamp metadata as bytes | ||||||||
|
||||||||
|
@@ -227,15 +231,19 @@ def update_timestamp(self, data: bytes): | |||||||
self.timestamp.signed.meta["snapshot.json"].version, | ||||||||
) | ||||||||
|
||||||||
if new_timestamp.signed.is_expired(self.reference_time): | ||||||||
raise exceptions.ExpiredMetadataError("New timestamp is expired") | ||||||||
# expiry not checked to allow old timestamp to be used for rollback | ||||||||
# protection of new timestamp: expiry is checked in update_snapshot() | ||||||||
|
||||||||
self._trusted_set["timestamp"] = new_timestamp | ||||||||
logger.debug("Updated timestamp") | ||||||||
|
||||||||
def update_snapshot(self, data: bytes): | ||||||||
"""Verifies and loads 'data' as new snapshot metadata. | ||||||||
|
||||||||
Note that an expired intermediate snapshot is considered valid so it | ||||||||
can be used for rollback checks on newer, final snapshot. Expiry is | ||||||||
only checked for the final snapshot in update_delegated_targets(). | ||||||||
|
||||||||
Args: | ||||||||
data: unverified new snapshot metadata as bytes | ||||||||
|
||||||||
|
@@ -250,6 +258,11 @@ def update_snapshot(self, data: bytes): | |||||||
raise RuntimeError("Cannot update snapshot after targets") | ||||||||
logger.debug("Updating snapshot") | ||||||||
|
||||||||
# Local timestamp was allowed to be expired to allow for rollback | ||||||||
# checks on new timestamp but now timestamp must not be expired | ||||||||
if self.timestamp.signed.is_expired(self.reference_time): | ||||||||
raise exceptions.ExpiredMetadataError("timestamp.json is expired") | ||||||||
|
||||||||
meta = self.timestamp.signed.meta["snapshot.json"] | ||||||||
|
||||||||
# Verify against the hashes in timestamp, if any | ||||||||
|
@@ -301,8 +314,8 @@ def update_snapshot(self, data: bytes): | |||||||
f"{new_fileinfo.version}, got {fileinfo.version}." | ||||||||
) | ||||||||
|
||||||||
if new_snapshot.signed.is_expired(self.reference_time): | ||||||||
raise exceptions.ExpiredMetadataError("New snapshot is expired") | ||||||||
# expiry not checked to allow old snapshot to be used for rollback | ||||||||
# protection of new snapshot: expiry is checked in update_targets() | ||||||||
|
||||||||
self._trusted_set["snapshot"] = new_snapshot | ||||||||
logger.debug("Updated snapshot") | ||||||||
|
@@ -336,6 +349,11 @@ def update_delegated_targets( | |||||||
if self.snapshot is None: | ||||||||
raise RuntimeError("Cannot load targets before snapshot") | ||||||||
|
||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Maybe it will be even clearer if we add the steps numbers of the client workflow? |
||||||||
# Local snapshot was allowed to be expired to allow for rollback | ||||||||
# checks on new snapshot but now snapshot must not be expired | ||||||||
if self.snapshot.signed.is_expired(self.reference_time): | ||||||||
raise exceptions.ExpiredMetadataError("snapshot.json is expired") | ||||||||
|
||||||||
delegator: Optional[Metadata] = self.get(delegator_name) | ||||||||
if delegator is None: | ||||||||
raise RuntimeError("Cannot load targets before delegator") | ||||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Maybe it will be even clearer if you add the step number of the client workflow?
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.
It would but unfortunately it also requires keeping these numbers updated with spec changes... so I'm more inclined to remove the step numbers I did use in the PR then I am to add more of them.