-
I am trying to scan the ECB mode, which is this API: /* package org.cambench.cap.basic.ecbmode; import javax.crypto.Cipher; import javax.crypto.KeyGenerator; import javax.crypto.NoSuchPaddingException; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; public class EcbMode1 { public static void main(String[] args) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException { Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); KeyGenerator keyGen = KeyGenerator.getInstance("AES"); cipher.init(Cipher.ENCRYPT_MODE,keyGen.generateKey()); } } I used the QL code scan I completed myself, but I don't know where the problem lies? I didn't scan any results. /** * @kind path-problem * @id java/0-javax-getInstance-misuse * @problem.severity error * @precision high * @tags security */ import java import semmle.code.java.dataflow.FlowSources import DataFlow::PathGraph module A0ModeUsage implements DataFlow::ConfigSig { predicate isSource(DataFlow::Node source) { exists(StringLiteral str | (str.getValue().toUpperCase().matches("%ECB%")) and source.asExpr() = str ) } predicate isSink(DataFlow::Node sink) { exists(Call call | call.getCallee().(Constructor).getDeclaringType().hasQualifiedName("javax.crypto.Cipher","getInstance") and sink.asExpr()=call.getArgument(0) ) } } module A0ModeUsageFlow = TaintTracking::Global; from A0ModeUsageFlow::PathNode source, A0ModeUsageFlow::PathNode sink where A0ModeUsageFlow::flowPath(source, sink) select sink.getNode(), source, sink, "I find one ECB" |
Beta Was this translation helpful? Give feedback.
Answered by
kexinoh
May 17, 2024
Replies: 1 comment 3 replies
-
Hi @kexinoh, From a quick read, I can see see you are matching a
or just
|
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i work it by this:
exists(MethodCall api | api.getQualifier().getType().(RefType).hasQualifiedName("javax.crypto","Cipher") and api.getMethod().getName() = "getInstance" and sink.asExpr()=api.getAnArgument() )