-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Java: Make java/weak-cryptographic-algorithm give a reason why the algo is insecure
#18161
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
owen-mc
merged 8 commits into
github:main
from
owen-mc:java/weak-crypto-algo-more-informative
Jan 13, 2025
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e6409e1
Give reason why crypto algorithm is insecure
owen-mc 09240e4
Refactor: use `concat` instead of hand-written version
owen-mc 95d26d9
Add change note
owen-mc 5c99c8c
Improve suggestion for ECB
owen-mc 95116ee
Update recommendations
owen-mc 5351f5b
Update wording of alert (accepting review suggestion)
owen-mc 5959a73
Only recommend GCM, and tighten wording
owen-mc 0728b3b
Update test expectation
owen-mc 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
4 changes: 4 additions & 0 deletions
4
java/ql/src/change-notes/2024-11-29-java-weak-crypto-algorithm-explanation.md
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,4 @@ | ||
| --- | ||
| category: fix | ||
| --- | ||
| * The query "Use of a broken or risky cryptographic algorithm" (`java/weak-cryptographic-algorithm`) now gives the reason why the cryptographic algorithm is considered weak. |
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
4 changes: 2 additions & 2 deletions
4
java/ql/test/library-tests/Encryption/cryptoalgospec.expected
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 |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| | Test.java:37:4:37:17 | super(...) | Test.java:37:10:37:15 | "some" | | ||
| | Test.java:41:3:41:38 | getInstance(...) | Test.java:41:29:41:37 | "another" | | ||
| | Test.java:41:4:41:17 | super(...) | Test.java:41:10:41:15 | "some" | | ||
| | Test.java:45:3:45:38 | getInstance(...) | Test.java:45:29:45:37 | "another" | |
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 |
|---|---|---|
| @@ -1,7 +1,11 @@ | ||
| | Test.java:9:4:9:8 | "DES" | | ||
| | Test.java:10:4:10:8 | "des" | | ||
| | Test.java:11:4:11:17 | "des_function" | | ||
| | Test.java:12:4:12:23 | "function_using_des" | | ||
| | Test.java:13:4:13:19 | "EncryptWithDES" | | ||
| | Test.java:14:4:14:22 | "AES/ECB/NoPadding" | | ||
| | Test.java:15:4:15:25 | "AES/CBC/PKCS5Padding" | | ||
| | Test.java:9:4:9:8 | "DES" | It has a short key length of 56 bits, making it vulnerable to brute-force attacks. Consider using AES instead. | | ||
| | Test.java:10:4:10:8 | "des" | It has a short key length of 56 bits, making it vulnerable to brute-force attacks. Consider using AES instead. | | ||
| | Test.java:11:4:11:17 | "des_function" | It has a short key length of 56 bits, making it vulnerable to brute-force attacks. Consider using AES instead. | | ||
| | Test.java:12:4:12:23 | "function_using_des" | It has a short key length of 56 bits, making it vulnerable to brute-force attacks. Consider using AES instead. | | ||
| | Test.java:13:4:13:19 | "EncryptWithDES" | It has a short key length of 56 bits, making it vulnerable to brute-force attacks. Consider using AES instead. | | ||
| | Test.java:14:4:14:8 | "RC2" | It is vulnerable to related-key attacks. Consider using AES instead. | | ||
| | Test.java:15:4:15:8 | "RC4" | It has multiple vulnerabilities, including biases in its output and susceptibility to several attacks. Consider using AES instead. | | ||
| | Test.java:16:4:16:12 | "ARCFOUR" | It has multiple vulnerabilities, including biases in its output and susceptibility to several attacks. Consider using AES instead. | | ||
| | Test.java:17:4:17:8 | "RC5" | It is vulnerable to differential and related-key attacks. Consider using AES instead. | | ||
| | Test.java:18:4:18:22 | "AES/ECB/NoPadding" | Encryption mode ECB like AES/ECB/NoPadding is vulnerable to replay and other attacks. Consider using AES instead. | | ||
| | Test.java:19:4:19:25 | "AES/CBC/PKCS5Padding" | CBC mode of operation with PKCS#5 or PKCS#7 padding is vulnerable to padding oracle attacks. Consider using AES instead. | |
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 |
|---|---|---|
| @@ -1,6 +1,10 @@ | ||
| import default | ||
| import semmle.code.java.security.Encryption | ||
|
|
||
| from StringLiteral s | ||
| where s.getValue().regexpMatch(getInsecureAlgorithmRegex()) | ||
| select s | ||
| from StringLiteral s, string reason | ||
| where | ||
| s.getValue().regexpMatch(getInsecureAlgorithmRegex()) and | ||
| if exists(getInsecureAlgorithmReason(s.getValue())) | ||
| then reason = getInsecureAlgorithmReason(s.getValue()) | ||
| else reason = "<no reason>" | ||
| select s, reason |
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 |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| | Test.java:18:4:18:8 | "AES" | | ||
| | Test.java:19:4:19:17 | "AES_function" | | ||
| | Test.java:22:4:22:8 | "AES" | | ||
| | Test.java:23:4:23:17 | "AES_function" | |
4 changes: 2 additions & 2 deletions
4
java/ql/test/query-tests/security/CWE-327/semmle/tests/BrokenCryptoAlgorithm.expected
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
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.
Uh oh!
There was an error while loading. Please reload this page.