Skip to content

Commit 023653a

Browse files
author
Sakshis
committed
gcm-nonce-reuse-java
1 parent ee1cda3 commit 023653a

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
id: gcm-nonce-reuse-java
2+
language: java
3+
severity: warning
4+
message: >-
5+
GCM IV/nonce is reused: encryption can be totally useless.
6+
note: >-
7+
[CWE-323] Reusing a Nonce, Key Pair in Encryption.
8+
[REFERENCES]
9+
- https://owasp.org/Top10/A02_2021-Cryptographic_Failures
10+
rule:
11+
any:
12+
- pattern: GCMParameterSpec $$$ = new GCMParameterSpec(GCM_TAG_LENGTH * 8, $A);
13+
follows:
14+
stopBy: end
15+
pattern: byte[] $A = $_;
16+
- pattern: new GCMParameterSpec($$$, "$$$".getBytes($$$), $$$)
17+
18+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
id: gcm-nonce-reuse-java
2+
snapshots:
3+
? |
4+
byte[] theBadIV = BAD_IV.getBytes();
5+
GCMParameterSpec gcmParameterSpec = new GCMParameterSpec(GCM_TAG_LENGTH * 8, theBadIV);
6+
: labels:
7+
- source: GCMParameterSpec gcmParameterSpec = new GCMParameterSpec(GCM_TAG_LENGTH * 8, theBadIV);
8+
style: primary
9+
start: 37
10+
end: 124
11+
- source: byte[] theBadIV = BAD_IV.getBytes();
12+
style: secondary
13+
start: 0
14+
end: 36
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
id: gcm-nonce-reuse-java
2+
valid:
3+
- |
4+
byte[] theBadIV = BAD_IV.getBytes();
5+
GCMParameterSpec gcmParameter = new GCMParameter(GCM_TAG_LENGTH * 8, theBadIV);
6+
invalid:
7+
- |
8+
byte[] theBadIV = BAD_IV.getBytes();
9+
GCMParameterSpec gcmParameterSpec = new GCMParameterSpec(GCM_TAG_LENGTH * 8, theBadIV);

0 commit comments

Comments
 (0)