-
Notifications
You must be signed in to change notification settings - Fork 11
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
Use of deprecated sha1 #27
Comments
Hi @nicopal, thank you for opening this issue. The reason it currently (still) defaults to using SHA1 is for backwards compatibility. If we were to change the default algorithm now, it's possible that systems importing the package do no longer work as a whole.
It seems possible to change it using |
Hi @hslatman thank you for looking into this. I suspected backward compatibility was the culprit (it's common). My initial thought was that perhaps NewSignedData could still support SHA1 but at least not default to it. However you have a better view of the constraints/requirements that others have towards this library and exposing the package global so that the default of SetDigestAlgorithm can be changed seems like a good solution. |
I've opened a PR to swap the hard-coded default here: Using SHA1 as a digest is going to start breaking across environments, OpenSSL 3.4 FIPS Provider forbids it, Golang forbids it without a environment variable - Using a hard-coded default to an unsupported algorithm combination does not make sense. My recommendation is take the easy approach here and just update the default to a SAFE default. If people need to override it, the SetDigestAlgorithm API already exists. |
If you feel really strongly about this default, your idea to expose it as a package global would probably be fine and meet most requirements That said, it's not really clear to me why this is a backwards compatibility issue - These are new signatures, and I cannot find any libraries that do not support RSA with SHA2-256 updated past 2005. I understand the general concern about changing defaults, but you could also go the Go STL direction and use a build tag to revert it - unsafe defaults is generally bad practice for cryptography. |
Good to see a change to a safe default, I hope this PR goes through soon. |
The PR won't go through as-is, that's for sure. We still support many older versions of Go, and SHA1 during verification is supported for those. Also note that PKCS7 (and CMS) are often used in environments where SHA1 is still in use for verifiction, so we can't just switch it in a minor version, in my opinion. It would mostly be a "silent" breaking change for the system as a whole: if you didn't know about the change, and just update the package (either directly, or transitively), the behavior of the relying system would change. There would be no indication in the form of CI breaking on a new argument, or something like that. Only when someone tests for a SHA1 signature explicitly, would it be uncovered during testing. It is a possibility to do it for Go version 1.24 and up with e.g. Also note that there's already a PR that allows to set the different default algorithm: #29. True, it does need the user to set it, but it does make things simpler if you rely on this package, since you only have to do it once in your program. It is absolutely being considered for a |
@hslatman I just pushed a new commit with some compromise here This allows us to set a build tag for a safe default, but the normal defaults are fully unchanged. It also exposes it as a package global to set it through multiple dependencies. Let me know what you think - I like the simplicity here, and the build tag proposed aligns with the Microsoft FIPS Golang build tag so chainguard customers/msft-go customers would benefit for free. |
Yeah, that looks better already. I'm curious if we can (also) rely on the native Go FIPS build tags that were introduced with 1.24, next to Note that we probably want the default algorithm setter to look like the one from #29 to be extra safe in highly-concurrent operations (but to be honest, there can still be issues with that approach), so I'll see if I can expedite that. |
@hslatman The new go fips build tags are under GODEBUG which is not intended to be used by downstream libs I understand the async concern, but this lib already has 3 package globals, I think for now, itd be better to solve the safe defaults problem, then in a future PR refactor the defaults to get mutex'ed via a setter. I dont think it makes sense to do it differently for this one new package global |
Gotcha. There's the In general I like the idea of being able to configure a certain "profile" for the cryptographic algorithms in use. An alternative I've thought about a bit is to have an upper level package with a straightforward and sensible API acting as a guard for which algorithms are allowed with sensible defaults. That layer would interact with the lower level implementation, which could support a more broad set of algorithms. That would allow runtime configuration of the default and allowed cryptographic primitives. Combined with an approach like
The package globals are from before we took over maintenance, and the main reason making changing the defaults harder for us now. I'd rather not introduce new package globals, but still allow some form of global configuration. We've added one before similar to this with |
Hi,
in the pkcs7 implementation, function NewSignedData in sign.go defaults to using SHA-1 as digest algorithm.
https://github.com/smallstep/pkcs7/blob/5e2c6a136dfaa418340bb4a7eb0d0c7421d4934c/sign.go
However, the use of sha1 is unadvisable according to NIST, and implementations should migrate to SHA-2 or SHA-3 as soon as possible (source: https://www.nist.gov/news-events/news/2022/12/nist-retires-sha-1-cryptographic-algorithm)
Is there a good reason this implementation defaults to SHA-1? Alternatively, would you accept a PR updating the default to SHA-2?
The text was updated successfully, but these errors were encountered: