Skip to content

Commit c6cc4ff

Browse files
committed
Crypto: Minor fixes to WeakBlockModes, WeakHash to consider SHA3 ok, Added unknown hash.
1 parent f524de4 commit c6cc4ff

File tree

3 files changed

+32
-13
lines changed

3 files changed

+32
-13
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @name Unknown hashes
3+
* @description Finds uses of cryptographic hashing algorithms of unknown type.
4+
* @id java/quantum/unknown-hash
5+
* @kind problem
6+
* @problem.severity error
7+
* @precision high
8+
* @tags quantum
9+
* experimental
10+
*/
11+
12+
import java
13+
import experimental.quantum.Language
14+
15+
from Crypto::HashAlgorithmNode alg
16+
where not exists(alg.getHashType())
17+
select alg, "Use of unknown hash algorithm or API."

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,21 @@ import java
1313
import experimental.quantum.Language
1414

1515
class WeakAESBlockModeAlgNode extends Crypto::KeyOperationAlgorithmNode {
16+
Crypto::ModeOfOperationAlgorithmNode mode;
17+
1618
WeakAESBlockModeAlgNode() {
1719
this.getAlgorithmType() = Crypto::KeyOpAlg::TSymmetricCipher(Crypto::KeyOpAlg::AES()) and
20+
mode = super.getModeOfOperation() and
1821
(
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()
22+
mode.getModeType() = Crypto::KeyOpAlg::ECB() or
23+
mode.getModeType() = Crypto::KeyOpAlg::CFB() or
24+
mode.getModeType() = Crypto::KeyOpAlg::OFB() or
25+
mode.getModeType() = Crypto::KeyOpAlg::CTR()
2326
)
2427
}
28+
29+
Crypto::ModeOfOperationAlgorithmNode getMode() { result = mode }
2530
}
2631

27-
from Crypto::KeyOperationNode op, Crypto::KeyOperationOutputNode codeNode
28-
where
29-
op.getAKnownAlgorithm() instanceof WeakAESBlockModeAlgNode and
30-
codeNode = op.getAnOutputArtifact()
31-
select op, "Weak AES block mode instance."
32+
from WeakAESBlockModeAlgNode alg
33+
select alg, "Weak AES block mode instance $@.", alg.getMode(), alg.getMode().toString()

java/ql/src/experimental/quantum/Analysis/WeakHashing.ql renamed to java/ql/src/experimental/quantum/Analysis/WeakHash.ql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @name Weak hashes
33
* @description Finds uses of cryptographic hashing algorithms that are unapproved or otherwise weak.
4-
* @id java/quantum/weak-hashes
4+
* @id java/quantum/weak-hash
55
* @kind problem
66
* @problem.severity error
77
* @precision high
@@ -17,15 +17,15 @@ from Crypto::HashAlgorithmNode alg, Crypto::HashType htype, string msg
1717
where
1818
htype = alg.getHashType() and
1919
(
20-
htype != Crypto::SHA2() and
20+
(htype != Crypto::SHA2() and htype != Crypto::SHA2()) and
2121
msg = "Use of unapproved hash algorithm or API " + htype.toString() + "."
2222
or
23-
htype = Crypto::SHA2() and
23+
(htype = Crypto::SHA2() or htype = Crypto::SHA3()) and
2424
not exists(alg.getDigestLength()) and
2525
msg =
2626
"Use of approved hash algorithm or API type " + htype.toString() + " but unknown digest size."
2727
or
28-
htype = Crypto::SHA2() and
28+
(htype = Crypto::SHA2() or htype = Crypto::SHA3()) and
2929
alg.getDigestLength() < 256 and
3030
msg =
3131
"Use of approved hash algorithm or API type " + htype.toString() + " but weak digest size (" +

0 commit comments

Comments
 (0)