Skip to content

Commit dc8b62b

Browse files
Jami CogswellJami Cogswell
authored andcommitted
add support for AlgorithmParameterGenerator
1 parent ff557a2 commit dc8b62b

File tree

2 files changed

+46
-5
lines changed

2 files changed

+46
-5
lines changed

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

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ class JavaSecuritySignature extends JavaSecurityAlgoSpec {
389389
override Expr getAlgoSpec() { result = this.(ConstructorCall).getArgument(0) }
390390
}
391391

392-
/** A method call to the Java class `java.security.KeyPairGenerator`. */
392+
/** An instance of a `java.security.KeyPairGenerator`. */
393393
class JavaSecurityKeyPairGenerator extends JavaSecurityAlgoSpec {
394394
JavaSecurityKeyPairGenerator() {
395395
exists(Constructor c | c.getAReference() = this |
@@ -405,6 +405,41 @@ class JavaSecurityKeyPairGenerator extends JavaSecurityAlgoSpec {
405405
override Expr getAlgoSpec() { result = this.(Call).getArgument(0) }
406406
}
407407

408+
/** The Java class `java.security.AlgorithmParameterGenerator`. */
409+
class AlgorithmParameterGenerator extends RefType {
410+
AlgorithmParameterGenerator() {
411+
this.hasQualifiedName("java.security", "AlgorithmParameterGenerator")
412+
}
413+
}
414+
415+
/** The `init` method declared in `java.security.AlgorithmParameterGenerator`. */
416+
class AlgoParamGeneratorInitMethod extends Method {
417+
AlgoParamGeneratorInitMethod() {
418+
this.getDeclaringType() instanceof AlgorithmParameterGenerator and
419+
this.hasName("init")
420+
}
421+
}
422+
423+
/** An instance of a `java.security.AlgorithmParameterGenerator`. */
424+
class JavaSecurityAlgoParamGenerator extends JavaSecurityAlgoSpec {
425+
JavaSecurityAlgoParamGenerator() {
426+
exists(Constructor c | c.getAReference() = this |
427+
c.getDeclaringType() instanceof AlgorithmParameterGenerator
428+
)
429+
or
430+
exists(Method m | m.getAReference() = this |
431+
m.getDeclaringType() instanceof AlgorithmParameterGenerator and
432+
m.getName() = "getInstance"
433+
)
434+
}
435+
436+
override Expr getAlgoSpec() {
437+
exists(Call c | c = this |
438+
if c.getNumArgument() = 3 then result = c.getArgument(2) else result = c.getArgument(0)
439+
)
440+
}
441+
}
442+
408443
/** The Java interface `java.security.spec.AlgorithmParameterSpec` */
409444
abstract class AlgorithmParameterSpec extends RefType { }
410445

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,10 @@ abstract class KeyGenInitMethodAccess extends MethodAccess {
131131

132132
/** A call to the `initialize` method declared in `java.security.KeyPairGenerator`. */
133133
private class AsymmetricInitMethodAccess extends KeyGenInitMethodAccess {
134-
AsymmetricInitMethodAccess() { this.getMethod() instanceof KeyPairGeneratorInitMethod }
134+
AsymmetricInitMethodAccess() {
135+
this.getMethod() instanceof KeyPairGeneratorInitMethod or
136+
this.getMethod() instanceof AlgoParamGeneratorInitMethod
137+
}
135138
}
136139

137140
/** A call to the `init` method declared in `javax.crypto.KeyGenerator`. */
@@ -146,16 +149,19 @@ abstract class KeyGeneratorObject extends CryptoAlgoSpec {
146149

147150
/** An instance of a `java.security.KeyPairGenerator`. */
148151
private class AsymmetricKeyGenerator extends KeyGeneratorObject {
149-
AsymmetricKeyGenerator() { this instanceof JavaSecurityKeyPairGenerator }
152+
AsymmetricKeyGenerator() {
153+
this instanceof JavaSecurityKeyPairGenerator or
154+
this instanceof JavaSecurityAlgoParamGenerator
155+
}
150156

151-
override Expr getAlgoSpec() { result = this.(MethodAccess).getArgument(0) }
157+
override Expr getAlgoSpec() { result = this.getAlgoSpec() }
152158
}
153159

154160
/** An instance of a `javax.crypto.KeyGenerator`. */
155161
private class SymmetricKeyGenerator extends KeyGeneratorObject {
156162
SymmetricKeyGenerator() { this instanceof JavaxCryptoKeyGenerator }
157163

158-
override Expr getAlgoSpec() { result = this.(MethodAccess).getArgument(0) }
164+
override Expr getAlgoSpec() { result = this.getAlgoSpec() }
159165
}
160166

161167
/** An instance of an algorithm specification. */

0 commit comments

Comments
 (0)