Skip to content
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

Java weak encryption #9

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions semgrep/java/java-use-of-des-encryption-algorithm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
- id: java-use-of-des-encryption-algorithm
message: |
DES is a weak algorithm that has known attacks and can be broken. Consider using a secure algorithm such as AES.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to add an auto-fix for this rule? Not sure how the fix should look like so it is hard to say..

languages: [ java ]
severity: ERROR
metadata:
vulnerability_category: weak_cryptography
violation_id: weak_encryption_algorithm
standards: [ Microsoft SDL ]
references:
- https://docs.microsoft.com/en-us/security/sdl/cryptographic-recommendations
patterns:
- pattern-either:
- patterns:
- pattern: |
$MD.getInstance("$RE", ...);
- metavariable-regex:
metavariable: $RE
regex: "(?i)^DES/.*$"
- patterns:
- pattern: |
$MD.getInstance("$RE", ...);
- metavariable-regex:
metavariable: $RE
regex: "(?i)^des$"
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
- id: java-use-of-rsa-encryption-algorithm-with-short-key
message: |
It is not secure to use the RSA algorithm with a 1024-bit key. The minimal acceptable key length is 2048 bits.
languages: [ java ]
severity: ERROR
metadata:
vulnerability_category: weak_cryptography
violation_id: weak_encryption_algorithm
standards: [ Microsoft SDL ]
references:
- https://docs.microsoft.com/en-us/security/sdl/cryptographic-recommendations
patterns:
- pattern: |
$K = $C.getInstance("$RE");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we change this to something like:

  • pattern-inside: |
    $K = $C.getInstance("$RE");
    ...
  • pattern: $K.initialize($BITS);
  • fix: $K.initialize(2048);

and this way we can have an auto-fix as well?

...
$K.initialize($BITS);
- metavariable-regex:
metavariable: $RE
regex: "(?i)^rsa$"
- metavariable-comparison:
comparison: $BITS < 2048
metavariable: $BITS