-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
crypto/rsa: refuse to generate and/or use keys smaller than 1024 bits #68762
Comments
For pyca/cryptography (most widely used Python cryptography library) in our last release (~3 weeks ago) we enforce a minimum of 1024-bit for RSA key generation (up from 512-bits in the previous release). This has produced only one complaint, about a testing workload (where small keys were being used for performance). We're also interested in enforcing key sizes in signing/verification (or perhaps in key loading), but haven't done so yet. |
An easy answer to this is a GenerateKey or package-level example, for folks to copy-paste.
Actually, this is not a good idea. Packages can opt in to the equivalent behavior simply by doing
in a test file (or an equivalent, test-scoped operation). |
This also requires crypto/rsa to import testing, which isn't good. |
@FiloSottile Are you committing to supporting that Also, I really don't think this should (only) be a |
Do you have an examples of those legitimate use-cases? I admit they may exist but besides test-case reasons, I am not aware of why you’d want to use RSA < 1024. Even 1024 is a stretch these days for anything that requires actual security. I almost want 1024 gated behind a GODEBUG too |
@mcpherrinm We have some edge devices that can only hardware accelerate 256-bit. I thought they were RSA, but turns out they are elliptic (P-256), so we're good! |
Great: P-256 elliptic curves have strength greater than RSA-2048 and are well within the margin of safety today. Confusion about key strength for different algorithms is one of the common reasons for accidental use of RSA-512. For example, hashicorp/consul#20112 defaulted to a key size of 256, which was suitable for P-256 but totally inappropriate if Consul was configured to use RSA but didn’t have a key size set. This proposal would have prevented that issue. |
A recent example of a real world security incident due to production usage of RSA 512-bit keys.
https://rya.nc/vpp-hack.html
(This incident prompted this proposal, but it was not public at the time.)
|
No need for this in a test. Tests can write a line at the top of the source file:
|
This proposal has been added to the active column of the proposals project |
There should be a way to still generate and use smaller keys, e.g. to interface with legacy embedded devices that require such. It would be kind of painful for such applications to have to use a separate RSA implementation just to sidestep the restriction. |
Do you have an example of a device that requires RSA keys smaller than 1024 bits? What key sizes does it support? |
Use these as test keys:
|
For example, signing the firmware of TI calculators requires 512-bit RSA keys. |
Signing TI calculator firmware requires special tools as it has a nonstandard signature format, so this isn't a good justification for supporting 512 bit RSA, and in any event requires neither key generation nor signature verification. |
You asked for an example. It just seems to me that gimping a cryptographical primitive like this with no good way out is not a particularly good idea. |
It's been made clear repeatedly that providing support is a dangerously bad idea, and so there must be a reason that outweighs that in order to keep it. |
@clausecker It seems to me that the |
I don't think we are committing to keeping the Another option we have before permanent |
Another option could be to have a global policy variable to set the least key with accepted by the package. This would allow weak keys and permit applications to restrict the key size even further. On the other hand, global state is probably not a good design pattern here. |
There has been some discussion here but probably not any compelling reasons not to change this as the default. Tools that care can set //go:debug lines in main. It doesn't seem like there are individual packages that will care. In the future we could consider a crypto/insecurersa as a separate proposal if more motivating cases arose. |
Have all remaining concerns about this proposal been addressed? The proposal is to change crypto/rsa to reject <1024-bit RSA keys by default.
Setting GODEBUG=rsa1024min=0 reverts to the old behavior. |
Based on the discussion above, this proposal seems like a likely accept. The proposal is to change crypto/rsa to reject <1024-bit RSA keys by default.
Setting GODEBUG=rsa1024min=0 reverts to the old behavior. |
No change in consensus, so accepted. 🎉 The proposal is to change crypto/rsa to reject <1024-bit RSA keys by default.
Setting GODEBUG=rsa1024min=0 reverts to the old behavior. |
Stumbled upon this by accident. Love the idea, and excited to see it accepted! 🎉 FWIW, I maintain a |
Assigning this to me, to try and get this in the tree before the freeze. If someone is already looking into it please let me know. |
Thanks @FiloSottile! |
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:
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.The text was updated successfully, but these errors were encountered: