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

Remove internal use of securesystemslib.hash #977

Merged
merged 6 commits into from
Mar 20, 2025

Conversation

lukpueh
Copy link
Member

@lukpueh lukpueh commented Mar 19, 2025

fixes #943

fixes secure-systems-lab#943

* Internally, the features added by the module (i.e. custom blake name
  support, and file hashing) are not needed. Builtin hashlib is used now
  directly.

* External users port the relevant features into their code base:
  theupdateframework/python-tuf#2815
  in-toto/in-toto#861

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
@@ -180,7 +180,7 @@ def _get_hash_algorithm(public_key: Key) -> str:
)

# trigger UnsupportedAlgorithm if appropriate
Copy link
Member Author

Choose a reason for hiding this comment

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

This is now a ValueError, which breaks the API and is also inconsistent with above, where we raise an UnsupportedAlgorithmError for some unsupported algorithms. Same is true for other signers in this PR

I'll mark the PR as draft until I fix this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Turns out, other signers exhaustively check public key schemes prior to using the hash algorithm name. This menas UnsupportedAlgorithmError is not expected when a digest object is created in those signers.

d5016ae adds a similar scheme check to GCPSigner to make use of the already existing raise UnsupportedAlgorithmError, previously only used for invalid key types.

f5f162f proposes an alternative, less invasive but IMO more clunky fix, which just re-raises hashlib's exception as UnsupportedAlgorithmError.

Either way, we may want to consider a more comprehensive solution in #593 and #766.

lukpueh added 2 commits March 20, 2025 09:51
GCPSigner is expected to raise UnsupportedAlgorithmError, if the hash
algorithm encoded in scheme is invalid. Switching from
securesystemslib.hash to hashlib, requires wrapping and re-raising to
maintain the expected behavior.

This is a temporary solution until secure-systems-lab#766.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
Minimally refactor EAFP to LBYL to avoid clunky re-raise.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
@lukpueh
Copy link
Member Author

lukpueh commented Mar 20, 2025

sigstore fails because its tuf installation still requires securesystemslib.hash. This should be fixed when sigstore updates to a tuf version, which includes theupdateframework/python-tuf#2815.

@lukpueh lukpueh marked this pull request as ready for review March 20, 2025 10:12
@jku
Copy link
Collaborator

jku commented Mar 20, 2025

sigstore fails because its tuf installation still requires securesystemslib.hash. This should be fixed when sigstore updates to a tuf version, which includes theupdateframework/python-tuf#2815.

yeah I'd prefer to not remove hash until there is a tuf release that does not use it

in ["ecdsa", "ecdsa-sha2-nistp256", "ecdsa-sha2-nistp384"]
and public_key.scheme.endswith(("256", "384"))
):
algo = public_key.scheme[-3:]
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm a little surprised if this works since it seems to change the algo value ("sha256" -> "256").

The GCP tests currently only run on push so you can trigger it by pushing the branch to main repo

I'm fine with the simpler solution too.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch. 🤦 That happens when code isn't tested right away.

@lukpueh lukpueh changed the title Remove securesystemslib.hash Remove internal use of securesystemslib.hash Mar 20, 2025
lukpueh added 2 commits March 20, 2025 13:23
Internally, it isn't used anymore, but we keep it for existing
(transitive) users until they had a chance to update.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
@lukpueh
Copy link
Member Author

lukpueh commented Mar 20, 2025

Okay, I fixed it. Sorry for the slip up. I re-added the hash module (now unused), and reverted to the easier solution, which might be more clunky but also more clearly doesn't change the behavior.

I also pushed the branch to the main repo and GCPSigner still works:
https://github.com/secure-systems-lab/securesystemslib/actions/runs/13969232266/job/39106703502

Note that the existing tests don't test the failure case asserting for the specific exception. I can add one if desired.

Copy link
Collaborator

@jku jku left a comment

Choose a reason for hiding this comment

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

lgtm. We can look at improving the tests if we actually end up improving the scheme parsing globally.

@lukpueh lukpueh merged commit 918b2dc into secure-systems-lab:main Mar 20, 2025
20 checks passed
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.

simplify hashing
2 participants