A key generator is set to a key size that can be broken

tx0/java:short-crypto-keyrecommendedwarningsecurity, cwe-326

What it finds

generator.initialize(1024) on an RSA, DSA or Diffie-Hellman key pair generator, or keyGenerator.init(64) on an AES or similar key generator, makes keys short enough to be broken with today's means (CWE-326). RSA, DSA and DH keys of 2048 bits, elliptic-curve keys of 224 bits and symmetric keys of 128 bits are the usual minimum.

Reported when the generator is a local variable initialized in the same method with KeyPairGenerator.getInstance or KeyGenerator.getInstance and a literal algorithm, and the size is an integer literal below that minimum, and for an RSAKeyGenParameterSpec made with fewer than 2048 bits.

From the rule's source, short_crypto_key.rs.

Example from the rule's tests
import java.security.KeyPairGenerator;import javax.crypto.KeyGenerator; class Keys {  void make() throws Exception {    KeyPairGenerator rsa = KeyPairGenerator.getInstance("RSA");    rsa.initialize(1024);tx0 reports: a 1024-bit RSA key can be broken    KeyPairGenerator strong = KeyPairGenerator.getInstance("RSA");    strong.initialize(3072);    KeyGenerator aes = KeyGenerator.getInstance("AES");    aes.init(64);tx0 reports: a 64-bit AES key can be broken  }}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/java:short-crypto-key" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/java:short-crypto-key] reason="..."

tx0 explain tx0/java:short-crypto-key shows the same in the terminal. Found a false positive? Report it.