Skip to content

Commit 81f06d9

Browse files
committed
Fixed QL for QL code scanning results for .NET
1 parent a452350 commit 81f06d9

File tree

4 files changed

+45
-48
lines changed

4 files changed

+45
-48
lines changed

csharp/ql/lib/experimental/quantum/dotnet/AlgorithmInstances.qll

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ private import FlowAnalysis
77

88
class NamedCurveAlgorithmInstance extends Crypto::EllipticCurveInstance instanceof NamedCurvePropertyAccess
99
{
10-
NamedCurveAlgorithmInstance() { this instanceof NamedCurvePropertyAccess }
11-
1210
override string getRawEllipticCurveName() { result = super.getCurveName() }
1311

1412
override Crypto::TEllipticCurveType getEllipticCurveType() {

csharp/ql/lib/experimental/quantum/dotnet/Cryptography.qll

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ class CryptographyType extends Type {
66
CryptographyType() { this.hasFullyQualifiedName("System.Security.Cryptography", _) }
77
}
88

9-
class ECParameters extends CryptographyType {
10-
ECParameters() { this.hasName("ECParameters") }
9+
class EcParameters extends CryptographyType {
10+
EcParameters() { this.hasName("ECParameters") }
1111
}
1212

13-
class RSAParameters extends CryptographyType {
14-
RSAParameters() { this.hasName("RSAParameters") }
13+
class RsaParameters extends CryptographyType {
14+
RsaParameters() { this.hasName("RSAParameters") }
1515
}
1616

17-
class ECCurve extends CryptographyType {
18-
ECCurve() { this.hasName("ECCurve") }
17+
class EcCurve extends CryptographyType {
18+
EcCurve() { this.hasName("ECCurve") }
1919
}
2020

2121
class HashAlgorithmType extends CryptographyType {
@@ -71,12 +71,12 @@ class EcdsaCreateCall extends CryptographyCreateCall {
7171
}
7272

7373
// This class is used to model the `ECDsa.Create(ECParameters)` call
74-
class ECDsaCreateCallWithParameters extends EcdsaCreateCall {
75-
ECDsaCreateCallWithParameters() { this.getArgument(0).getType() instanceof ECParameters }
74+
class EcdsaCreateCallWithParameters extends EcdsaCreateCall {
75+
EcdsaCreateCallWithParameters() { this.getArgument(0).getType() instanceof EcParameters }
7676
}
7777

78-
class ECDsaCreateCallWithECCurve extends EcdsaCreateCall {
79-
ECDsaCreateCallWithECCurve() { this.getArgument(0).getType() instanceof ECCurve }
78+
class EcdsaCreateCallWithECCurve extends EcdsaCreateCall {
79+
EcdsaCreateCallWithECCurve() { this.getArgument(0).getType() instanceof EcCurve }
8080
}
8181

8282
class RsaCreateCall extends CryptographyCreateCall {
@@ -127,7 +127,7 @@ class NamedCurvePropertyAccess extends PropertyAccess {
127127

128128
NamedCurvePropertyAccess() {
129129
super.getType().getName() = "ECCurve" and
130-
eccurveNameMapping(super.getProperty().toString().toUpperCase(), curveName)
130+
ecCurveNameMapping(super.getProperty().toString().toUpperCase(), curveName)
131131
}
132132

133133
string getCurveName() { result = curveName }
@@ -196,7 +196,7 @@ class HashAlgorithmNameUser extends MethodCall {
196196
* Private predicate mapping NIST names to SEC names and leaving all others the same.
197197
*/
198198
bindingset[nist]
199-
private predicate eccurveNameMapping(string nist, string secp) {
199+
private predicate ecCurveNameMapping(string nist, string secp) {
200200
if nist.matches("NIST%")
201201
then
202202
nist = "NISTP256" and secp = "secp256r1"
@@ -208,28 +208,28 @@ private predicate eccurveNameMapping(string nist, string secp) {
208208
}
209209

210210
// OPERATION INSTANCES
211-
private class ECDsaClass extends CryptographyType {
212-
ECDsaClass() { this.hasName("ECDsa") }
211+
private class EcdsaClass extends CryptographyType {
212+
EcdsaClass() { this.hasName("ECDsa") }
213213
}
214214

215-
private class RSAClass extends CryptographyType {
216-
RSAClass() { this.hasName("RSA") }
215+
private class RsaClass extends CryptographyType {
216+
RsaClass() { this.hasName("RSA") }
217217
}
218218

219-
private class RSAPKCS1SignatureFormatter extends CryptographyType {
220-
RSAPKCS1SignatureFormatter() { this.hasName("RSAPKCS1SignatureFormatter") }
219+
private class RsaPkcs1SignatureFormatter extends CryptographyType {
220+
RsaPkcs1SignatureFormatter() { this.hasName("RSAPKCS1SignatureFormatter") }
221221
}
222222

223-
private class RSAPKCS1SignatureDeformatter extends CryptographyType {
224-
RSAPKCS1SignatureDeformatter() { this.hasName("RSAPKCS1SignatureDeformatter") }
223+
private class RsaPkcs1SignatureDeformatter extends CryptographyType {
224+
RsaPkcs1SignatureDeformatter() { this.hasName("RSAPKCS1SignatureDeformatter") }
225225
}
226226

227227
private class SignerType extends Type {
228228
SignerType() {
229-
this instanceof ECDsaClass or
230-
this instanceof RSAClass or
231-
this instanceof RSAPKCS1SignatureFormatter or
232-
this instanceof RSAPKCS1SignatureDeformatter
229+
this instanceof EcdsaClass or
230+
this instanceof RsaClass or
231+
this instanceof RsaPkcs1SignatureFormatter or
232+
this instanceof RsaPkcs1SignatureDeformatter
233233
}
234234
}
235235

@@ -631,8 +631,8 @@ class MacAlgorithmType extends CryptographyType {
631631
MacAlgorithmType() { this.getName().matches(["HMAC%", "KeyedHashAlgorithm"]) }
632632
}
633633

634-
class HMACCreation extends ObjectCreation {
635-
HMACCreation() { this.getObjectType() instanceof MacAlgorithmType }
634+
class HmacCreation extends ObjectCreation {
635+
HmacCreation() { this.getObjectType() instanceof MacAlgorithmType }
636636

637637
Expr getKeyArg() { if this.hasNoArguments() then result = this else result = this.getArgument(0) }
638638

@@ -674,7 +674,7 @@ class MacUse extends Crypto::AlgorithmValueConsumer instanceof MethodCall {
674674
Expr getKeyArg() {
675675
if not super.getTarget().getName().matches("ComputeHash%")
676676
then result = super.getArgument(0)
677-
else result = HMACFlow::getCreationFromUse(this, _, _).getKeyArg()
677+
else result = HmacFlow::getCreationFromUse(this, _, _).getKeyArg()
678678
}
679679

680680
override Crypto::AlgorithmInstance getAKnownAlgorithmSource() { result = super.getQualifier() }
@@ -684,16 +684,16 @@ class MacUse extends Crypto::AlgorithmValueConsumer instanceof MethodCall {
684684
Expr getQualifier() { result = super.getQualifier() }
685685
}
686686

687-
class HMACAlgorithmInstance extends Crypto::MACAlgorithmInstance instanceof Expr {
688-
HMACAlgorithmInstance() { this = any(MacUse c).getQualifier() }
687+
class HmacAlgorithmInstance extends Crypto::MACAlgorithmInstance instanceof Expr {
688+
HmacAlgorithmInstance() { this = any(MacUse c).getQualifier() }
689689

690690
override Crypto::TMACType getMACType() { result instanceof Crypto::THMAC }
691691

692692
override string getRawMACAlgorithmName() { result = super.getType().getName() }
693693
}
694694

695-
class HMACAlgorithmQualifier extends Crypto::HMACAlgorithmInstance, Crypto::AlgorithmValueConsumer,
696-
HMACAlgorithmInstance, Crypto::HashAlgorithmInstance instanceof Expr
695+
class HmacAlgorithmQualifier extends Crypto::HMACAlgorithmInstance, Crypto::AlgorithmValueConsumer,
696+
HmacAlgorithmInstance, Crypto::HashAlgorithmInstance instanceof Expr
697697
{
698698
override Crypto::AlgorithmValueConsumer getHashAlgorithmValueConsumer() { result = this }
699699

@@ -718,7 +718,7 @@ class HMACAlgorithmQualifier extends Crypto::HMACAlgorithmInstance, Crypto::Algo
718718
private string getOriginalRawHashAlgorithmName() {
719719
exists(MacUse use |
720720
use.getQualifier() = this and
721-
result = HMACFlow::getCreationFromUse(use, _, _).getRawAlgorithmName().replaceAll("HMAC", "")
721+
result = HmacFlow::getCreationFromUse(use, _, _).getRawAlgorithmName().replaceAll("HMAC", "")
722722
)
723723
}
724724
}

csharp/ql/lib/experimental/quantum/dotnet/FlowAnalysis.qll

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ module CryptoStreamFlow = CreationToUseFlow<CryptoStreamCreation, CryptoStreamUs
7070

7171
module AeadFlow = CreationToUseFlow<AeadCreation, AeadUse>;
7272

73-
module HMACFlow = CreationToUseFlow<HMACCreation, MacUse>;
73+
module HmacFlow = CreationToUseFlow<HmacCreation, MacUse>;
7474

7575
module SymmetricAlgorithmFlow =
7676
CreationToUseFlow<SymmetricAlgorithmCreation, SymmetricAlgorithmUse>;
@@ -263,17 +263,16 @@ module SigningCreateToUseFlow {
263263
sink.asExpr() = any(SignerUse use).(QualifiableExpr).getQualifier()
264264
}
265265

266-
/**
267-
* An additional flow step across new object creations that use the original objects.
268-
*
269-
* Example:
270-
* ```
271-
* RSA rsa = RSA.Create()
272-
* RSAPKCS1SignatureFormatter rsaFormatter = new(rsa);
273-
* rsaFormatter.SetHashAlgorithm(nameof(SHA256));
274-
* signedHash = rsaFormatter.CreateSignature(hash);
275-
* ```
276-
*/
266+
// Holds if the incoming node is an argument of the constructor call
267+
// represented by the outgoing node.
268+
//
269+
// Example:
270+
// ```
271+
// RSA rsa = RSA.Create()
272+
// RSAPKCS1SignatureFormatter rsaFormatter = new(rsa);
273+
// rsaFormatter.SetHashAlgorithm(nameof(SHA256));
274+
// signedHash = rsaFormatter.CreateSignature(hash);
275+
// ```
277276
predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
278277
exists(ObjectCreation create |
279278
node2.asExpr() = create and node1.asExpr() = create.getAnArgument()

csharp/ql/lib/experimental/quantum/dotnet/OperationInstances.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,8 @@ class AeadOperationInstance extends Crypto::KeyOperationInstance instanceof Aead
210210
}
211211
}
212212

213-
class HMACOperationInstance extends Crypto::MACOperationInstance instanceof MacUse {
214-
HMACOperationInstance() { not super.isIntermediate() }
213+
class HmacOperationInstance extends Crypto::MACOperationInstance instanceof MacUse {
214+
HmacOperationInstance() { not super.isIntermediate() }
215215

216216
override Crypto::AlgorithmValueConsumer getAnAlgorithmValueConsumer() {
217217
result = super.getQualifier()

0 commit comments

Comments
 (0)