|
1 | 1 | import cpp
|
2 | 2 | import WindowsCng
|
3 | 3 |
|
4 |
| -predicate vulnerableCngFunctionName(string name) { name in ["BCryptSignHash", "BCryptEncrypt"] } |
5 |
| - |
6 | 4 | predicate keyGenAndImportFunctionName(string name) { name in ["BCryptImportKeyPair", "BCryptGenerateKeyPair"] }
|
7 | 5 |
|
8 |
| -predicate vulnerableCngFunction(Function f) { |
9 |
| - exists(string name | f.hasGlobalName(name) and vulnerableCngFunctionName(name)) |
10 |
| -} |
11 |
| - |
12 | 6 | predicate keyGenAndImportFunction(Function f){
|
13 | 7 | exists(string name | f.hasGlobalName(name) and keyGenAndImportFunctionName(name))
|
14 | 8 | }
|
15 | 9 |
|
16 | 10 | //TODO: Verify NCrypt calls (parameters) & find all other APIs that should be included (i.e. decrypt, etc.)
|
17 |
| -predicate isExprKeyHandleForBCryptSignHash(Expr e) { |
18 |
| - exists(FunctionCall call | |
19 |
| - e = call.getArgument(0) and |
20 |
| - vulnerableCngFunction(call.getTarget()) |
21 |
| - ) |
| 11 | + |
| 12 | + |
| 13 | +predicate isCallArgument(string funcGlobalName, Expr arg, int index){ |
| 14 | + exists(Call c | c.getArgument(index) = arg and c.getTarget().hasGlobalName(funcGlobalName)) |
22 | 15 | }
|
23 | 16 |
|
24 | 17 | class BCryptSignHashArgumentSink extends BCryptOpenAlgorithmProviderSink {
|
25 |
| - BCryptSignHashArgumentSink() { isExprKeyHandleForBCryptSignHash(this.asExpr()) } |
| 18 | + BCryptSignHashArgumentSink() { isCallArgument("BCryptSignHash", this.asExpr(), 0) } |
26 | 19 | }
|
27 | 20 |
|
| 21 | +class BCryptEncryptArgumentSink extends BCryptOpenAlgorithmProviderSink { |
| 22 | + BCryptEncryptArgumentSink() { isCallArgument("BCryptEncrypt", this.asExpr(), 0) } |
| 23 | + } |
| 24 | + |
| 25 | + |
28 | 26 | class BCryptOpenAlgorithmProviderPqcVulnerableAlgorithmsSource extends BCryptOpenAlgorithmProviderSource {
|
29 | 27 | BCryptOpenAlgorithmProviderPqcVulnerableAlgorithmsSource() {
|
30 | 28 | this.asExpr() instanceof StringLiteral and
|
|
0 commit comments