-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Draft
bdrodes
wants to merge
23
commits into
github:main
Choose a base branch
from
bdrodes:santander-java-crypto-check
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
23 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 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
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.
This file was deleted.
Oops, something went wrong.
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
51 changes: 51 additions & 0 deletions
51
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,51 @@ | ||
/** | ||
* @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 | ||
// NOTE: null nonces should be handled seaparately, often used for default values prior to initialization | ||
// failure to initialize should, in practice, lead to a NullPointerException, which is a separate concern | ||
// however there may be APIs where NULL uses a default nonce or action. | ||
not src.asElement() instanceof NullLiteral 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." |
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.
Is
instanceof Expr
necessary here?