-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
fbbe831
commit d540a03
Showing
12 changed files
with
170 additions
and
176 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
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
39 changes: 0 additions & 39 deletions
39
analyzers/tests/SonarAnalyzer.Test/TestCases/Hotspots/CreatingHashAlgorithms.CSharp11.cs
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
analyzers/tests/SonarAnalyzer.Test/TestCases/Hotspots/CreatingHashAlgorithms.CSharp12.cs
This file was deleted.
Oops, something went wrong.
65 changes: 65 additions & 0 deletions
65
analyzers/tests/SonarAnalyzer.Test/TestCases/Hotspots/CreatingHashAlgorithms.Latest.cs
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,65 @@ | ||
using System.Security.Cryptography; | ||
using System.Text; | ||
|
||
public class InsecureHashAlgorithm | ||
{ | ||
const string part1 = """System.Security.Cryptography"""; | ||
const string part2 = """SHA1"""; | ||
|
||
void RawStringLiterals(byte[] temp) | ||
{ | ||
using var SHA1HashAlgorithmWithNamespaceRawStringLiteral = HashAlgorithm.Create("""System.Security.Cryptography.SHA1"""); // Noncompliant | ||
using var SHA1HashAlgorithmWithNamespaceInterpolatedRawStringLiteral = HashAlgorithm.Create($$"""{{part1}}.{{part2}}"""); // Noncompliant | ||
} | ||
|
||
void NewlinesInStringInterpolation() | ||
{ | ||
using var SHA1HashAlgorithm = HashAlgorithm.Create($"{part1 + | ||
'.' + | ||
part2}"); // FN (at the moment we validate only constant string) | ||
using var SHA1HashAlgorithmRawString = HashAlgorithm.Create($$"""{{part1 + | ||
'.' + | ||
part2}}"""); // FN (at the moment we validate only constant string) | ||
} | ||
} | ||
|
||
// All the new .NET5 methods should be taken into consideration | ||
// https://github.com/SonarSource/sonar-dotnet/issues/8758 | ||
public class Repro_FN_8758 | ||
{ | ||
void Method() | ||
{ | ||
var data = new byte[42]; | ||
using var stream = new System.IO.MemoryStream(data); | ||
SHA1.HashData(stream); // FN | ||
SHA1.HashData(data); // FN | ||
} | ||
} | ||
|
||
class PrimaryConstructor(string ctorParam = "MD5") | ||
{ | ||
void Method(string methodParam = "MD5") | ||
{ | ||
var md5Ctor = (HashAlgorithm)CryptoConfig.CreateFromName(ctorParam); // FN | ||
var md5Method = (HashAlgorithm)CryptoConfig.CreateFromName(methodParam); // FN | ||
var lambda = (string lambdaParam = "MD5") => (HashAlgorithm)CryptoConfig.CreateFromName(lambdaParam); // FN | ||
} | ||
} | ||
|
||
class CSHarp13 | ||
{ | ||
void KMAK_Hashing() | ||
{ | ||
using var kmac128 = new Kmac128(new byte[] { 0x01, 0x02, 0x03, 0x04 }); // Compliant | ||
using var kmac256 = new Kmac256(new byte[] { 0x01, 0x02, 0x03, 0x04 }); // Compliant | ||
using var kmacXof128 = new KmacXof128(new byte[] { 0x01, 0x02, 0x03, 0x04 }); // Compliant | ||
using var kmacXof256 = new KmacXof256(new byte[] { 0x01, 0x02, 0x03, 0x04 }); // Compliant | ||
|
||
byte[] data = Encoding.UTF8.GetBytes("KMAK"); | ||
byte[] key = new byte[] { 0x01, 0x02, 0x03, 0x04 }; | ||
byte[] mac128 = Kmac128.HashData(key, data, 200); // Compliant | ||
byte[] mac256 = Kmac256.HashData(key, data, 200); // Compliant | ||
byte[] macXof128 = KmacXof128.HashData(key, data, 200); // Compliant | ||
byte[] macXof256 = KmacXof256.HashData(key, data, 200); // Compliant | ||
} | ||
} |
10 changes: 0 additions & 10 deletions
10
...zer.Test/TestCases/SymbolicExecution/Roslyn/HashesShouldHaveUnpredictableSalt.CSharp10.cs
This file was deleted.
Oops, something went wrong.
22 changes: 0 additions & 22 deletions
22
...zer.Test/TestCases/SymbolicExecution/Roslyn/HashesShouldHaveUnpredictableSalt.CSharp11.cs
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
...t/TestCases/SymbolicExecution/Roslyn/HashesShouldHaveUnpredictableSalt.CSharp8.NetCore.cs
This file was deleted.
Oops, something went wrong.
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
12 changes: 0 additions & 12 deletions
12
...yzer.Test/TestCases/SymbolicExecution/Sonar/HashesShouldHaveUnpredictableSalt.CSharp10.cs
This file was deleted.
Oops, something went wrong.
23 changes: 0 additions & 23 deletions
23
...yzer.Test/TestCases/SymbolicExecution/Sonar/HashesShouldHaveUnpredictableSalt.CSharp11.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.