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.
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();
}
}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
Related checks
- Insecure TLS protocol (Java)
JavaSeverity: Medium
trustivan-java-insecure-tls-protocol - Runtime exec concatenation (Java)
JavaSeverity: Medium
trustivan-java-runtime-exec-concatenation - JWT unsigned parse (Java)
JavaSeverity: High
trustivan-java-jwt-unsigned-parse - Template injection from request input (Java)
JavaSeverity: High
trustivan-java-taint-template-injection - Cookie flags disabled (Java)
JavaSeverity: Medium
trustivan-java-cookie-flags-disabled - Regex injection from request input (Java)
JavaSeverity: Medium
trustivan-java-taint-regex-injection
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