-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Crypto: Add Java Cryptographic Analysis Queries #20605
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nicolaswill
merged 71 commits into
github:main
from
bdrodes:santander-java-crypto-check
Oct 22, 2025
Merged
Changes from 18 commits
Commits
Show all changes
71 commits
Select commit
Hold shift + click to select a range
c5cf0ff
added java cryptographic check queries
unprovable f38ab45
removed all @security.severity ratings to keep the main impartial
unprovable bba541c
Merge remote-tracking branch 'upstream/java-crypto-check' into santan…
bdrodes cf88e3f
Crypto: Standardize naming where use of "family" and "type" have been…
bdrodes 1b1b333
Crypto: Modify suggested queries per misc. side conversations on stan…
bdrodes 143be8c
Crypto: Remove redundant queries.
bdrodes bd34b6c
Crypto: Removing JCA model of random, need to reassess this as this i…
bdrodes 83ff70b
Crypto: Adding tests for insecure iv or nonce. Updating generic liter…
bdrodes 8e10e19
Crypto: Adding query for unknown IV initialization.
bdrodes 75b5a9f
Crypto: Update general regression test results to account for removal…
bdrodes 11e8139
Crypto: Updated default flows to use taint tracking (this is needed t…
bdrodes 7a57496
Crypto: Missing test update.
bdrodes f524de4
Crypto: Updating insecure iv/nonce to consider if an operation is kno…
bdrodes fdba3ac
Crypto: Fix QL-for-QL alert and auto-format
nicolaswill c6cc4ff
Crypto: Minor fixes to WeakBlockModes, WeakHash to consider SHA3 ok, …
bdrodes 3dedda4
Merge branch 'santander-java-crypto-check' of https://github.com/bdro…
bdrodes deb4373
Crypto: Minor fixes to WeakSymmetricCipher, change to a singular name…
bdrodes fba8087
Crypto: Example query reorg - moving queries of this PR into 'example…
bdrodes 758759a
Crypto: Reused nonce query updates and test updates to address false …
bdrodes 3667365
Crypto: Weak asymmetric key gen size fixes and test.
bdrodes ffd191d
Crypto: missing new endpoint to get the creating operation for a key …
bdrodes d68f3cf
Crypto: InsecureIVorNonceSource now ignored null to avoid being too n…
bdrodes e76ced1
Crypto: Updating weak asymmetric key gen to include key exchange.
bdrodes 08abdb8
Crypto: Adding a "javaConstant" concept to handle config files.
bdrodes 4b241d7
Crypto: adding initial weak hash query overhaul and tests, but no exp…
bdrodes bd068c2
Crypto: Updating expected file for weak asymmetric key gen size.
bdrodes 76128ed
Crypto: Update InsecureIVorNonce to be a path problem.
bdrodes 7847e92
Crypto: Update KDF iteration and count to be path problems
bdrodes 8b5a423
Crypto: Convert ReusedNonce.ql into a path problem.
bdrodes 7e8acd7
Crypto: Update WeakAsymmetricKeyGenSize to a path problem.
bdrodes 55bbcee
Crypto: Make WeakAsymmetricKeyGenSize a path problem.
bdrodes ee08385
Crytpo: Update JCA keyagreement to type conversion, XDH is a type of …
bdrodes bf9a249
Crypto: Experimental queries for mac ordering
bdrodes c7be23e
Crypto: Remove all precision tags from all experimental queries. Prec…
bdrodes 631e482
Crytpo: when key encapsulation or cipher operations have multiple mod…
bdrodes c6174fb
Crypto: remove precision tag
bdrodes 9a6aac1
Crypto: To get unreferenced parameters as general sources for Java, I…
bdrodes 15e266d
Crypto: Tweaks to bad crypto ordering queries.
bdrodes 25599e9
crypto: Update JCA model macs to take into consideration update calls…
bdrodes 4860034
Crypto: Weak Hash test cases update and expected file.
bdrodes d2598d4
Crypto: Updating weak hash tests
bdrodes 79ccef3
Crypto: Initial sketch for unknown hash, the model needs to recognize…
bdrodes a64a24d
Crypto: Comment in Language.qll
bdrodes 3f36b09
Crypto: Rename tests for weak asymmetric key gen size.
bdrodes b9b0037
Crypto: Comment todo for observed missing modeled case. Tests for wea…
bdrodes 700f34e
Crypto: Bad Mac use tests, and fix for BadMacOrderMacOnEncryptPlainte…
bdrodes 5923e5c
Crypto: Bad expected files in last push.
bdrodes ef6f022
Crypto: Addressing FPs in BadMacOrderMacOnEncryptPlaintext
bdrodes ff7840d
Crypto: removing precision tags on experimental queries.
bdrodes 628bab9
Crypto: Modify BadMacOrderMacOnEncryptPlaintext to be a path query th…
bdrodes e127341
Crypto: WeakKDFKeySize tests.
bdrodes f480d90
Crypto: Add missing block mode JCA Models, add block mode unit tests
bdrodes b4ecb91
Crypto: Add missing cipher algorithms to JCA. Update node tests to ac…
bdrodes 1b205d8
Removing WeakRSA, this is redundant with weak asymmetric key size.
bdrodes b06e053
Crypto: altering all query IDs in examples to have "examples" in the …
bdrodes 540daa6
Crypto: weak symmetric cipher tests.
bdrodes c01c060
Crypto: more ID renaming to include "examples", fix singleton issues …
bdrodes 2b683c2
Merge branch 'main' into santander-java-crypto-check
bdrodes 354effe
Crypto: Missing hash algorithms for HMAC operations in jca.
bdrodes cc436e8
Merge branch 'santander-java-crypto-check' of https://github.com/bdro…
bdrodes eff94ef
Crypto: To allow for graph generation to have properties informed by …
bdrodes 22c0f9f
Crypto: Adding a proof of concept bad mac ordering predicate that tak…
bdrodes c50175b
Crypto: ql-for-ql alert fixes.
bdrodes ddeb42c
Crypto: Adding false positive to BadMacUse.java, we have no way to av…
bdrodes b374ba3
Crypto: Updating java 'location' information to be just a location's …
bdrodes dd60cf9
Crypto: Adjust output of bad mac order queries, update associated bad…
bdrodes db6d3ad
Crypto: Fix typo in not_included_in_qls.expected.
bdrodes e16543a
Merge branch 'main' into santander-java-crypto-check
bdrodes 3561d01
Crytpo: Trying to fix in pipeline test failure, experimentally alteri…
bdrodes 0837939
Crypto: Fix off by one column issue in unit tests.
bdrodes bdad95d
Crypto: Fixed alphabetical ordering issue in not_included_in_qls.expe…
bdrodes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 0 additions & 22 deletions
22
java/ql/src/experimental/quantum/Analysis/InsecureNonceSource.ql
This file was deleted.
Oops, something went wrong.
File renamed without changes.
47 changes: 47 additions & 0 deletions
47
java/ql/src/experimental/quantum/Examples/InsecureIVorNonceSource.ql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /** | ||
| * @name Insecure nonce/iv (static value or weak random source) | ||
| * @id java/quantum/insecure-iv-or-nonce | ||
| * @description A nonce/iv is generated from a source that is not secure. This can lead to | ||
| * vulnerabilities such as replay attacks or key recovery. Insecure generation | ||
| * is any static nonce, or any known insecure source for a nonce/iv if | ||
| * the value is used for an encryption operation (decryption operations are ignored | ||
| * as the nonce/iv would be provided alongside the ciphertext). | ||
| * @kind problem | ||
| * @problem.severity error | ||
| * @precision high | ||
| * @tags quantum | ||
| * experimental | ||
| */ | ||
|
|
||
| import experimental.quantum.Language | ||
|
|
||
| from Crypto::NonceArtifactNode nonce, Crypto::NodeBase src, Crypto::NodeBase op, string msg | ||
| where | ||
| nonce.getSourceNode() = src and | ||
| ( | ||
| // Case 1: Any constant nonce/iv is bad, regardless of how it is used | ||
| src.asElement() instanceof Crypto::GenericConstantSourceInstance and | ||
| op = nonce and // binding op by not using it | ||
| msg = "Nonce or IV uses constant source $@" | ||
| or | ||
| // Case 2: The nonce has a non-random source and there is no known operation for the nonce | ||
| // assume it is used for encryption | ||
| not src.asElement() instanceof SecureRandomnessInstance and | ||
| not src.asElement() instanceof Crypto::GenericConstantSourceInstance and | ||
| not exists(Crypto::CipherOperationNode o | o.getANonce() = nonce) and | ||
| op = nonce and // binding op, but not using it | ||
| msg = | ||
| "Nonce or IV uses insecure source $@ with no observed nonce usage (assuming could be for encryption)." | ||
| or | ||
| // Case 3: The nonce has a non-random source and is used in an encryption operation | ||
| not src.asElement() instanceof SecureRandomnessInstance and | ||
| not src.asElement() instanceof Crypto::GenericConstantSourceInstance and | ||
| op.(Crypto::CipherOperationNode).getANonce() = nonce and | ||
| ( | ||
| op.(Crypto::CipherOperationNode).getKeyOperationSubtype() instanceof Crypto::TEncryptMode | ||
| or | ||
| op.(Crypto::CipherOperationNode).getKeyOperationSubtype() instanceof Crypto::TWrapMode | ||
| ) and | ||
| msg = "Nonce or IV uses insecure source $@ at encryption operation $@" | ||
| ) | ||
| select nonce, msg, src, src.toString(), op, op.toString() |
25 changes: 25 additions & 0 deletions
25
java/ql/src/experimental/quantum/Examples/NonAESGCMCipher.ql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| /** | ||
| * @name Cipher not AES-GCM mode | ||
| * @id java/quantum/non-aes-gcm | ||
| * @description An AES cipher is in use without GCM | ||
| * @kind problem | ||
| * @problem.severity error | ||
| * @precision high | ||
| * @tags quantum | ||
| * experimental | ||
| */ | ||
|
|
||
| import experimental.quantum.Language | ||
|
|
||
| class NonAESGCMAlgorithmNode extends Crypto::KeyOperationAlgorithmNode { | ||
| NonAESGCMAlgorithmNode() { | ||
| this.getAlgorithmType() = Crypto::KeyOpAlg::TSymmetricCipher(Crypto::KeyOpAlg::AES()) and | ||
| this.getModeOfOperation().getModeType() != Crypto::KeyOpAlg::GCM() | ||
| } | ||
| } | ||
|
|
||
| from Crypto::KeyOperationNode op, Crypto::KeyOperationOutputNode codeNode | ||
| where | ||
| op.getAKnownAlgorithm() instanceof NonAESGCMAlgorithmNode and | ||
| codeNode = op.getAnOutputArtifact() | ||
| select op, "Non-AES-GCM instance." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| /** | ||
| * @name Unknown hashes | ||
| * @description Finds uses of cryptographic hashing algorithms of unknown type. | ||
| * @id java/quantum/unknown-hash | ||
| * @kind problem | ||
| * @problem.severity error | ||
| * @precision high | ||
| * @tags quantum | ||
| * experimental | ||
| */ | ||
|
|
||
| import java | ||
| import experimental.quantum.Language | ||
|
|
||
| from Crypto::HashAlgorithmNode alg | ||
| where not exists(alg.getHashType()) | ||
| select alg, "Use of unknown hash algorithm or API." |
36 changes: 36 additions & 0 deletions
36
java/ql/src/experimental/quantum/Examples/UnknownIVorNonceSource.ql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /** | ||
| * @name Unknown nonce/iv source | ||
| * @id java/quantum/unknown-iv-or-nonce-source | ||
| * @description A nonce/iv is generated from a source that is not secure. Failure to initialize | ||
| * an IV or nonce properly can lead to vulnerabilities such as replay attacks or key recovery. | ||
| * IV may be unknown at a decryption operation (IV would be provided alongside the ciphertext). | ||
| * These cases are ignored. | ||
| * @kind problem | ||
| * @problem.severity error | ||
| * @precision high | ||
| * @tags quantum | ||
| * experimental | ||
| */ | ||
|
|
||
| import experimental.quantum.Language | ||
|
|
||
| from Crypto::NonceArtifactNode nonce, Crypto::NodeBase op, string msg | ||
| where | ||
| not exists(nonce.getSourceNode()) and | ||
| ( | ||
| // Nonce not associated with any known cipher operation, assume unknown as insecure | ||
| not exists(Crypto::CipherOperationNode o | o.getANonce() = nonce) and | ||
| op = nonce and | ||
| msg = | ||
| "Unknown IV/Nonce initialization source with no observed nonce usage (assuming could be for encryption)." | ||
| or | ||
| // Nonce associated cipher operation where the mode is not explicitly encryption | ||
| op.(Crypto::CipherOperationNode).getANonce() = nonce and | ||
| ( | ||
| op.(Crypto::CipherOperationNode).getKeyOperationSubtype() instanceof Crypto::TEncryptMode | ||
| or | ||
| op.(Crypto::CipherOperationNode).getKeyOperationSubtype() instanceof Crypto::TWrapMode | ||
| ) and | ||
| msg = "Unknown IV/Nonce initialization source at encryption operation $@" | ||
| ) | ||
| select nonce, msg, op, op.toString() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
java/ql/src/experimental/quantum/Examples/WeakAsymmetric.ql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| /** | ||
| * @name Weak Asymmetric Key Size | ||
| * @id java/quantum/weak-asymmetric-key-size | ||
| * @description An asymmetric cipher with a short key size is in use | ||
| * @kind problem | ||
| * @problem.severity error | ||
| * @precision high | ||
| * @tags quantum | ||
| * experimental | ||
| */ | ||
|
|
||
| import java | ||
| import experimental.quantum.Language | ||
|
|
||
| from Crypto::KeyOperationAlgorithmNode op, int keySize, string algName | ||
| where | ||
| keySize = op.getKeySizeFixed() and | ||
| keySize < 2048 and | ||
| algName = op.getAlgorithmName() and | ||
| // Can't be an elliptic curve | ||
| op.getAlgorithmType() != Crypto::KeyOpAlg::AlgorithmType::EllipticCurveType() | ||
| select "Use of weak asymmetric key size (" + keySize.toString() + " bits) for algorithm " + algName |
33 changes: 33 additions & 0 deletions
33
java/ql/src/experimental/quantum/Examples/WeakBlockModes.ql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| /** | ||
| * @name Weak AES Block mode | ||
| * @id java/quantum/weak-block-modes | ||
| * @description An AES cipher is in use with an insecure block mode | ||
| * @kind problem | ||
| * @problem.severity error | ||
| * @precision high | ||
| * @tags quantum | ||
| * experimental | ||
| */ | ||
|
|
||
| import java | ||
| import experimental.quantum.Language | ||
|
|
||
| class WeakAESBlockModeAlgNode extends Crypto::KeyOperationAlgorithmNode { | ||
| Crypto::ModeOfOperationAlgorithmNode mode; | ||
|
|
||
| WeakAESBlockModeAlgNode() { | ||
| this.getAlgorithmType() = Crypto::KeyOpAlg::TSymmetricCipher(Crypto::KeyOpAlg::AES()) and | ||
| mode = super.getModeOfOperation() and | ||
| ( | ||
| mode.getModeType() = Crypto::KeyOpAlg::ECB() or | ||
| mode.getModeType() = Crypto::KeyOpAlg::CFB() or | ||
| mode.getModeType() = Crypto::KeyOpAlg::OFB() or | ||
| mode.getModeType() = Crypto::KeyOpAlg::CTR() | ||
| ) | ||
| } | ||
|
|
||
| Crypto::ModeOfOperationAlgorithmNode getMode() { result = mode } | ||
| } | ||
|
|
||
| from WeakAESBlockModeAlgNode alg | ||
| select alg, "Weak AES block mode instance $@.", alg.getMode(), alg.getMode().toString() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /** | ||
| * @name Weak hashes | ||
| * @description Finds uses of cryptographic hashing algorithms that are unapproved or otherwise weak. | ||
| * @id java/quantum/weak-hash | ||
| * @kind problem | ||
| * @problem.severity error | ||
| * @precision high | ||
| * @tags external/cwe/cwe-327 | ||
| * quantum | ||
| * experimental | ||
| */ | ||
|
|
||
| import java | ||
| import experimental.quantum.Language | ||
|
|
||
| from Crypto::HashAlgorithmNode alg, Crypto::HashType htype, string msg | ||
| where | ||
| htype = alg.getHashType() and | ||
| ( | ||
| (htype != Crypto::SHA2() and htype != Crypto::SHA2()) and | ||
| msg = "Use of unapproved hash algorithm or API " + htype.toString() + "." | ||
| or | ||
| (htype = Crypto::SHA2() or htype = Crypto::SHA3()) 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() or htype = Crypto::SHA3()) 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 |
File renamed without changes.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an impactful change. We should do a DCA run.