rspec/rules/S4432/csharp/rule.adoc

45 lines
1.4 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
2020-06-30 12:49:37 +02:00
Encryption algorithms can be used with various modes. Some combinations are not secured:
2021-02-02 15:02:10 +01: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. CBC + PKCS#7 can be used if combined with an authenticity check (HMAC-SHA256 for example) on the cipher text.
In both cases, Galois/Counter Mode (GCM) with no padding should be preferred. As the .NET framework doesn't provide this natively, the use of a certified third party lib is recommended.
2021-02-02 15:02:10 +01:00
2020-06-30 12:49:37 +02:00
This rule raises an issue when any of the following CipherMode is detected: ECB, CBC, OFB, CFB, CTS.
=== Noncompliant code example
2020-06-30 12:49:37 +02:00
2022-02-04 17:28:24 +01:00
[source,csharp]
2020-06-30 12:49:37 +02:00
----
AesManaged aes = new AesManaged
{
KeySize = 128,
BlockSize = 128,
Mode = CipherMode.OFB, // Noncompliant
Padding = PaddingMode.PKCS7
};
----
include::../see.adoc[]
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::message.adoc[]
include::highlighting.adoc[]
'''
== Comments And Links
(visible only on this page)
include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]