An RSA or DSA key is made shorter than 2048 bits

tx0/python:weak-key-sizerecommendedwarningsecurity, cwe-326

What it finds

rsa.generate_private_key(public_exponent=65537, key_size=1024): RSA and DSA keys shorter than 2048 bits can be factored or broken with resources that are within reach today (CWE-326).

Reported are integer literals below 2048 given as the key size to the key generators of cryptography, PyCryptodome and PyCrypto.

From the rule's source, weak_key_size.rs.

Example from the rule's tests
from cryptography.hazmat.primitives.asymmetric import rsafrom Crypto.PublicKey import RSA  def keys():    a = rsa.generate_private_key(public_exponent=65537, key_size=1024)tx0 reports: a key of 1024 bits can be broken    b = RSA.generate(512)tx0 reports: a key of 512 bits    c = rsa.generate_private_key(public_exponent=65537, key_size=4096)    d = RSA.generate(2048)    return a, b, c, d
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/python:weak-key-size" = "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/python:weak-key-size] reason="..."

tx0 explain tx0/python:weak-key-size shows the same in the terminal. Found a false positive? Report it.