Static analysis (SAST) check · Java

Weak RSA key (Java)

The RSA key is shorter than 2048 bits, which is within reach of factoring.

Why it matters

Signatures made with the key can be forged and data encrypted to it can be read by whoever factors it.

How to fix it

Initialise the generator with 2048 bits or more (3072 for new keys).

Example

The rule's own test fixtures, verbatim: the test suite requires the rule to report the first and not the second.

Vulnerable: reported (Java)
import java.security.KeyPair;
import java.security.KeyPairGenerator;

public class Bad {
    public KeyPair generate() throws Exception {
        KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA");
        generator.initialize(1024);
        return generator.generateKeyPair();
    }
}
Fixed: not reported (Java)
import java.security.KeyPair;
import java.security.KeyPairGenerator;

public class Ok {
    public KeyPair generate() throws Exception {
        KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA");
        generator.initialize(3072);
        return generator.generateKeyPair();
    }
}

What TrustIvan reads

Runs on repository scans of Java source once static analysis is turned on (SAST_RULES and the separately built analyzer image); it is off by default.

Weakness classes and references

Terms: SAST (static application security testing), Taint analysis, CWE (Common Weakness Enumeration), OWASP Top 10

All static analysis (SAST) checks · The whole catalogue · How this works in TrustIvan · Documentation

See TrustIvan on your own estate.

Book thirty minutes with an engineer and bring an image, a repository or a cloud account, or start free on the hosted service.