@@ -47,16 +47,18 @@ module JCAModel {
4747 CipherAlgorithmStringLiteral ( ) { cipher_names ( this .getValue ( ) .splitAt ( "/" ) ) }
4848 }
4949
50- class ModeOfOperationStringLiteral extends Crypto :: ModeOfOperation instanceof StringLiteral {
50+ class ModeOfOperationStringLiteral extends StringLiteral {
5151 ModeOfOperationStringLiteral ( ) { cipher_modes ( this .( StringLiteral ) .getValue ( ) .splitAt ( "/" ) ) }
5252
53- override string getRawAlgorithmName ( ) {
54- result = this .( StringLiteral ) .getValue ( ) .regexpCapture ( ".*/(.*)/.*" , 1 )
55- }
53+ string getRawAlgorithmName ( ) { result = this .getValue ( ) .regexpCapture ( ".*/(.*)/.*" , 1 ) }
54+ }
5655
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 ( ) }
6062
6163 predicate modeToNameMapping ( Crypto:: TModeOperation type , string name ) {
6264 name = "ECB" and type instanceof Crypto:: ECB
@@ -65,24 +67,26 @@ module JCAModel {
6567 override Crypto:: TModeOperation getModeType ( ) {
6668 modeToNameMapping ( result , this .getRawAlgorithmName ( ) )
6769 }
70+
71+ override Crypto:: LocatableElement getOrigin ( string name ) {
72+ result = mode and name = mode .toString ( )
73+ }
6874 }
6975
7076 abstract class CipherAlgorithmPadding extends Crypto:: NodeBase {
7177 string getValue ( ) { result = "" }
7278 }
7379
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+ // }
8690 private module AlgorithmStringToFetchConfig implements DataFlow:: ConfigSig {
8791 predicate isSource ( DataFlow:: Node src ) { src .asExpr ( ) instanceof CipherAlgorithmStringLiteral }
8892
@@ -108,6 +112,7 @@ module JCAModel {
108112 string name , ModeOfOperationStringLiteral mode , Expr arg
109113 ) {
110114 exists ( CipherInstance sinkCall |
115+ //consider if this should be a more specific predicate
111116 mode .getRawAlgorithmName ( ) = name and
112117 arg = sinkCall and
113118 AlgorithmStringToFetchFlow:: flow ( DataFlow:: exprNode ( mode ) ,
@@ -127,8 +132,10 @@ module JCAModel {
127132
128133 AESAlgo ( ) { algorithmStringToCipherInstanceArgFlow ( "AES" , alg , this ) }
129134
135+ //todo this is really not correct yet
130136 override Crypto:: ModeOfOperation getModeOfOperation ( ) {
131- modeStringToCipherInstanceArgFlow ( result .getAlgorithmName ( ) , result , this )
137+ none ( )
138+ //exists(Crypto::ModeOfOperation mode | mode = this and result = this)
132139 }
133140
134141 override Crypto:: LocatableElement getOrigin ( string name ) {
0 commit comments