rspec/rules/S5542/kotlin/rule.adoc

72 lines
2.2 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
include::../description.adoc[]
=== Noncompliant code example
2022-02-04 17:28:24 +01:00
[source,kotlin]
----
Cipher.getInstance("AES") // Noncompliant: by default ECB mode is chosen
Cipher.getInstance("AES/ECB/NoPadding") // Noncompliant: ECB doesn't provide serious message confidentiality
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
2022-02-04 17:28:24 +01:00
[source,kotlin]
----
// Recommended for block ciphers
Cipher.getInstance("AES/GCM/NoPadding")
// Recommended for RSA
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.
Cipher.getInstance("RSA/ECB/OAEPWITHSHA-256ANDMGF1PADDING")
----
== Resources
* https://owasp.org/Top10/A02_2021-Cryptographic_Failures/[OWASP Top 10 2021 Category A2] - Cryptographic Failures
* https://owasp.org/www-project-top-ten/2017/A6_2017-Security_Misconfiguration[OWASP Top 10 2017 Category A6] - Security Misconfiguration
* https://mobile-security.gitbook.io/masvs/security-requirements/0x08-v3-cryptography_verification_requirements[Mobile AppSec Verification Standard] - Cryptography Requirements
* https://owasp.org/www-project-mobile-top-10/2016-risks/m5-insufficient-cryptography[OWASP Mobile Top 10 2016 Category M5] - Insufficient Cryptography
* https://cwe.mitre.org/data/definitions/327[MITRE, CWE-327] - Use of a Broken or Risky Cryptographic Algorithm
* 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
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
==== ECB
Use a secure cipher mode.
==== CBC
Use another cipher mode or disable padding.
==== RSA
Use a secure padding scheme.
=== Highlighting
javax.crypto.Cipher#Cipher.getInstance
'''
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]