11import cpp
22import 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-
314predicate 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)
4013predicate 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