mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
Crypto: Modify suggested queries per misc. side conversations on standards. Remove redundant query. Fix QL-for-QL issues.
This commit is contained in:
@@ -1,17 +0,0 @@
|
|||||||
/**
|
|
||||||
* @name Reuse of cryptographic nonce
|
|
||||||
* @description Reuse of nonce in cryptographic operations can lead to vulnerabilities.
|
|
||||||
* @id java/quantum/reused-nonce
|
|
||||||
* @kind problem
|
|
||||||
* @problem.severity error
|
|
||||||
* @precision medium
|
|
||||||
* @tags quantum
|
|
||||||
* experimental
|
|
||||||
*/
|
|
||||||
|
|
||||||
import java
|
|
||||||
import ArtifactReuse
|
|
||||||
|
|
||||||
from Crypto::NonceArtifactNode nonce1, Crypto::NonceArtifactNode nonce2
|
|
||||||
where isArtifactReuse(nonce1, nonce2)
|
|
||||||
select nonce1, "Reuse with nonce $@", nonce2, nonce2.toString()
|
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
* @id java/quantum/reused-nonce
|
* @id java/quantum/reused-nonce
|
||||||
* @kind problem
|
* @kind problem
|
||||||
* @problem.severity error
|
* @problem.severity error
|
||||||
* @precision medium
|
* @precision high
|
||||||
* @tags quantum
|
* @tags quantum
|
||||||
* experimental
|
* experimental
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* @name Weak Asymetric Key Size
|
* @name Weak Asymmetric Key Size
|
||||||
* @id java/quantum/weak-asymmetric-key-size
|
* @id java/quantum/weak-asymmetric-key-size
|
||||||
* @description An asymmetric cipher with a short key size is in use
|
* @description An asymmetric cipher with a short key size is in use
|
||||||
* @kind problem
|
* @kind problem
|
||||||
@@ -20,5 +20,5 @@ where
|
|||||||
// Can't be an elliptic curve
|
// Can't be an elliptic curve
|
||||||
not Crypto::isEllipticCurveAlgorithmName(algName)
|
not Crypto::isEllipticCurveAlgorithmName(algName)
|
||||||
select op,
|
select op,
|
||||||
"Use of weak asymmetric key size (int bits)" + keySize.toString() + " for algorithm " +
|
"Use of weak asymmetric key size (" + keySize.toString() + " bits) for algorithm " +
|
||||||
algName.toString() + " at config source $@", configSrc, configSrc.toString()
|
algName.toString() + " at config source $@", configSrc, configSrc.toString()
|
||||||
|
|||||||
@@ -15,15 +15,17 @@ import experimental.quantum.Language
|
|||||||
class WeakAESBlockModeAlgNode extends Crypto::KeyOperationAlgorithmNode {
|
class WeakAESBlockModeAlgNode extends Crypto::KeyOperationAlgorithmNode {
|
||||||
WeakAESBlockModeAlgNode() {
|
WeakAESBlockModeAlgNode() {
|
||||||
this.getAlgorithmType() = Crypto::KeyOpAlg::TSymmetricCipher(Crypto::KeyOpAlg::AES()) and
|
this.getAlgorithmType() = Crypto::KeyOpAlg::TSymmetricCipher(Crypto::KeyOpAlg::AES()) and
|
||||||
(this.getModeOfOperation().getModeType() = Crypto::KeyOpAlg::ECB() or
|
(
|
||||||
this.getModeOfOperation().getModeType() = Crypto::KeyOpAlg::CFB() or
|
this.getModeOfOperation().getModeType() = Crypto::KeyOpAlg::ECB() or
|
||||||
this.getModeOfOperation().getModeType() = Crypto::KeyOpAlg::OFB() or
|
this.getModeOfOperation().getModeType() = Crypto::KeyOpAlg::CFB() or
|
||||||
this.getModeOfOperation().getModeType() = Crypto::KeyOpAlg::CTR()
|
this.getModeOfOperation().getModeType() = Crypto::KeyOpAlg::OFB() or
|
||||||
|
this.getModeOfOperation().getModeType() = Crypto::KeyOpAlg::CTR()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
from Crypto::KeyOperationNode op, Crypto::KeyOperationOutputNode codeNode
|
from Crypto::KeyOperationNode op, Crypto::KeyOperationOutputNode codeNode
|
||||||
where op.getAKnownAlgorithm() instanceof WeakAESBlockModeAlgNode and
|
where
|
||||||
codeNode = op.getAnOutputArtifact()
|
op.getAKnownAlgorithm() instanceof WeakAESBlockModeAlgNode and
|
||||||
|
codeNode = op.getAnOutputArtifact()
|
||||||
select op, "Weak AES block mode instance."
|
select op, "Weak AES block mode instance."
|
||||||
|
|||||||
@@ -1,19 +1,34 @@
|
|||||||
/**
|
/**
|
||||||
* @name Weak hashes
|
* @name Weak hashes
|
||||||
* @description Finds uses of cryptographic hashing algorithms that are unapproved or otherwise weak.
|
* @description Finds uses of cryptographic hashing algorithms that are unapproved or otherwise weak.
|
||||||
* @id java/quantum/slices/weak-hashes
|
* @id java/quantum/weak-hashes
|
||||||
* @kind problem
|
* @kind problem
|
||||||
* @problem.severity error
|
* @problem.severity error
|
||||||
* @precision high
|
* @precision high
|
||||||
* @tags external/cwe/cwe-327
|
* @tags external/cwe/cwe-327
|
||||||
|
* quantum
|
||||||
|
* experimental
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java
|
import java
|
||||||
import experimental.quantum.Language
|
import experimental.quantum.Language
|
||||||
|
|
||||||
from Crypto::HashAlgorithmNode alg, string name, string msg
|
from Crypto::HashAlgorithmNode alg, Crypto::HashType htype, string msg
|
||||||
where
|
where
|
||||||
name = alg.getAlgorithmName() and
|
htype = alg.getHashType() and
|
||||||
not name in ["SHA256", "SHA384", "SHA512", "SHA-256", "SHA-384", "SHA-512"] and
|
(
|
||||||
msg = "Use of unapproved hash algorithm or API " + name + "."
|
htype != Crypto::SHA2() and
|
||||||
|
msg = "Use of unapproved hash algorithm or API " + htype.toString() + "."
|
||||||
|
or
|
||||||
|
htype = Crypto::SHA2() and
|
||||||
|
not exists(alg.getDigestLength()) and
|
||||||
|
msg =
|
||||||
|
"Use of approved hash algorithm or API type " + htype.toString() + " but unknown digest size."
|
||||||
|
or
|
||||||
|
htype = Crypto::SHA2() and
|
||||||
|
alg.getDigestLength() < 256 and
|
||||||
|
msg =
|
||||||
|
"Use of approved hash algorithm or API type " + htype.toString() + " but weak digest size (" +
|
||||||
|
alg.getDigestLength() + ")."
|
||||||
|
)
|
||||||
select alg, msg
|
select alg, msg
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
* @name Weak known key derivation function output length
|
* @name Weak known key derivation function output length
|
||||||
* @description Detects key derivation operations with a known weak output length
|
* @description Detects key derivation operations with a known weak output length
|
||||||
* @id java/quantum/weak-kdf-iteration-count
|
* @id java/quantum/weak-kdf-key-size
|
||||||
* @kind problem
|
* @kind problem
|
||||||
* @problem.severity error
|
* @problem.severity error
|
||||||
* @precision high
|
* @precision high
|
||||||
@@ -17,4 +17,4 @@ where
|
|||||||
op.getOutputKeySize().asElement() = l and
|
op.getOutputKeySize().asElement() = l and
|
||||||
l.getValue().toInt() < 256
|
l.getValue().toInt() < 256
|
||||||
select op, "Key derivation operation configures output key length below 256: $@", l,
|
select op, "Key derivation operation configures output key length below 256: $@", l,
|
||||||
l.getValue().toString()
|
l.getValue().toString()
|
||||||
|
|||||||
@@ -11,14 +11,15 @@
|
|||||||
|
|
||||||
import experimental.quantum.Language
|
import experimental.quantum.Language
|
||||||
|
|
||||||
class WeakRSAAlgorithmNode extends Crypto::KeyOperationAlgorithmNode {
|
class WeakRsaAlgorithmNode extends Crypto::KeyOperationAlgorithmNode {
|
||||||
WeakRSAAlgorithmNode() {
|
WeakRsaAlgorithmNode() {
|
||||||
this.getAlgorithmType() = Crypto::KeyOpAlg::TAsymmetricCipher(Crypto::KeyOpAlg::RSA()) and
|
this.getAlgorithmType() = Crypto::KeyOpAlg::TAsymmetricCipher(Crypto::KeyOpAlg::RSA()) and
|
||||||
this.getKeySizeFixed() < 2048
|
this.getKeySizeFixed() < 2048
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
from Crypto::KeyOperationNode op, string message
|
from Crypto::KeyOperationNode op, string message
|
||||||
where op.getAKnownAlgorithm() instanceof WeakRSAAlgorithmNode and
|
where
|
||||||
message = "Weak RSA instance found with key length <2048"
|
op.getAKnownAlgorithm() instanceof WeakRsaAlgorithmNode and
|
||||||
|
message = "Weak RSA instance found with key length <2048"
|
||||||
select op, message
|
select op, message
|
||||||
|
|||||||
@@ -1,19 +1,30 @@
|
|||||||
/**
|
/**
|
||||||
* @name Weak symmetric ciphers
|
* @name Weak symmetric ciphers
|
||||||
* @description Finds uses of cryptographic symmetric cipher algorithms that are unapproved or otherwise weak.
|
* @description Finds uses of cryptographic symmetric cipher algorithms that are unapproved or otherwise weak.
|
||||||
* @id java/quantum/slices/weak-ciphers
|
* @id java/quantum/weak-ciphers
|
||||||
* @kind problem
|
* @kind problem
|
||||||
* @problem.severity error
|
* @problem.severity error
|
||||||
* @precision high
|
* @precision high
|
||||||
* @tags external/cwe/cwe-327
|
* @tags external/cwe/cwe-327
|
||||||
|
* quantum
|
||||||
|
* experimental
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java
|
import java
|
||||||
import experimental.quantum.Language
|
import experimental.quantum.Language
|
||||||
|
import Crypto::KeyOpAlg as KeyOpAlg
|
||||||
|
|
||||||
from Crypto::KeyOperationAlgorithmNode alg, string name, string msg
|
from Crypto::KeyOperationAlgorithmNode alg, KeyOpAlg::AlgorithmType algType, string msg
|
||||||
where
|
where
|
||||||
name = alg.getAlgorithmName() and
|
algType = alg.getAlgorithmType() and
|
||||||
name in ["DES", "TripleDES", "DoubleDES", "RC2", "RC4", "IDEA", "Blowfish"] and
|
(
|
||||||
msg = "Use of unapproved symmetric cipher algorithm or API: " + name + "."
|
algType = KeyOpAlg::TSymmetricCipher(KeyOpAlg::DES()) or
|
||||||
select alg, msg
|
algType = KeyOpAlg::TSymmetricCipher(KeyOpAlg::TRIPLE_DES()) or
|
||||||
|
algType = KeyOpAlg::TSymmetricCipher(KeyOpAlg::DOUBLE_DES()) or
|
||||||
|
algType = KeyOpAlg::TSymmetricCipher(KeyOpAlg::RC2()) or
|
||||||
|
algType = KeyOpAlg::TSymmetricCipher(KeyOpAlg::RC4()) or
|
||||||
|
algType = KeyOpAlg::TSymmetricCipher(KeyOpAlg::IDEA()) or
|
||||||
|
algType = KeyOpAlg::TSymmetricCipher(KeyOpAlg::BLOWFISH())
|
||||||
|
) and
|
||||||
|
msg = "Use of unapproved symmetric cipher algorithm or API: " + algType.toString() + "."
|
||||||
|
select alg, msg
|
||||||
|
|||||||
@@ -344,7 +344,7 @@ module Types {
|
|||||||
/**
|
/**
|
||||||
* Elliptic curve algorithms
|
* Elliptic curve algorithms
|
||||||
*/
|
*/
|
||||||
newtype TEllipticCurveFamilyType =
|
newtype TEllipticCurveType =
|
||||||
NIST() or
|
NIST() or
|
||||||
SEC() or
|
SEC() or
|
||||||
NUMS() or
|
NUMS() or
|
||||||
@@ -357,7 +357,7 @@ module Types {
|
|||||||
ES() or
|
ES() or
|
||||||
OtherEllipticCurveType()
|
OtherEllipticCurveType()
|
||||||
|
|
||||||
class EllipticCurveFamilyType extends TEllipticCurveFamilyType {
|
class EllipticCurveType extends TEllipticCurveType {
|
||||||
string toString() {
|
string toString() {
|
||||||
this = NIST() and result = "NIST"
|
this = NIST() and result = "NIST"
|
||||||
or
|
or
|
||||||
@@ -445,7 +445,7 @@ module Types {
|
|||||||
*/
|
*/
|
||||||
bindingset[rawName]
|
bindingset[rawName]
|
||||||
predicate ellipticCurveNameToKnownKeySizeAndFamilyMapping(
|
predicate ellipticCurveNameToKnownKeySizeAndFamilyMapping(
|
||||||
string rawName, int keySize, TEllipticCurveFamilyType curveFamily
|
string rawName, int keySize, TEllipticCurveType curveFamily
|
||||||
) {
|
) {
|
||||||
exists(string curveName | curveName = rawName.toUpperCase() |
|
exists(string curveName | curveName = rawName.toUpperCase() |
|
||||||
isSecCurve(curveName, keySize) and curveFamily = SEC()
|
isSecCurve(curveName, keySize) and curveFamily = SEC()
|
||||||
|
|||||||
Reference in New Issue
Block a user