Skip to content

Commit 422352c

Browse files
committed
Crypto: Continued refactoring of operation steps and bug fixes.
1 parent 48dc280 commit 422352c

21 files changed

+91
-56
lines changed

cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmInstances/AlgToAVCFlow.qll

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@ private import PaddingAlgorithmInstance
1414
*/
1515
module KnownOpenSslAlgorithmToAlgorithmValueConsumerConfig implements DataFlow::ConfigSig {
1616
predicate isSource(DataFlow::Node source) {
17-
source.asExpr() instanceof KnownOpenSslAlgorithmExpr and
17+
(
18+
source.asExpr() instanceof KnownOpenSslAlgorithmExpr or
19+
source.asIndirectExpr() instanceof KnownOpenSslAlgorithmExpr
20+
) and
1821
// No need to flow direct operations to AVCs
19-
not source.asExpr() instanceof OpenSslDirectAlgorithmOperationCall
22+
not source.asExpr() instanceof OpenSslDirectAlgorithmOperationCall and
23+
not source.asIndirectExpr() instanceof OpenSslDirectAlgorithmOperationCall
2024
}
2125

2226
predicate isSink(DataFlow::Node sink) {

cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmInstances/BlockAlgorithmInstance.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ class KnownOpenSslBlockModeConstantAlgorithmInstance extends OpenSslAlgorithmIns
5353
// Sink is an argument to a CipherGetterCall
5454
sink = getterCall.getInputNode() and
5555
// Source is `this`
56-
src.asExpr() = this and
56+
// NOTE: src literals can be ints or strings, so need to consider asExpr and asIndirectExpr
57+
this = [src.asExpr(), src.asIndirectExpr()] and
5758
// This traces to a getter
5859
KnownOpenSslAlgorithmToAlgorithmValueConsumerFlow::flow(src, sink)
5960
)

cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmInstances/CipherAlgorithmInstance.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ class KnownOpenSslCipherConstantAlgorithmInstance extends OpenSslAlgorithmInstan
7777
// Sink is an argument to a CipherGetterCall
7878
sink = getterCall.getInputNode() and
7979
// Source is `this`
80-
src.asExpr() = this and
80+
// NOTE: src literals can be ints or strings, so need to consider asExpr and asIndirectExpr
81+
this = [src.asExpr(), src.asIndirectExpr()] and
8182
// This traces to a getter
8283
KnownOpenSslAlgorithmToAlgorithmValueConsumerFlow::flow(src, sink)
8384
)

cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmInstances/EllipticCurveAlgorithmInstance.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ class KnownOpenSslEllipticCurveConstantAlgorithmInstance extends OpenSslAlgorith
2121
// Sink is an argument to a CipherGetterCall
2222
sink = getterCall.getInputNode() and
2323
// Source is `this`
24-
src.asExpr() = this and
24+
// NOTE: src literals can be ints or strings, so need to consider asExpr and asIndirectExpr
25+
this = [src.asExpr(), src.asIndirectExpr()] and
2526
// This traces to a getter
2627
KnownOpenSslAlgorithmToAlgorithmValueConsumerFlow::flow(src, sink)
2728
)

cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmInstances/HashAlgorithmInstance.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ class KnownOpenSslHashConstantAlgorithmInstance extends OpenSslAlgorithmInstance
5959
// Sink is an argument to a CipherGetterCall
6060
sink = getterCall.getInputNode() and
6161
// Source is `this`
62-
src.asExpr() = this and
62+
// NOTE: src literals can be ints or strings, so need to consider asExpr and asIndirectExpr
63+
this = [src.asExpr(), src.asIndirectExpr()] and
6364
// This traces to a getter
6465
KnownOpenSslAlgorithmToAlgorithmValueConsumerFlow::flow(src, sink)
6566
)

cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmInstances/KeyAgreementAlgorithmInstance.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ class KnownOpenSslKeyAgreementConstantAlgorithmInstance extends OpenSslAlgorithm
3737
// Sink is an argument to a CipherGetterCall
3838
sink = getterCall.getInputNode() and
3939
// Source is `this`
40-
src.asExpr() = this and
40+
// NOTE: src literals can be ints or strings, so need to consider asExpr and asIndirectExpr
41+
this = [src.asExpr(), src.asIndirectExpr()] and
4142
// This traces to a getter
4243
KnownOpenSslAlgorithmToAlgorithmValueConsumerFlow::flow(src, sink)
4344
)

cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmInstances/KnownAlgorithmConstants.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@ predicate knownOpenSslAlgorithmOperationCall(Call c, string normalized, string a
177177
] and
178178
normalized = "RSA" and
179179
algType = "ASYMMETRIC_ENCRYPTION"
180+
or
181+
c.getTarget().getName() in ["DSA_do_sign", "DSA_do_verify"] and
182+
normalized = "DSA" and
183+
algType = "SIGNATURE"
180184
}
181185

182186
/**

cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmInstances/MACAlgorithmInstance.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ class KnownOpenSslMacConstantAlgorithmInstance extends OpenSslAlgorithmInstance,
2222
// Sink is an argument to a CipherGetterCall
2323
sink = getterCall.getInputNode() and
2424
// Source is `this`
25-
src.asExpr() = this and
25+
// NOTE: src literals can be ints or strings, so need to consider asExpr and asIndirectExpr
26+
this = [src.asExpr(), src.asIndirectExpr()] and
2627
// This traces to a getter
2728
KnownOpenSslAlgorithmToAlgorithmValueConsumerFlow::flow(src, sink)
2829
)

cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmInstances/PaddingAlgorithmInstance.qll

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ class KnownOpenSslPaddingConstantAlgorithmInstance extends OpenSslAlgorithmInsta
6464
// Sink is an argument to a CipherGetterCall
6565
sink = getterCall.getInputNode() and
6666
// Source is `this`
67-
src.asExpr() = this and
67+
// NOTE: src literals can be ints or strings, so need to consider asExpr and asIndirectExpr
68+
this = [src.asExpr(), src.asIndirectExpr()] and
6869
// This traces to a getter
6970
KnownOpenSslAlgorithmToAlgorithmValueConsumerFlow::flow(src, sink) and
7071
isPaddingSpecificConsumer = false
@@ -82,7 +83,8 @@ class KnownOpenSslPaddingConstantAlgorithmInstance extends OpenSslAlgorithmInsta
8283
// Sink is an argument to a CipherGetterCall
8384
sink = getterCall.getInputNode() and
8485
// Source is `this`
85-
src.asExpr() = this and
86+
// NOTE: src literals can be ints or strings, so need to consider asExpr and asIndirectExpr
87+
this = [src.asExpr(), src.asIndirectExpr()] and
8688
// This traces to a padding-specific consumer
8789
RsaPaddingAlgorithmToPaddingAlgorithmValueConsumerFlow::flow(src, sink)
8890
) and

cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmInstances/SignatureAlgorithmInstance.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ class KnownOpenSslSignatureConstantAlgorithmInstance extends OpenSslAlgorithmIns
4747
// Sink is an argument to a signature getter call
4848
sink = getterCall.getInputNode() and
4949
// Source is `this`
50-
src.asExpr() = this and
50+
// NOTE: src literals can be ints or strings, so need to consider asExpr and asIndirectExpr
51+
this = [src.asExpr(), src.asIndirectExpr()] and
5152
// This traces to a getter
5253
KnownOpenSslAlgorithmToAlgorithmValueConsumerFlow::flow(src, sink)
5354
)

0 commit comments

Comments
 (0)