@@ -14,41 +14,6 @@ predicate cipher_modes(string mode) {mode = ["NONE", "CBC", "CCM", "CFB", "CFBx"
14
14
predicate cipher_padding ( string padding ) { padding = [ "NoPadding" , "ISO10126Padding" , "OAEPPadding" , "OAEPWith" , "PKCS1Padding" , "PKCS5Padding" , "SSL3Padding" ] }
15
15
16
16
17
- abstract class BlockCiper extends Crypto:: Algorithm {
18
- CipherAlgorithmStringLiteral alg ;
19
- CipherAlgorithmMode mode ;
20
- CipherAlgorithmPadding padding ;
21
-
22
-
23
- CipherAlgorithmStringLiteral getAlg ( ) { result = alg }
24
- CipherAlgorithmMode getMode ( ) { result = mode }
25
-
26
- CipherAlgorithmPadding getPadding ( ) { result = padding }
27
- }
28
- /**
29
- * Symmetric algorithms
30
- */
31
- abstract class SymmetricAlgorithm extends Crypto:: Algorithm {
32
-
33
-
34
- //TODO figure out how to get this from the Cipher interface, is it explicit?
35
- //abstract string getKeySize(Location location);
36
-
37
- // override predicate properties(string key, string value, Location location) {
38
- // super.properties(key, value, location)
39
- // or
40
- // key = "key_size" and
41
- // if exists(this.getKeySize(location))
42
- // then value = this.getKeySize(location)
43
- // else (
44
- // value instanceof Crypto::UnknownPropertyValue and location instanceof UnknownLocation
45
- // )
46
- // // other properties, like field type are possible, but not modeled until considered necessary
47
- // }
48
-
49
- abstract override string getAlgorithmName ( ) ;
50
- }
51
-
52
17
////cipher specifics ----------------------------------------
53
18
54
19
class CipherInstance extends Call {
@@ -60,24 +25,26 @@ class CipherInstance extends Call {
60
25
/**
61
26
* this may be specified either in the ALG/MODE/PADDING or just ALG format
62
27
*/
63
- class CipherAlgorithmStringLiteral extends Crypto :: NodeBase instanceof StringLiteral {
28
+ class CipherAlgorithmStringLiteral extends StringLiteral {
64
29
CipherAlgorithmStringLiteral ( ) { cipher_names ( this .getValue ( ) .splitAt ( "/" ) ) }
65
-
66
- override string toString ( ) { result = this .( StringLiteral ) .toString ( ) }
67
-
68
- string getValue ( ) { result = this .( StringLiteral ) .getValue ( ) }
69
30
}
70
31
71
- abstract class CipherAlgorithmMode extends Crypto:: NodeBase {
72
- string getValue ( ) { result = "" }
73
- }
74
32
75
- class CipherAlgorithmModeStringLiteral extends CipherAlgorithmMode instanceof StringLiteral {
76
- CipherAlgorithmModeStringLiteral ( ) { cipher_modes ( this .( StringLiteral ) .getValue ( ) .splitAt ( "/" ) ) }
33
+ class ModeOfOperationStringLiteral extends Crypto :: ModeOfOperation instanceof StringLiteral {
34
+ ModeOfOperationStringLiteral ( ) { cipher_modes ( this .( StringLiteral ) .getValue ( ) .splitAt ( "/" ) ) }
77
35
78
- override string toString ( ) { result = this .( StringLiteral ) .toString ( ) }
36
+ override string getRawAlgorithmName ( ) { result = this .( StringLiteral ) .getValue ( ) . regexpCapture ( ".*/(.*)/.*" , 1 ) }
79
37
80
38
override string getValue ( ) { result = this .( StringLiteral ) .getValue ( ) .regexpCapture ( ".*/(.*)/.*" , 1 ) }
39
+
40
+
41
+ predicate modeToNameMapping ( Crypto:: TModeOperation type , string name ) {
42
+ name = "ECB" and type instanceof Crypto:: ECB
43
+ }
44
+
45
+ override Crypto:: TModeOperation getModeType ( ) {
46
+ modeToNameMapping ( result , this .getRawAlgorithmName ( ) )
47
+ }
81
48
}
82
49
83
50
abstract class CipherAlgorithmPadding extends Crypto:: NodeBase {
@@ -102,32 +69,51 @@ abstract class CipherAlgorithmMode extends Crypto::NodeBase {
102
69
103
70
module AlgorithmStringToFetchFlow = DataFlow:: Global< AlgorithmStringToFetchConfig > ;
104
71
105
- predicate algorithmStringToCipherInstanceArgFlow ( string name , CipherAlgorithmStringLiteral origin , CipherAlgorithmModeStringLiteral mode , CipherAlgorithmPaddingStringLiteral padding , Expr arg ) {
72
+ predicate algorithmStringToCipherInstanceArgFlow ( string name , CipherAlgorithmStringLiteral origin , Expr arg ) {
106
73
exists ( CipherInstance sinkCall |
107
74
origin .getValue ( ) .splitAt ( "/" ) = name and
108
- origin = mode and
109
- origin = padding and
110
75
arg = sinkCall .getAlgorithmArg ( ) and
111
76
AlgorithmStringToFetchFlow:: flow ( DataFlow:: exprNode ( origin ) , DataFlow:: exprNode ( arg ) )
112
77
)
113
78
}
114
79
80
+
81
+ predicate modeStringToCipherInstanceArgFlow ( string name , ModeOfOperationStringLiteral mode , Expr arg ) {
82
+ exists ( CipherInstance sinkCall |
83
+ mode .getRawAlgorithmName ( ) = name and
84
+ arg = sinkCall .getAlgorithmArg ( ) and
85
+ AlgorithmStringToFetchFlow:: flow ( DataFlow:: exprNode ( mode ) , DataFlow:: exprNode ( arg ) )
86
+ )
87
+ }
88
+
115
89
/**
116
90
* A class to represent when AES is used AND it has literal mode and padding provided
117
91
* this does not capture the use without
118
92
*/
119
- class AESLiteral extends SymmetricAlgorithm , BlockCiper instanceof Expr {
93
+ // class AESLiteral extends Crypto::SymmetricAlgorithm instanceof Expr {
94
+ // CipherAlgorithmStringLiteral alg;
95
+ // AESLiteral() { algorithmStringToCipherInstanceArgFlow("AES", alg, this)
96
+ // }
120
97
98
+ // override Crypto::ModeOfOperation getModeOfOperation(){ modeStringToCipherInstanceArgFlow(result.getAlgorithmName(), result, this)}
121
99
122
- AESLiteral ( ) { algorithmStringToCipherInstanceArgFlow ( "AES" , alg , mode , padding , this )
123
- }
100
+ // override Crypto::LocatableElement getOrigin(string name) {
101
+ // result = alg and name = alg.toString()
102
+ // }
124
103
125
- override Crypto:: LocatableElement getOrigin ( string name ) {
126
- result = alg and name = alg .toString ( )
127
- }
104
+ // override string getAlgorithmName(){ result = "AES" }
128
105
129
- override string getAlgorithmName ( ) { result = alg .getValue ( ) }
130
- }
106
+ // override string getRawAlgorithmName(){ result = alg.getValue()}
107
+
108
+ // override Crypto::TSymmetricCipherFamilyType getSymmetricCipherFamilyType() { result instanceof Crypto::AES}
109
+
110
+ // //temp hacks for testing
111
+ // override string getKeySize(Location location){
112
+ // result = ""
113
+ // }
114
+
115
+ // override Crypto::TCipherStructure getCipherType(){ none()}
116
+ // }
131
117
132
118
133
119
}
0 commit comments