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

Key storage detecting #438

Merged
merged 2 commits into from
Nov 9, 2023
Merged

Key storage detecting #438

merged 2 commits into from
Nov 9, 2023

Conversation

babenek
Copy link
Contributor

@babenek babenek commented Oct 14, 2023

Description

Please include a summary of the change and which is fixed.

based on #441

  • Add JKS and PKCS12 storages detection in --doc mode
  • 3 default passwords are used: empty, "changeit" and "changeme" to open a storage

How has this been tested?

Please describe the tests that you ran to verify your changes.

  • UnitTest
  • Benchmark - does not impact
  • fuzzing

@codecov-commenter
Copy link

codecov-commenter commented Oct 14, 2023

Codecov Report

Attention: 6 lines in your changes are missing coverage. Please review.

Comparison is base (105e296) 90.82% compared to head (6f3f832) 90.89%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #438      +/-   ##
==========================================
+ Coverage   90.82%   90.89%   +0.06%     
==========================================
  Files         126      128       +2     
  Lines        4209     4283      +74     
  Branches      666      678      +12     
==========================================
+ Hits         3823     3893      +70     
- Misses        251      254       +3     
- Partials      135      136       +1     
Files Coverage Δ
credsweeper/deep_scanner/deep_scanner.py 95.27% <100.00%> (+0.19%) ⬆️
credsweeper/deep_scanner/jks_scanner.py 100.00% <100.00%> (ø)
credsweeper/deep_scanner/pkcs12_scanner.py 90.47% <90.47%> (ø)
credsweeper/utils/util.py 87.92% <84.61%> (+0.34%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@babenek babenek force-pushed the jks branch 2 times, most recently from 72d307f to 344f94d Compare October 16, 2023 10:51
@babenek babenek marked this pull request as ready for review October 16, 2023 11:27
@babenek babenek requested a review from a team as a code owner October 16, 2023 11:27
@babenek babenek marked this pull request as draft October 20, 2023 03:08
@babenek babenek force-pushed the jks branch 2 times, most recently from 83e86d0 to 56c680e Compare October 21, 2023 11:42
@babenek babenek marked this pull request as ready for review November 1, 2023 12:15
Copy link
Collaborator

@csh519 csh519 left a comment

Choose a reason for hiding this comment

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

Thank you for adding jks and pkcs12 scanner.

LGTM 👍

for pw_probe in ["", "changeit", "changeme"]:
try:
keystore = jks.KeyStore.loads(data_provider.data, pw_probe, try_decrypt_keys=True)
if keystore.private_keys or keystore.secret_keys:
Copy link
Contributor

Choose a reason for hiding this comment

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

This part is not clear.
You check for private keys in the keystore. They are returned in encrypted form (if your password guess is wrong) or decrypted format (if password matches). This is the first part of IF.
Then ELSE section is used for cases when there are no private keys at all. But you marked jks as candidate as well.
It seems there is a trouble out here. 4 cases should be checked independently:

  • pkey present, default password, issue.
  • pkey present, unknown password, no issue.
  • no pkey, default password, no issue (?)
  • no pkey, unknown password, no issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In any case - a storage with default password should not appear.
IF-ELSE block just decide which text will be in info for user.

Unknown password will raise an exception and no issue is created.

Copy link
Contributor

Choose a reason for hiding this comment

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

https://pyjks.readthedocs.io/en/latest/_modules/jks/jks.html#KeyStore.loads
if try_decrypt_keys:
try:
entry.decrypt(store_password)
except DecryptionFailureException:
pass # ok, let user call decrypt() manually

No exception

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In common (wrong) case the password of keys is the same like for the storage.
Suppose, if the key has good encryption - else branch will be taken.
Anyway, the scanner finds unencrypted(weak password) storage.

Copy link
Contributor

Choose a reason for hiding this comment

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

Whether it is used? Cannot see traces in the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

in tests/data/doc.json above - the storage is encrypted with different password, so it is not found

Copy link
Contributor

@kmnls kmnls left a comment

Choose a reason for hiding this comment

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

See comment.
The code does not match jks source code behavior https://pyjks.readthedocs.io/en/latest/_modules/jks/jks.html#KeyStore.loads

Copy link
Contributor

@xDizzix xDizzix left a comment

Choose a reason for hiding this comment

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

@babenek babenek merged commit ea2ee96 into Samsung:main Nov 9, 2023
29 checks passed
@babenek babenek deleted the jks branch November 9, 2023 10:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants