Skip to content

Commit 1b1b333

Browse files
committed
Crypto: Modify suggested queries per misc. side conversations on standards. Remove redundant query. Fix QL-for-QL issues.
1 parent cf88e3f commit 1b1b333

File tree

9 files changed

+59
-47
lines changed

9 files changed

+59
-47
lines changed

java/ql/src/experimental/quantum/Analysis/NonceReuse.ql

Lines changed: 0 additions & 17 deletions
This file was deleted.

java/ql/src/experimental/quantum/Analysis/ReusedNonce.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @id java/quantum/reused-nonce
55
* @kind problem
66
* @problem.severity error
7-
* @precision medium
7+
* @precision high
88
* @tags quantum
99
* experimental
1010
*/

java/ql/src/experimental/quantum/Analysis/WeakAsymmetric.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @name Weak Asymetric Key Size
2+
* @name Weak Asymmetric Key Size
33
* @id java/quantum/weak-asymmetric-key-size
44
* @description An asymmetric cipher with a short key size is in use
55
* @kind problem
@@ -20,5 +20,5 @@ where
2020
// Can't be an elliptic curve
2121
not Crypto::isEllipticCurveAlgorithmName(algName)
2222
select op,
23-
"Use of weak asymmetric key size (int bits)" + keySize.toString() + " for algorithm " +
24-
algName.toString() + " at config source $@", configSrc, configSrc.toString()
23+
"Use of weak asymmetric key size (" + keySize.toString() + " bits) for algorithm " +
24+
algName.toString() + " at config source $@", configSrc, configSrc.toString()

