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

More flexible file hashing support #991

Closed

Conversation

joshuagl
Copy link
Member

@joshuagl joshuagl commented Mar 5, 2020

Please fill in the fields below to submit a pull request. The more information
that is provided, the better.

Fixes issue #:

Description of the changes being introduced by the pull request:

  • Don't use securesystemslib.settings.HASH_ALGORITHMS for file hashing – doing so is poor cohesion and overloading a setting meant for key hashing
  • Add a new tuf.settings.FILE_HASHING_ALGORITHM for file hashing
  • Use tuf.settings.FILE_HASHING_ALGORITHM for hashes in timestamp and targets metadata

Please verify and check that the pull request fulfills the following
requirements
:

  • 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

Using securesystemslib.settings.HASH_ALGORITHMS is undersirable, because
it binds tuf to an implementation detail of the underlying library.
In this specific instance of file hashing algorithms it's even more
undesirable because it's overloading the intended use of the setting
which is "algorithm(s) [...] used to generate key IDs".

Add a new setting tuf.settings.FILE_HASH_ALGORITHMS, with a default
value of ['sha256', 'sha512'] (that matches the current value of
securesystemslib.settings.HASH_ALGORITHMS), to be used for file
hashing operations in tuf.

Signed-off-by: Joshua Lock <[email protected]>
Timestamp.json includes a METAFILES entry for snapshot.json. METAFILES
includes HASHES:
"HASHES is the dictionary that specifies one or more hashes, including the
cryptographic hash function. For example: { "sha256": HASH, ... }."

We've been hard-coding this to a single sha256 hash, as that's the default
algorithms argument of securesystemlib.util.get_file_details() -- this
feels wrong. Change to using the new tuf.settings.FILE_HASH_ALGORITHMS
setting.

Signed-off-by: Joshua Lock <[email protected]>
@@ -1531,7 +1531,8 @@ def generate_timestamp_metadata(snapshot_filename, version, expiration_date,

# Retrieve the versioninfo of the Snapshot metadata file.
snapshot_fileinfo = {}
length, hashes = securesystemslib.util.get_file_details(snapshot_filename)
length, hashes = securesystemslib.util.get_file_details(snapshot_filename,
tuf.settings.FILE_HASH_ALGORITHMS)
Copy link
Member Author

Choose a reason for hiding this comment

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

I couldn't see any reason in the spec not to use the same hashing algorithms here as we do in targets?

Copy link
Contributor

Choose a reason for hiding this comment

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

That's my reading as well. The more consistency in algorithm selection between roles the better, IMO.

@joshuagl
Copy link
Member Author

joshuagl commented Mar 6, 2020

I'm closing this pull request because I don't want the branch name 'dirtyhack' to live in perpetuity in the merge commit. This didn't end up being such a dirty hack after-all.

@joshuagl joshuagl closed this Mar 6, 2020
@joshuagl joshuagl deleted the joshuagl/dirtyhack branch August 10, 2021 08:32
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.

3 participants