Skip to content

Commit c79a3eb

Browse files
Add query for insecure key generation
1 parent 75a2b94 commit c79a3eb

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/** Definitions for the insecure local authentication query. */
22

33
import java
4+
import semmle.code.java.dataflow.DataFlow
45

56
/** A base class that is used as a callback for biometric authentication. */
67
private class AuthenticationCallbackClass extends Class {
@@ -40,3 +41,21 @@ class AuthenticationSuccessCallback extends Method {
4041
not result = this.getASuperResultUse()
4142
}
4243
}
44+
45+
/** A call that sets a parameter for key generation that is insecure for use with biometric authentication. */
46+
class InsecureBiometricKeyParam extends MethodCall {
47+
InsecureBiometricKeyParam() {
48+
exists(string name, CompileTimeConstantExpr val |
49+
this.getMethod()
50+
.hasQualifiedName("android.security.keystore", "KeyGenParameterSpec$Builder", name) and
51+
DataFlow::localExprFlow(val, this.getArgument(0)) and
52+
(
53+
name = ["setUserAuthenticationRequired", "setInvalidatedByBiometricEnrollment"] and
54+
val.getBooleanValue() = false
55+
or
56+
name = "setUserAuthenticationValidityDurationSeconds" and
57+
val.getIntValue() != -1
58+
)
59+
)
60+
}
61+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @name Insecurely generated keys for local authentication
3+
* @description Keys used for local biometric authentication should be generated with secure parameters.
4+
* @kind problem
5+
* @problem.severity warning
6+
* @security-severity 9.3
7+
* @precision medium
8+
* @id java/android/insecure-local-key-gen
9+
* @tags security
10+
* external/cwe/cwe-287
11+
*/
12+
13+
import java
14+
import semmle.code.java.security.AndroidLocalAuthQuery
15+
16+
/** Holds if the application contains an instance of a key being used for local biometric authentication. */
17+
predicate usesLocalAuth() { exists(AuthenticationSuccessCallback cb | exists(cb.getAResultUse())) }
18+
19+
from InsecureBiometricKeyParam call
20+
where usesLocalAuth()
21+
select call, "This key is not secure for biometric authentication."

0 commit comments

Comments
 (0)