Skip to content

Commit 73b3398

Browse files
authored
Merge pull request #2 from bdrodes/signature_model_refactor_experimental
Signature model refactor experimental
2 parents b7ceeb3 + 938b47c commit 73b3398

32 files changed

+756
-585
lines changed

cpp/ql/lib/experimental/quantum/Language.qll

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ module CryptoInput implements InputSig<Language::Location> {
1414
result = node.asExpr() or
1515
result = node.asParameter() or
1616
result = node.asVariable() or
17-
result = node.asDefiningArgument()
18-
// TODO: do we need asIndirectExpr()?
17+
result = node.asDefiningArgument() or
18+
result = node.asIndirectExpr()
1919
}
2020

2121
string locationToFileBaseNameAndLineNumberString(Location location) {
@@ -93,7 +93,10 @@ module GenericDataSourceFlow = TaintTracking::Global<GenericDataSourceFlowConfig
9393

9494
private class ConstantDataSource extends Crypto::GenericConstantSourceInstance instanceof OpenSslGenericSourceCandidateLiteral
9595
{
96-
override DataFlow::Node getOutputNode() { result.asExpr() = this }
96+
override DataFlow::Node getOutputNode() {
97+
// A literal can be a string or an int, so handling both indirect and direct cases
98+
[result.asIndirectExpr(), result.asExpr()] = this
99+
}
97100

98101
override predicate flowsTo(Crypto::FlowAwareElement other) {
99102
// TODO: separate config to avoid blowing up data-flow analysis

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: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,14 @@ class KnownOpenSslKeyAgreementAlgorithmExpr extends Expr instanceof KnownOpenSsl
172172

173173
predicate knownOpenSslAlgorithmOperationCall(Call c, string normalized, string algType) {
174174
c.getTarget().getName() in [
175-
"EVP_RSA_gen", "RSA_generate_key_ex", "RSA_generate_key", "RSA_new", "RSA_sign", "RSA_verify",
176-
"EVP_PKEY_get1_RSA"
175+
"EVP_RSA_gen", "RSA_generate_key_ex", "RSA_generate_key", "RSA_new", "RSA_sign", "RSA_verify"
177176
] and
178177
normalized = "RSA" and
179178
algType = "ASYMMETRIC_ENCRYPTION"
179+
or
180+
c.getTarget().getName() in ["DSA_do_sign", "DSA_do_verify"] and
181+
normalized = "DSA" and
182+
algType = "SIGNATURE"
180183
}
181184

182185
/**

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

0 commit comments

Comments
 (0)