@@ -5,6 +5,7 @@ import java
55import semmle.code.java.dataflow.DataFlow
66import semmle.code.java.dataflow.TaintTracking
77import semmle.code.java.controlflow.Dominance
8+ private import Crypto:: KeyOpAlg as KeyOpAlg
89
910module JCAModel {
1011 import Language
@@ -205,12 +206,6 @@ module JCAModel {
205206 )
206207 }
207208
208- bindingset [ name]
209- predicate mac_name_to_mac_type_known ( Crypto:: TMacType type , string name ) {
210- type = Crypto:: HMAC ( ) and
211- name .toUpperCase ( ) .matches ( "HMAC%" )
212- }
213-
214209 bindingset [ name]
215210 predicate key_agreement_name_to_type_known ( Crypto:: TKeyAgreementType type , string name ) {
216211 type = Crypto:: DH ( ) and
@@ -1480,7 +1475,7 @@ module JCAModel {
14801475
14811476 module MacInitCallToMacOperationFlow = DataFlow:: Global< MacInitCallToMacOperationFlowConfig > ;
14821477
1483- class KnownMacAlgorithm extends Crypto:: MacAlgorithmInstance instanceof StringLiteral {
1478+ class KnownMacAlgorithm extends Crypto:: KeyOperationAlgorithmInstance instanceof StringLiteral {
14841479 MacGetInstanceAlgorithmValueConsumer consumer ;
14851480
14861481 KnownMacAlgorithm ( ) {
@@ -1490,13 +1485,30 @@ module JCAModel {
14901485
14911486 MacGetInstanceAlgorithmValueConsumer getConsumer ( ) { result = consumer }
14921487
1493- override string getRawMacAlgorithmName ( ) { result = super .getValue ( ) }
1488+ override string getRawAlgorithmName ( ) { result = super .getValue ( ) }
14941489
1495- override Crypto:: MacType getMacType ( ) {
1496- if mac_name_to_mac_type_known ( _, super .getValue ( ) )
1497- then mac_name_to_mac_type_known ( result , super .getValue ( ) )
1498- else result = Crypto:: OtherMacType ( )
1490+ override Crypto:: KeyOpAlg:: AlgorithmType getAlgorithmType ( ) {
1491+ if super .getValue ( ) .toUpperCase ( ) .matches ( "HMAC%" )
1492+ then result = KeyOpAlg:: TMac ( KeyOpAlg:: HMAC ( ) )
1493+ else
1494+ if super .getValue ( ) .toUpperCase ( ) .matches ( "CMAC%" )
1495+ then result = KeyOpAlg:: TMac ( KeyOpAlg:: CMAC ( ) )
1496+ else result = KeyOpAlg:: TMac ( KeyOpAlg:: OtherMacAlgorithmType ( ) )
1497+ }
1498+
1499+ override Crypto:: ConsumerInputDataFlowNode getKeySizeConsumer ( ) {
1500+ // TODO: trace to any key size initializer?
1501+ none ( )
14991502 }
1503+
1504+ override int getKeySizeFixed ( ) {
1505+ // TODO: are there known fixed key sizes to consider?
1506+ none ( )
1507+ }
1508+
1509+ override Crypto:: ModeOfOperationAlgorithmInstance getModeOfOperationAlgorithm ( ) { none ( ) }
1510+
1511+ override Crypto:: PaddingAlgorithmInstance getPaddingAlgorithm ( ) { none ( ) }
15001512 }
15011513
15021514 class MacGetInstanceCall extends MethodCall {
@@ -1566,7 +1578,7 @@ module JCAModel {
15661578 )
15671579 }
15681580
1569- override Crypto:: ConsumerInputDataFlowNode getMessageConsumer ( ) {
1581+ override Crypto:: ConsumerInputDataFlowNode getInputConsumer ( ) {
15701582 result .asExpr ( ) = super .getArgument ( 0 ) and
15711583 super .getMethod ( ) .getParameterType ( 0 ) .hasName ( "byte[]" )
15721584 }
0 commit comments