Modify rule S5542[kotlin]: Detect CBC mode when used with padding (APPSEC-30) (#1054)

This commit is contained in:
Pierre-Loup 2022-11-29 16:29:30 +01:00 committed by GitHub
parent 5f2457dd6a
commit 3c31fb8713
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 7 deletions

View File

@ -0,0 +1,3 @@
=== Highlighting
javax.crypto.Cipher#Cipher.getInstance

View File

@ -0,0 +1,14 @@
=== Message
==== ECB
Use a secure cipher mode.
==== CBC
Use another cipher mode or disable padding.
==== RSA
Use a secure padding scheme.

View File

@ -4,10 +4,11 @@ include::../description.adoc[]
[source,kotlin]
----
val c1 = Cipher.getInstance("AES") // Noncompliant: by default ECB mode is chosen
val c2 = Cipher.getInstance("AES/ECB/NoPadding") // Noncompliant: ECB doesn't provide serious message confidentiality
Cipher.getInstance("AES") // Noncompliant: by default ECB mode is chosen
Cipher.getInstance("AES/ECB/NoPadding") // Noncompliant: ECB doesn't provide serious message confidentiality
val c3 = Cipher.getInstance("RSA/None/NoPadding") // Noncompliant: RSA without OAEP padding scheme is not recommanded
Cipher.getInstance("AES/CBC/PKCS5Padding") // Noncompliant: Vulnerable to Padding Oracle attacks
Cipher.getInstance("RSA/None/NoPadding") // Noncompliant: RSA without OAEP padding scheme is not recommended
----
== Compliant Solution
@ -15,12 +16,12 @@ val c3 = Cipher.getInstance("RSA/None/NoPadding") // Noncompliant: RSA without O
[source,kotlin]
----
// Recommended for block ciphers
val c1 = Cipher.getInstance("AES/GCM/NoPadding"); // Compliant
Cipher.getInstance("AES/GCM/NoPadding")
// Recommended for RSA
val c3 = Cipher.getInstance("RSA/None/OAEPWITHSHA-256ANDMGF1PADDING") // Compliant
Cipher.getInstance("RSA/None/OAEPWITHSHA-256ANDMGF1PADDING")
// or the ECB mode can be used for RSA when "None" is not available with the security provider used - in that case, ECB will be treated as "None" for RSA.
val c3 = Cipher.getInstance("RSA/ECB/OAEPWITHSHA-256ANDMGF1PADDING"); // Compliant
Cipher.getInstance("RSA/ECB/OAEPWITHSHA-256ANDMGF1PADDING")
----
== See
@ -39,7 +40,9 @@ ifdef::env-github,rspecator-view[]
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
include::message.adoc[]
include::highlighting.adoc[]
'''
== Comments And Links