@@ -14,37 +14,43 @@ import cpp
14
14
import semmle.code.cpp.ir.dataflow.DataFlow
15
15
import semmle.code.cpp.ir.IR
16
16
17
- int getMinimumKeyStrength ( string func ) {
18
- func = "EVP_PKEY_CTX_set_dsa_paramgen_bits" and result = 2048
19
- or
20
- func = "EVP_PKEY_CTX_set_dh_paramgen_prime_len" and result = 2048
21
- or
22
- func = "EVP_PKEY_CTX_set_rsa_keygen_bits" and result = 2048
17
+ // Holds if `func` is the name of an encryption function that accepts a key size as parameter `paramIndex`
18
+ int getMinimumKeyStrength ( string func , int paramIndex ) {
19
+ func =
20
+ [
21
+ "EVP_PKEY_CTX_set_dsa_paramgen_bits" , "DSA_generate_parameters_ex" ,
22
+ "EVP_PKEY_CTX_set_rsa_keygen_bits" , "RSA_generate_key_ex" , "RSA_generate_key_fips" ,
23
+ "EVP_PKEY_CTX_set_dh_paramgen_prime_len" , "DH_generate_parameters_ex"
24
+ ] and
25
+ paramIndex = 1 and
26
+ result = 2048
23
27
}
24
28
25
29
class KeyStrengthFlow extends DataFlow:: Configuration {
26
- KeyStrengthFlow ( ) {
27
- this = "KeyStrengthFlow"
28
- }
30
+ KeyStrengthFlow ( ) { this = "KeyStrengthFlow" }
29
31
30
32
override predicate isSource ( DataFlow:: Node node ) {
31
33
node .asInstruction ( ) instanceof IntegerConstantInstruction
32
34
}
33
35
34
36
override predicate isSink ( DataFlow:: Node node ) {
35
- exists ( FunctionCall fc , string name |
36
- node .asExpr ( ) = fc .getArgument ( 1 ) and
37
+ exists ( FunctionCall fc , string name , int param |
38
+ node .asExpr ( ) = fc .getArgument ( param ) and
37
39
fc .getTarget ( ) .hasGlobalName ( name ) and
38
- exists ( getMinimumKeyStrength ( name ) )
40
+ exists ( getMinimumKeyStrength ( name , param ) )
39
41
)
40
42
}
41
43
}
42
44
43
- from DataFlow:: PathNode source , DataFlow:: PathNode sink , KeyStrengthFlow conf , FunctionCall fc , string name , int bits
45
+ from
46
+ DataFlow:: PathNode source , DataFlow:: PathNode sink , KeyStrengthFlow conf , FunctionCall fc ,
47
+ string name , int bits
44
48
where
45
49
conf .hasFlowPath ( source , sink ) and
46
50
sink .getNode ( ) .asExpr ( ) = fc .getArgument ( 1 ) and
47
51
fc .getTarget ( ) .hasGlobalName ( name ) and
48
- bits = getMinimumKeyStrength ( name ) and
49
- source .getNode ( ) .asInstruction ( ) .( ConstantValueInstruction ) .getValue ( ) .toInt ( ) < bits
50
- select fc , source , sink , "The key size $@ is insufficient for security" , source , source .toString ( )
52
+ bits = getMinimumKeyStrength ( name , _) and
53
+ source .getNode ( ) .asInstruction ( ) .( ConstantValueInstruction ) .getValue ( ) .toInt ( ) < bits
54
+ select fc , source , sink ,
55
+ "The key size $@ is less than the recommended key size of " + bits .toString ( ) + " bits." , source ,
56
+ source .toString ( )
0 commit comments