Skip to content

Commit b242b4b

Browse files
committed
More re-org
1 parent da8a7f3 commit b242b4b

File tree

3 files changed

+49
-48
lines changed

3 files changed

+49
-48
lines changed

cpp/ql/src/experimental/campaigns/nccoe-pqc-migration/QuantumVulnerableDiscovery/WinCng/WindowsCng.qll

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,32 @@ import cpp
22
import DataFlow::PathGraph
33
import semmle.code.cpp.dataflow.TaintTracking
44

5-
abstract class BCryptOpenAlgorithmProviderSink extends DataFlow::Node {}
6-
abstract class BCryptOpenAlgorithmProviderSource extends DataFlow::Node {}
5+
abstract class BCryptOpenAlgorithmProviderSink extends DataFlow::Node { }
76

7+
abstract class BCryptOpenAlgorithmProviderSource extends DataFlow::Node { }
8+
9+
predicate isCallArgument(string funcGlobalName, Expr arg, int index) {
10+
exists(Call c | c.getArgument(index) = arg and c.getTarget().hasGlobalName(funcGlobalName))
11+
}
12+
13+
//TODO: Verify NCrypt calls (parameters) & find all other APIs that should be included (i.e. decrypt, etc.)
14+
// ------------------ SINKS ----------------------
15+
class BCryptSignHashArgumentSink extends BCryptOpenAlgorithmProviderSink {
16+
BCryptSignHashArgumentSink() { isCallArgument("BCryptSignHash", this.asExpr(), 0) }
17+
}
18+
19+
class BCryptEncryptArgumentSink extends BCryptOpenAlgorithmProviderSink {
20+
BCryptEncryptArgumentSink() { isCallArgument("BCryptEncrypt", this.asExpr(), 0) }
21+
}
22+
23+
// ----------------- SOURCES -----------------------
24+
class BCryptOpenAlgorithmProviderPqcVulnerableAlgorithmsSource extends BCryptOpenAlgorithmProviderSource {
25+
BCryptOpenAlgorithmProviderPqcVulnerableAlgorithmsSource() {
26+
this.asExpr() instanceof StringLiteral and
27+
(
28+
this.asExpr().getValue() in ["DH", "DSA", "ECDSA", "ECDH"] or
29+
this.asExpr().getValue().matches("ECDH%") or
30+
this.asExpr().getValue().matches("RSA%")
31+
)
32+
}
33+
}

cpp/ql/src/experimental/campaigns/nccoe-pqc-migration/QuantumVulnerableDiscovery/WinCng/WindowsCngPQCVulnerableUsage.ql

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,8 @@ import DataFlow::PathGraph
1616
import WindowsCng
1717
import WindowsCngPQCVulnerableUsage
1818

19-
// CNG-specific DataFlow configuration
20-
class BCryptConfiguration extends DataFlow::Configuration {
21-
BCryptConfiguration() {
22-
this = "BCryptConfiguration"
23-
}
24-
override predicate isSource(DataFlow::Node source) {
25-
source instanceof BCryptOpenAlgorithmProviderSource
26-
}
27-
28-
override predicate isSink(DataFlow::Node sink) {
29-
sink instanceof BCryptOpenAlgorithmProviderSink
30-
}
31-
32-
override predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
33-
isWindowsCngAdditionalTaintStep( node1, node2)
34-
}
35-
}
3619

3720
from BCryptConfiguration config, DataFlow::PathNode source, DataFlow::PathNode sink
3821
where config.hasFlowPath(source, sink)
3922
select sink.getNode(), source, sink, "PQC vulnerable algorithm $@ in use has been detected.",
40-
source.getNode().asExpr(), source.getNode().asExpr().toString()
23+
source.getNode().asExpr(), source.getNode().asExpr().toString()
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,6 @@
11
import cpp
22
import WindowsCng
33

4-
//TODO: Verify NCrypt calls (parameters) & find all other APIs that should be included (i.e. decrypt, etc.)
5-
6-
7-
predicate isCallArgument(string funcGlobalName, Expr arg, int index){
8-
exists(Call c | c.getArgument(index) = arg and c.getTarget().hasGlobalName(funcGlobalName))
9-
}
10-
11-
class BCryptSignHashArgumentSink extends BCryptOpenAlgorithmProviderSink {
12-
BCryptSignHashArgumentSink() { isCallArgument("BCryptSignHash", this.asExpr(), 0) }
13-
}
14-
15-
class BCryptEncryptArgumentSink extends BCryptOpenAlgorithmProviderSink {
16-
BCryptEncryptArgumentSink() { isCallArgument("BCryptEncrypt", this.asExpr(), 0) }
17-
}
18-
19-
20-
class BCryptOpenAlgorithmProviderPqcVulnerableAlgorithmsSource extends BCryptOpenAlgorithmProviderSource {
21-
BCryptOpenAlgorithmProviderPqcVulnerableAlgorithmsSource() {
22-
this.asExpr() instanceof StringLiteral and
23-
(
24-
this.asExpr().getValue() in ["DH", "DSA", "ECDSA", "ECDH"] or
25-
this.asExpr().getValue().matches("ECDH%") or
26-
this.asExpr().getValue().matches("RSA%")
27-
)
28-
}
29-
}
30-
314
predicate stepOpenAlgorithmProvider(DataFlow::Node node1, DataFlow::Node node2) {
325
exists(FunctionCall call |
336
// BCryptOpenAlgorithmProvider 2nd argument specifies the algorithm to be used
@@ -40,7 +13,10 @@ predicate stepOpenAlgorithmProvider(DataFlow::Node node1, DataFlow::Node node2)
4013
predicate stepImportGenerateKeyPair(DataFlow::Node node1, DataFlow::Node node2) {
4114
exists(FunctionCall call |
4215
node1.asExpr() = call.getArgument(0) and
43-
exists(string name | name in ["BCryptImportKeyPair", "BCryptGenerateKeyPair"] and call.getTarget().hasGlobalName(name)) and
16+
exists(string name |
17+
name in ["BCryptImportKeyPair", "BCryptGenerateKeyPair"] and
18+
call.getTarget().hasGlobalName(name)
19+
) and
4420
node2.asDefiningArgument() = call.getArgument(1)
4521
)
4622
}
@@ -50,3 +26,19 @@ predicate isWindowsCngAdditionalTaintStep(DataFlow::Node node1, DataFlow::Node n
5026
or
5127
stepImportGenerateKeyPair(node1, node2)
5228
}
29+
30+
31+
// CNG-specific DataFlow configuration
32+
class BCryptConfiguration extends DataFlow::Configuration {
33+
BCryptConfiguration() { this = "BCryptConfiguration" }
34+
35+
override predicate isSource(DataFlow::Node source) {
36+
source instanceof BCryptOpenAlgorithmProviderSource
37+
}
38+
39+
override predicate isSink(DataFlow::Node sink) { sink instanceof BCryptOpenAlgorithmProviderSink }
40+
41+
override predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
42+
isWindowsCngAdditionalTaintStep(node1, node2)
43+
}
44+
}

0 commit comments

Comments
 (0)