A digest, cipher or protocol known to be broken is requested by name
What it finds
MessageDigest.getInstance("MD5"), Cipher.getInstance("DES/CBC/PKCS5Padding") and SSLContext.getInstance("TLSv1") ask the platform for algorithms that are broken or retired: collisions for MD5 and SHA-1 can be computed (CWE-328), DES, RC4 and Blowfish keys or streams can be recovered, ECB mode, also the default of a bare "AES", shows patterns of the plain text, RSA without padding is malleable (CWE-327), and SSL 3 and TLS 1.0 and 1.1 have known attacks. SHA-256, AES in GCM mode, RSA with OAEP and TLS 1.2 or later are the usual replacements.
The algorithm must be a string literal given to getInstance of MessageDigest, Cipher, KeyGenerator or SSLContext, or a protocol in the array given to setEnabledProtocols. The MD5 and SHA-1 methods of Commons Codec's DigestUtils and Guava's Hashing count as asking for those digests.
From the rule's source, weak_crypto_algorithm.rs.
import java.security.MessageDigest;import javax.crypto.Cipher;import javax.net.ssl.SSLContext; class Crypto { void setup() throws Exception { MessageDigest a = MessageDigest.getInstance("MD5");tx0 reports: MD5 is a digest whose collisions can be computed MessageDigest b = MessageDigest.getInstance("SHA-256"); Cipher c = Cipher.getInstance("DES/CBC/PKCS5Padding");tx0 reports: DES/CBC/PKCS5Padding is a cipher Cipher d = Cipher.getInstance("AES");tx0 reports: AES uses ECB mode Cipher e = Cipher.getInstance("AES/GCM/NoPadding"); Cipher f = Cipher.getInstance("RSA/ECB/NoPadding");tx0 reports: is RSA without padding SSLContext g = SSLContext.getInstance("TLSv1");tx0 reports: TLSv1 is a protocol version with known attacks SSLContext h = SSLContext.getInstance("TLSv1.3"); }} 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:
[rules]
"tx0/java:weak-crypto-algorithm" = "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:weak-crypto-algorithm] reason="..."tx0 explain tx0/java:weak-crypto-algorithm shows the same in the terminal. Found a false positive? Report it.