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

Added support for sha384/sha512 hash algorithms in hashedrekords #1959

Merged
merged 3 commits into from
Jan 23, 2024

Conversation

ret2libc
Copy link
Contributor

Summary

Add support for SHA384/512 in hashedrekord type. This PR has been split from #1945 and borrows code from #1958 (from @bobcallaway ).

Release Note

  • Extend hashedrekord v0.0.1 schema to support sha256, sha384, and sha512 in data.hash.algorithm
  • Changed hashedrekord.CreateFromArtifactProperties to accept a prefixed-checksum (e.g. sha512:<value>) to determine the type of hash used.
  • Added util.UnprefixSHA API to split a string into the crypto.Hash being used and its value

Documentation

@ret2libc ret2libc marked this pull request as ready for review January 18, 2024 10:24
@ret2libc ret2libc requested review from bobcallaway and a team as code owners January 18, 2024 10:24
@ret2libc
Copy link
Contributor Author

Copy link

codecov bot commented Jan 18, 2024

Codecov Report

Attention: 11 lines in your changes are missing coverage. Please review.

Comparison is base (fc28ac1) 66.39% compared to head (0f1f8e3) 66.48%.

Files Patch % Lines
pkg/util/sha.go 76.66% 7 Missing ⚠️
pkg/types/hashedrekord/v0.0.1/entry.go 80.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1959      +/-   ##
==========================================
+ Coverage   66.39%   66.48%   +0.08%     
==========================================
  Files          92       92              
  Lines        9199     9246      +47     
==========================================
+ Hits         6108     6147      +39     
- Misses       2347     2355       +8     
  Partials      744      744              
Flag Coverage Δ
e2etests 47.53% <34.00%> (-0.11%) ⬇️
unittests 47.68% <78.00%> (+0.44%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Includes changes provided by @bobcallaway

Signed-off-by: Riccardo Schirone <riccardo.schirone@trailofbits.com>
Comment on lines +68 to +69
case 40:
return crypto.SHA1, sha
Copy link
Member

Choose a reason for hiding this comment

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

I know this is probably because the function above included sha1, but I think we should remove this (and the stanza above). There's no other use of that AFAIK in sigstore, and I wouldn't want to perpetuate this.

Copy link
Member

Choose a reason for hiding this comment

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

actually, i think it is used to search for entries from gitsign, im working to confirm

@wlynch - any thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

nm, i think we need to leave this - but it would be nice to add a test case that calls CreateFromArtifactProperties with a proposed sha1 value to ensure that it doesn't somehow end up in the log.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added it in 6903f5f . Please let me know if this is what you meant, otherwise I can adjust it.

Copy link
Member

@wlynch wlynch Jan 22, 2024

Choose a reason for hiding this comment

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

We don't use this for gitsign today - gitsign does a sha256 over the commit content + sha1 for rekor.

(though it would be a neat way to remove some of the chattiness gitsign has today with it's sha -> rekor entry lookup 🤔 )

Since it looks like this is already done + tests were added, I say keep it. We can revisit removing it later.

Copy link
Contributor

@haydentherapper haydentherapper left a comment

Choose a reason for hiding this comment

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

LGTM, can you add the one test bob mentioned?

Make sure Rekor accepts SHA256 digest but not SHA1

Signed-off-by: Riccardo Schirone <riccardo.schirone@trailofbits.com>
Comment on lines 123 to 139
re := V001Entry{}

// we will need artifact, public-key, signature
re.HashedRekordObj.Data = &models.HashedrekordV001SchemaData{}

re.HashedRekordObj.Signature = &models.HashedrekordV001SchemaSignature{}
re.HashedRekordObj.Signature.Content = strfmt.Base64(signature)

re.HashedRekordObj.Signature.PublicKey = &models.HashedrekordV001SchemaSignaturePublicKey{}
publicKeyBytes := [][]byte{pubBytes}

re.HashedRekordObj.Signature.PublicKey.Content = strfmt.Base64(publicKeyBytes[0])
re.HashedRekordObj.Data.Hash = &models.HashedrekordV001SchemaDataHash{
Algorithm: swag.String("sha1"),
Value: swag.String("a17c9aaa61e80a1bf71d0d850af4e5baa9800bbd"),
}

Copy link
Member

Choose a reason for hiding this comment

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

Could you switch this to use the same pattern as above where you call CreateFromArtifactProperties? That is the call path that is at risk (as the JSON Schema validation will fail the API request)

Copy link
Member

Choose a reason for hiding this comment

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

Doing this now!

Copy link
Member

Choose a reason for hiding this comment

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

Done in 0f1f8e3: I've moved this out of e2e since it no longer needs access to a runtime Rekor instance.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason why I did not use CreateFromArtifactProperties is that the test would fail in CreateFromArtifactProperties on the client side and and not on the rekor server side. Thus I wanted to test that the server did not accept it rather than just checking the client.

Copy link
Member

Choose a reason for hiding this comment

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

The reason why I did not use CreateFromArtifactProperties is that the test would fail in CreateFromArtifactProperties on the client side and and not on the rekor server side. Thus I wanted to test that the server did not accept it rather than just checking the client.

That makes sense, but I think @bobcallaway is pointing out that the server side is already checked by virtue of the JSON Schema Validation -- we could include both checks, though (with the non-e2e doing CreateFromArtifactProperties and the e2e doing it manually).

Signed-off-by: William Woodruff <william@trailofbits.com>
@bobcallaway bobcallaway merged commit 9865ca9 into sigstore:main Jan 23, 2024
14 checks passed
@github-actions github-actions bot added this to the v1.2.2 milestone Jan 23, 2024
@woodruffw woodruffw deleted the add-sha384-512-hashedrekord branch March 19, 2024 20:25
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.

5 participants