Skip to content

Commit 4993fa8

Browse files
author
Sakshis
committed
desede-is-deprecated-java
1 parent 7d42251 commit 4993fa8

File tree

3 files changed

+100
-0
lines changed

3 files changed

+100
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
id: desede-is-deprecated-java
2+
language: java
3+
severity: warning
4+
message: >-
5+
Triple DES (3DES or DESede) is considered deprecated. AES is the recommended cipher. Upgrade to use AES.
6+
note: >-
7+
[CWE-326]: Inadequate Encryption Strength
8+
[OWASP A03:2017]: Sensitive Data Exposure
9+
[OWASP A02:2021]: Cryptographic Failures
10+
[REFERENCES]
11+
- https://find-sec-bugs.github.io/bugs.htm#TDES_USAGE
12+
- https://csrc.nist.gov/News/2017/Update-to-Current-Use-and-Deprecation-of-TDEA
13+
utils:
14+
match_method_invocation:
15+
kind: method_invocation
16+
all:
17+
- has:
18+
stopBy: end
19+
kind: identifier
20+
- has:
21+
stopBy: end
22+
kind: identifier
23+
regex: '^getInstance$'
24+
has:
25+
stopBy: end
26+
kind: argument_list
27+
has:
28+
stopBy: end
29+
kind: string_literal
30+
regex: 'DESede'
31+
match_key_generator:
32+
kind: method_invocation
33+
nthChild: 1
34+
all:
35+
- has:
36+
stopBy: end
37+
kind: field_access
38+
field: object
39+
- has:
40+
stopBy: end
41+
kind: identifier
42+
regex: '^KeyGenerator$'
43+
rule:
44+
any:
45+
- matches: match_method_invocation
46+
- matches: match_key_generator
47+
48+
49+
50+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
id: desede-is-deprecated-java
2+
snapshots:
3+
? |
4+
Cipher c = Cipher.getInstance("kDESede/ECB/PKCS5Padding");
5+
c.init(Cipher.ENCRYPT_MODE, k, iv);
6+
: labels:
7+
- source: Cipher.getInstance("kDESede/ECB/PKCS5Padding")
8+
style: primary
9+
start: 11
10+
end: 57
11+
- source: Cipher
12+
style: secondary
13+
start: 11
14+
end: 17
15+
- source: getInstance
16+
style: secondary
17+
start: 18
18+
end: 29
19+
- source: '"kDESede/ECB/PKCS5Padding"'
20+
style: secondary
21+
start: 30
22+
end: 56
23+
- source: ("kDESede/ECB/PKCS5Padding")
24+
style: secondary
25+
start: 29
26+
end: 57
27+
? "javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance(\"DES\").generateKey(); \n"
28+
: labels:
29+
- source: javax.crypto.KeyGenerator.getInstance("DES")
30+
style: primary
31+
start: 29
32+
end: 73
33+
- source: javax.crypto.KeyGenerator
34+
style: secondary
35+
start: 29
36+
end: 54
37+
- source: KeyGenerator
38+
style: secondary
39+
start: 42
40+
end: 54
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
id: desede-is-deprecated-java
2+
valid:
3+
- |
4+
Cipher c = Cipher.getInstance("AES/GCM/NoPadding");
5+
invalid:
6+
- |
7+
Cipher c = Cipher.getInstance("kDESede/ECB/PKCS5Padding");
8+
c.init(Cipher.ENCRYPT_MODE, k, iv);
9+
- |
10+
javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey();

0 commit comments

Comments
 (0)