-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Description
crypto/rsa is unusual in that it can be secure (used with a key size > 2048) or completely insecure (used with a key size such as 512 bits, which can be broken on a laptop). Small keys are sometimes useful in tests, but having an rsa.PrivateKey value that behaves and looks exactly like a secure one but actually provides no security at all is a significant footgun.
In production, if a 512-bit key is used, it's overwhelmingly likely that the operator thinks they have security and doesn't (this happens in the real world on a regular basis) as opposed to being intentional about using fake RSA, so this feels like one of those rare occasions where breaking them is justified.
I propose we do both the following in Go 1.24:
- return an error from rsa.GenerateKey if bits is less than 1024
- return an error from all Sign, Verify, Encrypt, and Decrypt methods if the key is smaller than 1024 bits
GODEBUG=rsa1024min=0 reverts to the old behavior.
OpenSSL sounds on the way to doing (1) in a minor release and (2) in a major release. openssl/openssl#25092
To avoid slow key generation in tests, we can recommend using the test keys in RFC 9500. If anyone has a good idea for how to expose them, we can even provide them ready to use.
We could also disable the restriction based on testing.Testing() but I would keep that as a fallback if the amount of tests that require fixing turns out to be truly unmanageable, because generally tests are supposed to test actual behavior.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status