Skip to content

Commit 1e9c2b3

Browse files
committed
Applied formatting.
1 parent 7a27635 commit 1e9c2b3

File tree

1 file changed

+37
-47
lines changed

1 file changed

+37
-47
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,57 @@
11
import cpp
22
import WindowsCng
33

4-
predicate vulnerableCngFunctionName(string name) {
5-
name in ["BCryptSignHash", "BCryptEncrypt"]
6-
}
4+
predicate vulnerableCngFunctionName(string name) { name in ["BCryptSignHash", "BCryptEncrypt"] }
75

8-
predicate vulnerableCngFunction(Function f)
9-
{
10-
exists(string name | f.hasGlobalName(name) and vulnerableCngFunctionName(name))
6+
predicate vulnerableCngFunction(Function f) {
7+
exists(string name | f.hasGlobalName(name) and vulnerableCngFunctionName(name))
118
}
129

1310
//TODO: Verify NCrypt calls (parameters) & find all other APIs that should be included (i.e. decrypt, etc.)
14-
predicate isExprKeyHandleForBCryptSignHash(Expr e){
15-
exists( FunctionCall call |
16-
e = call.getArgument(0)
17-
and
18-
vulnerableCngFunction(call.getTarget())
19-
)
11+
predicate isExprKeyHandleForBCryptSignHash(Expr e) {
12+
exists(FunctionCall call |
13+
e = call.getArgument(0) and
14+
vulnerableCngFunction(call.getTarget())
15+
)
2016
}
2117

2218
class BCryptSignHashArgumentSink extends BCryptOpenAlgorithmProviderSink {
23-
BCryptSignHashArgumentSink() {
24-
isExprKeyHandleForBCryptSignHash(this.asExpr())
25-
}
19+
BCryptSignHashArgumentSink() { isExprKeyHandleForBCryptSignHash(this.asExpr()) }
2620
}
2721

2822
class BCryptOpenAlgorithmProviderPqcVulnerableAlgorithmsSource extends BCryptOpenAlgorithmProviderSource {
29-
BCryptOpenAlgorithmProviderPqcVulnerableAlgorithmsSource() {
30-
this.asExpr() instanceof StringLiteral and
31-
(
32-
this.asExpr().getValue() in ["DH", "DSA", "ECDSA", "ECDH"]
33-
or this.asExpr().getValue().matches("ECDH%")
34-
or this.asExpr().getValue().matches("RSA%")
35-
)
36-
}
23+
BCryptOpenAlgorithmProviderPqcVulnerableAlgorithmsSource() {
24+
this.asExpr() instanceof StringLiteral and
25+
(
26+
this.asExpr().getValue() in ["DH", "DSA", "ECDSA", "ECDH"] or
27+
this.asExpr().getValue().matches("ECDH%") or
28+
this.asExpr().getValue().matches("RSA%")
29+
)
30+
}
3731
}
3832

39-
predicate stepOpenAlgorithmProvider(DataFlow::Node node1, DataFlow::Node node2)
40-
{
41-
exists( FunctionCall call |
42-
// BCryptOpenAlgorithmProvider 2nd argument specifies the algorithm to be used
43-
node1.asExpr() = call.getArgument(1)
44-
and
45-
call.getTarget().hasGlobalName("BCryptOpenAlgorithmProvider")
46-
and
47-
node2.asDefiningArgument() = call.getArgument(0)
48-
)
33+
predicate stepOpenAlgorithmProvider(DataFlow::Node node1, DataFlow::Node node2) {
34+
exists(FunctionCall call |
35+
// BCryptOpenAlgorithmProvider 2nd argument specifies the algorithm to be used
36+
node1.asExpr() = call.getArgument(1) and
37+
call.getTarget().hasGlobalName("BCryptOpenAlgorithmProvider") and
38+
node2.asDefiningArgument() = call.getArgument(0)
39+
)
4940
}
5041

51-
predicate stepImportGenerateKeyPair(DataFlow::Node node1, DataFlow::Node node2)
52-
{
53-
exists( FunctionCall call |
54-
node1.asExpr() = call.getArgument(0)
55-
and
56-
( call.getTarget().hasGlobalName("BCryptImportKeyPair") or
57-
call.getTarget().hasGlobalName("BCryptGenerateKeyPair"))
58-
and
59-
node2.asDefiningArgument() = call.getArgument(1)
60-
)
42+
predicate stepImportGenerateKeyPair(DataFlow::Node node1, DataFlow::Node node2) {
43+
exists(FunctionCall call |
44+
node1.asExpr() = call.getArgument(0) and
45+
(
46+
call.getTarget().hasGlobalName("BCryptImportKeyPair") or
47+
call.getTarget().hasGlobalName("BCryptGenerateKeyPair")
48+
) and
49+
node2.asDefiningArgument() = call.getArgument(1)
50+
)
6151
}
6252

6353
predicate isWindowsCngAsymmetricKeyAdditionalTaintStep(DataFlow::Node node1, DataFlow::Node node2) {
64-
stepOpenAlgorithmProvider(node1, node2)
65-
or
66-
stepImportGenerateKeyPair(node1, node2)
67-
}
54+
stepOpenAlgorithmProvider(node1, node2)
55+
or
56+
stepImportGenerateKeyPair(node1, node2)
57+
}

0 commit comments

Comments
 (0)