@@ -47,16 +47,18 @@ module JCAModel {
47
47
CipherAlgorithmStringLiteral ( ) { cipher_names ( this .getValue ( ) .splitAt ( "/" ) ) }
48
48
}
49
49
50
- class ModeOfOperationStringLiteral extends Crypto :: ModeOfOperation instanceof StringLiteral {
50
+ class ModeOfOperationStringLiteral extends StringLiteral {
51
51
ModeOfOperationStringLiteral ( ) { cipher_modes ( this .( StringLiteral ) .getValue ( ) .splitAt ( "/" ) ) }
52
52
53
- override string getRawAlgorithmName ( ) {
54
- result = this .( StringLiteral ) .getValue ( ) .regexpCapture ( ".*/(.*)/.*" , 1 )
55
- }
53
+ string getRawAlgorithmName ( ) { result = this .getValue ( ) .regexpCapture ( ".*/(.*)/.*" , 1 ) }
54
+ }
56
55
57
- override string getValue ( ) {
58
- result = this .( StringLiteral ) .getValue ( ) .regexpCapture ( ".*/(.*)/.*" , 1 )
59
- }
56
+ class ECBMode extends Crypto:: ModeOfOperation {
57
+ ModeOfOperationStringLiteral mode ;
58
+
59
+ ECBMode ( ) { modeStringToCipherInstanceArgFlow ( "ECB" , mode , this ) }
60
+
61
+ override string getRawAlgorithmName ( ) { result = mode .getRawAlgorithmName ( ) }
60
62
61
63
predicate modeToNameMapping ( Crypto:: TModeOperation type , string name ) {
62
64
name = "ECB" and type instanceof Crypto:: ECB
@@ -65,24 +67,26 @@ module JCAModel {
65
67
override Crypto:: TModeOperation getModeType ( ) {
66
68
modeToNameMapping ( result , this .getRawAlgorithmName ( ) )
67
69
}
70
+
71
+ override Crypto:: LocatableElement getOrigin ( string name ) {
72
+ result = mode and name = mode .toString ( )
73
+ }
68
74
}
69
75
70
76
abstract class CipherAlgorithmPadding extends Crypto:: NodeBase {
71
77
string getValue ( ) { result = "" }
72
78
}
73
79
74
- class CipherAlgorithmPaddingStringLiteral extends CipherAlgorithmPadding instanceof StringLiteral {
75
- CipherAlgorithmPaddingStringLiteral ( ) {
76
- cipher_padding ( this .( StringLiteral ) .getValue ( ) .splitAt ( "/" ) )
77
- }
78
-
79
- override string toString ( ) { result = this .( StringLiteral ) .toString ( ) }
80
-
81
- override string getValue ( ) {
82
- result = this .( StringLiteral ) .getValue ( ) .regexpCapture ( ".*/.*/(.*)" , 1 )
83
- }
84
- }
85
-
80
+ //todo refactor
81
+ // class CipherAlgorithmPaddingStringLiteral extends CipherAlgorithmPadding instanceof StringLiteral {
82
+ // CipherAlgorithmPaddingStringLiteral() {
83
+ // cipher_padding(this.(StringLiteral).getValue().splitAt("/"))
84
+ // }
85
+ // override string toString() { result = this.(StringLiteral).toString() }
86
+ // override string getValue() {
87
+ // result = this.(StringLiteral).getValue().regexpCapture(".*/.*/(.*)", 1)
88
+ // }
89
+ // }
86
90
private module AlgorithmStringToFetchConfig implements DataFlow:: ConfigSig {
87
91
predicate isSource ( DataFlow:: Node src ) { src .asExpr ( ) instanceof CipherAlgorithmStringLiteral }
88
92
@@ -108,6 +112,7 @@ module JCAModel {
108
112
string name , ModeOfOperationStringLiteral mode , Expr arg
109
113
) {
110
114
exists ( CipherInstance sinkCall |
115
+ //consider if this should be a more specific predicate
111
116
mode .getRawAlgorithmName ( ) = name and
112
117
arg = sinkCall and
113
118
AlgorithmStringToFetchFlow:: flow ( DataFlow:: exprNode ( mode ) ,
@@ -127,8 +132,10 @@ module JCAModel {
127
132
128
133
AESAlgo ( ) { algorithmStringToCipherInstanceArgFlow ( "AES" , alg , this ) }
129
134
135
+ //todo this is really not correct yet
130
136
override Crypto:: ModeOfOperation getModeOfOperation ( ) {
131
- modeStringToCipherInstanceArgFlow ( result .getAlgorithmName ( ) , result , this )
137
+ none ( )
138
+ //exists(Crypto::ModeOfOperation mode | mode = this and result = this)
132
139
}
133
140
134
141
override Crypto:: LocatableElement getOrigin ( string name ) {
0 commit comments