java/ql/src/experimental/quantum/Analysis/WeakBlockModes.ql

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@ import experimental.quantum.Language
1515
class WeakAESBlockModeAlgNode extends Crypto::KeyOperationAlgorithmNode {
1616
WeakAESBlockModeAlgNode() {
1717
this.getAlgorithmType() = Crypto::KeyOpAlg::TSymmetricCipher(Crypto::KeyOpAlg::AES()) and
18-
(this.getModeOfOperation().getModeType() = Crypto::KeyOpAlg::ECB() or
19-
this.getModeOfOperation().getModeType() = Crypto::KeyOpAlg::CFB() or
20-
this.getModeOfOperation().getModeType() = Crypto::KeyOpAlg::OFB() or
21-
this.getModeOfOperation().getModeType() = Crypto::KeyOpAlg::CTR()
18+
(
19+
this.getModeOfOperation().getModeType() = Crypto::KeyOpAlg::ECB() or
20+
this.getModeOfOperation().getModeType() = Crypto::KeyOpAlg::CFB() or
21+
this.getModeOfOperation().getModeType() = Crypto::KeyOpAlg::OFB() or
22+
this.getModeOfOperation().getModeType() = Crypto::KeyOpAlg::CTR()
2223
)
2324
}
2425
}
2526

2627
from Crypto::KeyOperationNode op, Crypto::KeyOperationOutputNode codeNode
27-
where op.getAKnownAlgorithm() instanceof WeakAESBlockModeAlgNode and
28-
codeNode = op.getAnOutputArtifact()
28+
where
29+
op.getAKnownAlgorithm() instanceof WeakAESBlockModeAlgNode and
30+
codeNode = op.getAnOutputArtifact()
2931
select op, "Weak AES block mode instance."
Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,34 @@
11
/**
22
* @name Weak hashes
33
* @description Finds uses of cryptographic hashing algorithms that are unapproved or otherwise weak.
4-
* @id java/quantum/slices/weak-hashes
4+
* @id java/quantum/weak-hashes
55
* @kind problem
66
* @problem.severity error
77
* @precision high
88
* @tags external/cwe/cwe-327
9+
* quantum
10+
* experimental
911
*/
1012

1113
import java
1214
import experimental.quantum.Language
1315

14-
from Crypto::HashAlgorithmNode alg, string name, string msg
16+
from Crypto::HashAlgorithmNode alg, Crypto::HashType htype, string msg
1517
where
16-
name = alg.getAlgorithmName() and
17-
not name in ["SHA256", "SHA384", "SHA512", "SHA-256", "SHA-384", "SHA-512"] and
18-
msg = "Use of unapproved hash algorithm or API " + name + "."
18+
htype = alg.getHashType() and
19+
(
20+
htype != Crypto::SHA2() and
21+
msg = "Use of unapproved hash algorithm or API " + htype.toString() + "."
22+
or
23+
htype = Crypto::SHA2() and
24+
not exists(alg.getDigestLength()) and
25+
msg =
26+
"Use of approved hash algorithm or API type " + htype.toString() + " but unknown digest size."
27+
or
28+
htype = Crypto::SHA2() and
29+
alg.getDigestLength() < 256 and
30+
msg =
31+
"Use of approved hash algorithm or API type " + htype.toString() + " but weak digest size (" +
32+
alg.getDigestLength() + ")."
33+
)
1934
select alg, msg

java/ql/src/experimental/quantum/Analysis/WeakKDFKeySize.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @name Weak known key derivation function output length
33
* @description Detects key derivation operations with a known weak output length
4-
* @id java/quantum/weak-kdf-iteration-count
4+
* @id java/quantum/weak-kdf-key-size
55
* @kind problem
66
* @problem.severity error
77
* @precision high
@@ -17,4 +17,4 @@ where
1717
op.getOutputKeySize().asElement() = l and
1818
l.getValue().toInt() < 256
1919
select op, "Key derivation operation configures output key length below 256: $@", l,
20-
l.getValue().toString()
20+
l.getValue().toString()

java/ql/src/experimental/quantum/Analysis/WeakRSA.ql

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@
1111

1212
import experimental.quantum.Language
1313

14-
class WeakRSAAlgorithmNode extends Crypto::KeyOperationAlgorithmNode {
15-
WeakRSAAlgorithmNode() {
14+
class WeakRsaAlgorithmNode extends Crypto::KeyOperationAlgorithmNode {
15+
WeakRsaAlgorithmNode() {
1616
this.getAlgorithmType() = Crypto::KeyOpAlg::TAsymmetricCipher(Crypto::KeyOpAlg::RSA()) and
1717
this.getKeySizeFixed() < 2048
1818
}
1919
}
2020

2121
from Crypto::KeyOperationNode op, string message
22-
where op.getAKnownAlgorithm() instanceof WeakRSAAlgorithmNode and
23-
message = "Weak RSA instance found with key length <2048"
22+
where
23+
op.getAKnownAlgorithm() instanceof WeakRsaAlgorithmNode and
24+
message = "Weak RSA instance found with key length <2048"
2425
select op, message
Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,30 @@
11
/**
22
* @name Weak symmetric ciphers
33
* @description Finds uses of cryptographic symmetric cipher algorithms that are unapproved or otherwise weak.
4-
* @id java/quantum/slices/weak-ciphers
4+
* @id java/quantum/weak-ciphers
55
* @kind problem
66
* @problem.severity error
77
* @precision high
88
* @tags external/cwe/cwe-327
9+
* quantum
10+
* experimental
911
*/
1012

1113
import java
1214
import experimental.quantum.Language
15+
import Crypto::KeyOpAlg as KeyOpAlg
1316

14-
from Crypto::KeyOperationAlgorithmNode alg, string name, string msg
17+
from Crypto::KeyOperationAlgorithmNode alg, KeyOpAlg::AlgorithmType algType, string msg
1518
where
16-
name = alg.getAlgorithmName() and
17-
name in ["DES", "TripleDES", "DoubleDES", "RC2", "RC4", "IDEA", "Blowfish"] and
18-
msg = "Use of unapproved symmetric cipher algorithm or API: " + name + "."
19-
select alg, msg
19+
algType = alg.getAlgorithmType() and
20+
(
21+
algType = KeyOpAlg::TSymmetricCipher(KeyOpAlg::DES()) or
22+
algType = KeyOpAlg::TSymmetricCipher(KeyOpAlg::TRIPLE_DES()) or
23+
algType = KeyOpAlg::TSymmetricCipher(KeyOpAlg::DOUBLE_DES()) or
24+
algType = KeyOpAlg::TSymmetricCipher(KeyOpAlg::RC2()) or
25+
algType = KeyOpAlg::TSymmetricCipher(KeyOpAlg::RC4()) or
26+
algType = KeyOpAlg::TSymmetricCipher(KeyOpAlg::IDEA()) or
27+
algType = KeyOpAlg::TSymmetricCipher(KeyOpAlg::BLOWFISH())
28+
) and
29+
msg = "Use of unapproved symmetric cipher algorithm or API: " + algType.toString() + "."
30+
select alg, msg

shared/quantum/codeql/quantum/experimental/Standardization.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ module Types {
344344
/**
345345
* Elliptic curve algorithms
346346
*/
347-
newtype TEllipticCurveFamilyType =
347+
newtype TEllipticCurveType =
348348
NIST() or
349349
SEC() or
350350
NUMS() or
@@ -357,7 +357,7 @@ module Types {
357357
ES() or
358358
OtherEllipticCurveType()
359359

360-
class EllipticCurveFamilyType extends TEllipticCurveFamilyType {
360+
class EllipticCurveType extends TEllipticCurveType {
361361
string toString() {
362362
this = NIST() and result = "NIST"
363363
or
@@ -445,7 +445,7 @@ module Types {
445445
*/
446446
bindingset[rawName]
447447
predicate ellipticCurveNameToKnownKeySizeAndFamilyMapping(
448-
string rawName, int keySize, TEllipticCurveFamilyType curveFamily
448+
string rawName, int keySize, TEllipticCurveType curveFamily
449449
) {
450450
exists(string curveName | curveName = rawName.toUpperCase() |
451451
isSecCurve(curveName, keySize) and curveFamily = SEC()

0 commit comments

Comments
 (0)