-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create rule S5547: Cipher algorithms should be robust (#4652)
* Add go to rule S5547 * Add description for S5547 for Go --------- Co-authored-by: daniel-teuchert-sonarsource <[email protected]> Co-authored-by: Daniel Teuchert <[email protected]>
- Loading branch information
1 parent
19b9e22
commit 162d5ba
Showing
2 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
include::../summary.adoc[] | ||
|
||
== Why is this an issue? | ||
|
||
include::../rationale.adoc[] | ||
|
||
include::../impact.adoc[] | ||
|
||
== How to fix it | ||
|
||
=== Code examples | ||
|
||
include::../common/fix/code-rationale.adoc[] | ||
|
||
==== Noncompliant code example | ||
|
||
[source,go,diff-id=1,diff-type=noncompliant] | ||
---- | ||
import ( | ||
"crypto/des" | ||
"crypto/rand" | ||
) | ||
func encrypt(message []byte, key []byte) []byte { | ||
blockCipher, _ := des.NewCipher(key) // Noncompliant | ||
cipherText := make([]byte, blockCipher.BlockSize()) | ||
blockCipher.Encrypt(cipherText, message) | ||
return cipherText | ||
} | ||
---- | ||
|
||
==== Compliant solution | ||
|
||
[source,go,diff-id=1,diff-type=compliant] | ||
---- | ||
import ( | ||
"crypto/aes" | ||
"crypto/rand" | ||
) | ||
func encrypt(message []byte, key []byte) []byte { | ||
blockCipher, _ := aes.NewCipher(key) | ||
cipherText := make([]byte, blockCipher.BlockSize()) | ||
blockCipher.Encrypt(cipherText, message) | ||
return cipherText | ||
} | ||
---- | ||
|
||
=== How does this work? | ||
|
||
include::../common/fix/strong-cryptography.adoc[] | ||
|
||
|
||
|
||
== Resources | ||
|
||
include::../common/resources/standards.adoc[] | ||
|
||
ifdef::env-github,rspecator-view[] | ||
|
||
''' | ||
== Implementation Specification | ||
(visible only on this page) | ||
|
||
include::../message.adoc[] | ||
|
||
''' | ||
== Comments And Links | ||
(visible only on this page) | ||
|
||
include::../comments-and-links.adoc[] | ||
|
||
endif::env-github,rspecator-view[] | ||
|