Skip to content

Commit e0f0d55

Browse files
Jami CogswellJami Cogswell
authored andcommitted
condense code
1 parent bcb506b commit e0f0d55

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

java/ql/lib/semmle/code/java/security/InsufficientKeySize.qll

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,20 +96,22 @@ private predicate hasKeySizeInInitMethod(DataFlow::Node node, string typeFlag) {
9696
jcaSpec instanceof JavaSecurityKeyPairGenerator and typeFlag.matches("asymmetric%")
9797
) and
9898
(
99-
jcaSpec.getAlgoSpec().(StringLiteral).getValue().toUpperCase() = "AES" and
100-
typeFlag = "symmetric"
99+
getAlgoName(jcaSpec) = "AES" and typeFlag = "symmetric"
101100
or
102-
jcaSpec.getAlgoSpec().(StringLiteral).getValue().toUpperCase().matches(["RSA", "DSA", "DH"]) and
103-
typeFlag = "asymmetric-non-ec"
101+
getAlgoName(jcaSpec).matches(["RSA", "DSA", "DH"]) and typeFlag = "asymmetric-non-ec"
104102
or
105-
jcaSpec.getAlgoSpec().(StringLiteral).getValue().toUpperCase().matches("EC%") and
106-
typeFlag = "asymmetric-ec"
103+
getAlgoName(jcaSpec).matches("EC%") and typeFlag = "asymmetric-ec"
107104
) and
108105
DataFlow::localExprFlow(jcaSpec, ma.getQualifier()) and
109106
node.asExpr() = ma.getArgument(0)
110107
)
111108
}
112109

110+
// TODO: this predicate is just a poc for more code condensing; redo this
111+
private string getAlgoName(JavaxCryptoAlgoSpec jca) {
112+
result = jca.getAlgoSpec().(StringLiteral).getValue().toUpperCase()
113+
}
114+
113115
// TODO: rethink the predicate name; also think about whether this could/should be a class instead; or a predicate within the sink class so can do sink.predicate()...
114116
// TODO: can prbly re-work way using the typeFlag to be better and less repetitive
115117
private predicate hasKeySizeInSpec(DataFlow::Node node, string typeFlag) {

0 commit comments

Comments
 (0)