@@ -5,6 +5,7 @@ import java
5
5
import semmle.code.java.dataflow.DataFlow
6
6
import semmle.code.java.dataflow.TaintTracking
7
7
import semmle.code.java.controlflow.Dominance
8
+ private import Crypto:: KeyOpAlg as KeyOpAlg
8
9
9
10
module JCAModel {
10
11
import Language
@@ -205,12 +206,6 @@ module JCAModel {
205
206
)
206
207
}
207
208
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
-
214
209
bindingset [ name]
215
210
predicate key_agreement_name_to_type_known ( Crypto:: TKeyAgreementType type , string name ) {
216
211
type = Crypto:: DH ( ) and
@@ -1480,7 +1475,7 @@ module JCAModel {
1480
1475
1481
1476
module MacInitCallToMacOperationFlow = DataFlow:: Global< MacInitCallToMacOperationFlowConfig > ;
1482
1477
1483
- class KnownMacAlgorithm extends Crypto:: MacAlgorithmInstance instanceof StringLiteral {
1478
+ class KnownMacAlgorithm extends Crypto:: KeyOperationAlgorithmInstance instanceof StringLiteral {
1484
1479
MacGetInstanceAlgorithmValueConsumer consumer ;
1485
1480
1486
1481
KnownMacAlgorithm ( ) {
@@ -1490,13 +1485,30 @@ module JCAModel {
1490
1485
1491
1486
MacGetInstanceAlgorithmValueConsumer getConsumer ( ) { result = consumer }
1492
1487
1493
- override string getRawMacAlgorithmName ( ) { result = super .getValue ( ) }
1488
+ override string getRawAlgorithmName ( ) { result = super .getValue ( ) }
1494
1489
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 ( )
1499
1502
}
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 ( ) }
1500
1512
}
1501
1513
1502
1514
class MacGetInstanceCall extends MethodCall {
@@ -1566,7 +1578,7 @@ module JCAModel {
1566
1578
)
1567
1579
}
1568
1580
1569
- override Crypto:: ConsumerInputDataFlowNode getMessageConsumer ( ) {
1581
+ override Crypto:: ConsumerInputDataFlowNode getInputConsumer ( ) {
1570
1582
result .asExpr ( ) = super .getArgument ( 0 ) and
1571
1583
super .getMethod ( ) .getParameterType ( 0 ) .hasName ( "byte[]" )
1572
1584
}
0 commit comments