2023-05-03 11:06:20 +02:00
== Why is this an issue?
2020-06-30 12:49:37 +02:00
The Advanced Encryption Standard (AES) encryption algorithm can be used with various modes. Some combinations are not secured:
2020-06-30 14:49:38 +02:00
2020-06-30 12:49:37 +02:00
* Electronic Codebook (ECB) mode: Under a given key, any given plaintext block always gets encrypted to the same ciphertext block. Thus, it does not hide data patterns well. In some senses, it doesn't provide serious message confidentiality, and it is not recommended for use in cryptographic protocols at all.
* Cipher Block Chaining (CBC) with PKCS#5 padding (or PKCS#7) is susceptible to padding oracle attacks.
In both cases, Galois/Counter Mode (GCM) with no padding should be preferred.
2021-02-02 15:02:10 +01:00
2021-01-27 13:42:22 +01:00
This rule raises an issue when a ``++Cipher++`` instance is created with either ECB or CBC/PKCS5Padding mode.
2020-06-30 12:49:37 +02:00
2023-05-03 11:06:20 +02:00
=== Noncompliant code example
2020-06-30 12:49:37 +02:00
2022-02-04 17:28:24 +01:00
[source,java]
2020-06-30 12:49:37 +02:00
----
Cipher c1 = Cipher.getInstance("AES/ECB/NoPadding"); // Noncompliant
Cipher c2 = Cipher.getInstance("AES/CBC/PKCS5Padding"); // Noncompliant
----
2023-05-03 11:06:20 +02:00
=== Compliant solution
2020-06-30 12:49:37 +02:00
2022-02-04 17:28:24 +01:00
[source,java]
2020-06-30 12:49:37 +02:00
----
Cipher c = Cipher.getInstance("AES/GCM/NoPadding");
----
2023-05-03 11:06:20 +02:00
== Resources
2021-09-21 15:40:35 +02:00
2022-07-08 13:58:56 +02:00
* https://owasp.org/www-project-top-ten/2017/A6_2017-Security_Misconfiguration[OWASP Top 10 2017 Category A6] - Security Misconfiguration
2022-04-07 08:53:59 -05:00
* https://cwe.mitre.org/data/definitions/327[MITRE, CWE-327] - Use of a Broken or Risky Cryptographic Algorithm
2021-09-21 15:40:35 +02:00
* https://wiki.sei.cmu.edu/confluence/x/hDdGBQ[CERT, MSC61-J.] - Do not use insecure or weak cryptographic algorithms
* https://www.sans.org/top25-software-errors/#cat3[SANS Top 25] - Porous Defenses
* https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38a.pdf[Recommendation for Block Cipher Modes of Operation]
* Derived from FindSecBugs rule https://find-sec-bugs.github.io/bugs.htm#ECB_MODE[ECB_MODE]
* Derived from FindSecBugs rule https://find-sec-bugs.github.io/bugs.htm#PADDING_ORACLE[PADDING_ORACLE]
2021-06-02 20:44:38 +02:00
2021-06-03 09:05:38 +02:00
ifdef::env-github,rspecator-view[]
2021-09-20 15:38:42 +02:00
'''
== Implementation Specification
(visible only on this page)
2023-05-25 14:18:12 +02:00
=== Message
Use Galois/Counter Mode (GCM/NoPadding) instead.
=== Highlighting
Cipher.getInstance() call
2021-09-20 15:38:42 +02:00
2021-06-08 15:52:13 +02:00
'''
2021-06-02 20:44:38 +02:00
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
2021-06-03 09:05:38 +02:00
endif::env-github,rspecator-view[]