Skip to content

Quantum: Initial support for C# #19905

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 40 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
9decd51
Initial quantum support for C#
fegge Jun 16, 2025
66eee73
Fixed issues in C# Language.qll
fegge Jun 16, 2025
69e6308
Added C# query to generate CBOM graph
fegge Jun 19, 2025
07a3032
quantum-c#: initial support for ECDSA and RSA signatures
fcasal Jun 19, 2025
36213c5
Merge branch 'tob/quantum-csharp' of github.com:trailofbits/codeql in…
fcasal Jun 19, 2025
d690a34
quantum-c#: make type precise
fcasal Jun 19, 2025
9970e58
quantum-c#: add HashAlgorithms
fcasal Jun 19, 2025
1762959
quantum-c#: Add HashAlgorithmInstance
fcasal Jun 23, 2025
01b98fc
quantum-c#: Add generic dataflow module
fcasal Jun 23, 2025
3913f44
quanntum-c#: refactor class names
fcasal Jun 23, 2025
b1bbd97
Added initial support for C# block ciphers
fegge Jun 23, 2025
791c260
quantum-c#: Add HashAlgorithmInstance
fcasal Jun 23, 2025
2642e32
Merge branch 'tob/quantum-csharp' of github.com:trailofbits/codeql in…
fcasal Jun 23, 2025
6d0024d
quantum-c#: refactoring
fcasal Jun 23, 2025
c7caf97
Extended CryptoStreamKeyOperationInstance
fegge Jun 23, 2025
a3e93ce
quantum-c#: add hash operation instance
fcasal Jun 24, 2025
e0430a7
Merge branch 'tob/quantum-csharp' of github.com:trailofbits/codeql in…
fcasal Jun 24, 2025
9238b12
Added support for the system CSPRNG
fegge Jun 24, 2025
46c037c
Added unit tests for C# block cipher modes
fegge Jun 24, 2025
a7c5f7a
refactoring
fcasal Jun 24, 2025
50c98f6
Merge branch 'tob/quantum-csharp' of github.com:trailofbits/codeql in…
fcasal Jun 24, 2025
3e70e8e
Updated Stream related data flow
fegge Jun 24, 2025
e488a74
Merge branch 'tob/quantum-csharp' of github.com:trailofbits/codeql in…
fcasal Jun 24, 2025
f3c436a
quantum-c#: Use stream flows for the HashOperationInstance
fcasal Jun 24, 2025
45ae4d1
Added support for AesGcm and AesCcm
fegge Jun 25, 2025
e643cc4
Updated test suite with AesGcm and AesCcm tests
fegge Jun 25, 2025
5fc267a
Added support for ChaCha20Poly1305
fegge Jun 25, 2025
e344505
quantum-c#: refactor AVCs for hashes and signatures.
fcasal Jun 25, 2025
601d5d1
Merge branch 'tob/quantum-csharp' of github.com:trailofbits/codeql in…
fcasal Jun 25, 2025
298d226
Added support for bare symmetric algorithms
fegge Jun 25, 2025
2d4af33
quantum-c#: add tests for signatures
fcasal Jun 25, 2025
7c72a65
Add RSAPKCS1Signature formatters
fcasal Jun 25, 2025
7d7b8b2
Merge branch 'tob/quantum-csharp' of github.com:trailofbits/codeql in…
fcasal Jun 25, 2025
39581e2
quantum-c#: add support for RSAPKC1Signature formatters
fcasal Jun 26, 2025
6763f18
quantum-c#: Add hash tests
fcasal Jun 26, 2025
b417436
quantum-c#: Add support for HMACs
fcasal Jun 27, 2025
e0193f8
Fixed spelling
fegge Jul 4, 2025
0fc2427
Fixed missing symmetric algorithm type
fegge Jul 4, 2025
a452350
Added CBOM graph-based unit tests for .NET
fegge Jul 4, 2025
81f06d9
Fixed QL for QL code scanning results for .NET
fegge Jul 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
quantum-c#: add HashAlgorithms
  • Loading branch information
fcasal committed Jun 19, 2025
commit 9970e586b247b477df24e6fdc04a903bc0ff5edd
30 changes: 25 additions & 5 deletions csharp/ql/lib/experimental/quantum/dotnet/Cryptography.qll
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,21 @@ class SigningNamedCurvePropertyAccess extends PropertyAccess {
string getCurveName() { result = curveName }
}

class HashAlgorithmNameType extends CryptographyType {
HashAlgorithmNameType() { this.hasName("HashAlgorithmName") }
}

class HashAlgorithmName extends PropertyAccess {
string algorithmName;

HashAlgorithmName() {
this.getType() instanceof HashAlgorithmNameType and
this.getProperty().getName() = algorithmName
}

string getAlgorithmName() { result = algorithmName }
}

/**
* Private predicate mapping NIST names to SEC names and leaving all others the same.
*/
Expand All @@ -76,12 +91,12 @@ private predicate eccurveNameMapping(string nist, string secp) {
}

// OPERATION INSTANCES
private class ECDsaClass extends Type {
ECDsaClass() { this.hasFullyQualifiedName("System.Security.Cryptography", "ECDsa") }
private class ECDsaClass extends CryptographyType {
ECDsaClass() { this.hasName("ECDsa") }
}

private class RSAClass extends Type {
RSAClass() { this.hasFullyQualifiedName("System.Security.Cryptography", "RSA") }
private class RSAClass extends CryptographyType {

Check warning

Code scanning / CodeQL

Acronyms should be PascalCase/camelCase. Warning

Acronyms in RSAClass should be PascalCase/camelCase.
RSAClass() { this.hasName("RSA") }
}

class ByteArrayType extends Type {
Expand All @@ -92,7 +107,7 @@ class ReadOnlyByteSpanType extends Type {
ReadOnlyByteSpanType() { this.getName() = "ReadOnlySpan<Byte>" }
}

abstract class DotNetSigner extends MethodCall {
class DotNetSigner extends MethodCall {
DotNetSigner() { this.getTarget().getName().matches(["Verify%", "Sign%"]) }

Expr getMessageArg() {
Expand All @@ -117,6 +132,11 @@ abstract class DotNetSigner extends MethodCall {
result = this
}

Expr getHashAlgorithmArg() {
// Get the hash algorithm argument if it has the correct type.
result = this.getAnArgument() and result.getType() instanceof HashAlgorithmNameType
}

predicate isSigner() { this.getTarget().getName().matches("Sign%") }

predicate isVerifier() { this.getTarget().getName().matches("Verify%") }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ class ECDsaORRSASigningOperationInstance extends Crypto::SignatureOperationInsta
CryptographyCreateCall creator;

ECDsaORRSASigningOperationInstance() {
this instanceof DotNetSigner and
CryptographyCreateToUseFlow::flow(DataFlow::exprNode(creator), DataFlow::exprNode(this))
}

// TODO FIXME
override Crypto::AlgorithmValueConsumer getAnAlgorithmValueConsumer() {
result = creator.getAlgorithmArg()
or
// FIXME: currently not working
result = super.getHashAlgorithmArg()
}

override Crypto::KeyOperationSubtype getKeyOperationSubtype() {
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy