-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Moving from SHA1 to SHA256 for Hash task #8812
Conversation
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.
As noted with the test changes to expectedHash, this is a breaking change if someone uses the Hash task and verifies that the output matches some fixed value, but I'm still in favor of moving to the more secure SHA256 implementation. Also, I noticed we have a GetFileHash task competing with this one with fairly small differences, and that one seems to already use SHA256, so it feels weird that this one was overlooked...
We probably need a breaking change notice for this one, yeah? |
Thanks for bringing this up @baronfel I haven't find any learn.microsoft.com documentation for this task, so probably only source serves as a documentation and it makes it clear this is subject to change: https://github.com/dotnet/msbuild/blob/main/src/Tasks/Hash.cs#L17 So it might not be necessary - though it certainly would not hurt |
We should document the task with the explicit "the hash function is an implementation detail and may vary between MSBuild engine versions" caveat. But I'd say we should also call it out as an info-level "breaking" change. |
@rainersigwald - I wasn't able to find documentation for the |
SHA256 is 15% - 25% slower than SHA1. Given the intended use case of HashTask which is "to measure only uniqueness between build executions" this task does not required to use "Strong cryptography". I am not sure if this pose real possibility of perf regression as it hashes only itemspec, but even then, I am not convinced it is actually needed. @rainersigwald, @JanKrivanek Can we please reconsider it? |
Staying with We can pull in A dummy search seems to yield some usages within our repos and some in the wild, not much though - so priority might be bit questionable. That being said - if anybody is willing to give me quick crash course (or point me to some PR (set of PRs) containing all required changes) I'm up for attempting to rewrite this with |
In case we'll choose to leverage System.IO.Hashing - than this is related: dotnet/roslyn#68700 |
I'm a little confused here about the roslyn side. The hash algorithm we use it not an implementation detail. It's a contract we have (including on the PDB side, where we use these hashes to match things up). I'm not understanding the idea here in terms of changing things out. Note: i would have been happy to stay with sha1 (since we don't use this for cryptographic purposes). But my recollectino was that it was a mandatory MS thing (with no exceptions allowed whatsoever) to maintain support for sha1 without sha256 support. |
The Prism measurements of current impact: [internal link] https://prism.vsdata.io/?query=bf%3DMicrosoft.Build.Tasks.Core.dll!Microsoft.Build.Tasks.Hash.Execute&eventType=cpu 0.12% of CPU used by the |
d4b6f38
to
e9cefe2
Compare
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.
Lets go for it - If performance measurements are acceptable .
Minor notes:
-
We are using crypto-strong hashing algos when three is no need for it. It could be that thanks for HW optimization and stuff it is faster than crypto-weak hashing, or maybe loading another dependency on system.hashing can cancel perf gains, or we strategically do not want to introduce another dependency ... whatever is the reason we shall document it in code for future us.
-
SUPER NIT: UnitTest HashTaskDifferentInputSizesTest is testing implementation, basically duplicates hashing code which makes it hard to maintain. I would probably just verify that it produces no conflicts by
hashset
or something.
Fixes (internal) https://dev.azure.com/devdiv/DevDiv/_workitems/edit/1645155/
Context
Moving away from crypthographicaly weak
SHA1
toSHA256
for Hash taskChanges Made
SHA1
-SHA256
Testing
Existing tests