An initialization vector is a constant or an array of zeros
What it finds
new IvParameterSpec(new byte[16]) or an IV spelled out in the code gives every message the same initialization vector. With CBC, equal starts of messages then encrypt equally; with GCM or CTR, reusing an IV under one key gives the key stream away.
An IV counts as fixed when it is an array initializer, the bytes of a string literal, a new array that is never filled, or a variable that holds one of these: a final field, or a local variable that is used nowhere else. Some protocols prescribe a zero IV, as with a key used for a single message, so the rule is not in the default tier.
From the rule's source, constant_iv.rs.
import javax.crypto.spec.GCMParameterSpec;import javax.crypto.spec.IvParameterSpec; class Ivs { void make(byte[] random) { IvParameterSpec a = new IvParameterSpec(new byte[16]);tx0 reports: the initialization vector is an array of zeros IvParameterSpec b = new IvParameterSpec("0123456789abcdef".getBytes());tx0 reports: the initialization vector is a constant IvParameterSpec c = new IvParameterSpec(random); GCMParameterSpec d = new GCMParameterSpec(128, new byte[] {1, 2, 3});tx0 reports: the initialization vector is a constant }} 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:constant-iv" = "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:constant-iv] reason="..."tx0 explain tx0/java:constant-iv shows the same in the terminal. Found a false positive? Report it.