-
Notifications
You must be signed in to change notification settings - Fork 31
Create rule S7203: Java Keystore files should not disclose cryptographic private keys #4685
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
pierre-loup-tristant-sonarsource
merged 3 commits into
master
from
rule/add-RSPEC-S7203
Feb 28, 2025
Merged
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{ | ||
} |
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,61 @@ | ||
{ | ||
"title": "Java Keystore files should not disclose cryptographic private keys", | ||
"type": "VULNERABILITY", | ||
"code": { | ||
"impacts": { | ||
"SECURITY": "BLOCKER" | ||
}, | ||
"attribute": "TRUSTWORTHY" | ||
}, | ||
"status": "ready", | ||
"remediation": { | ||
"func": "Constant\/Issue", | ||
"constantCost": "30min" | ||
}, | ||
"tags": [ | ||
"cwe", | ||
"cert" | ||
], | ||
"defaultSeverity": "Blocker", | ||
"ruleSpecification": "RSPEC-7203", | ||
"sqKey": "S7203", | ||
"scope": "All", | ||
"securityStandards": { | ||
"CWE": [ | ||
798, | ||
259 | ||
], | ||
"OWASP": [ | ||
"A3" | ||
], | ||
"CERT": [ | ||
"MSC03-J." | ||
], | ||
"OWASP Top 10 2021": [ | ||
"A7" | ||
], | ||
"OWASP Mobile Top 10 2024": [ | ||
"M1", | ||
"M2", | ||
"M10" | ||
], | ||
"PCI DSS 3.2": [ | ||
"6.5.10" | ||
], | ||
"PCI DSS 4.0": [ | ||
"6.2.4" | ||
], | ||
"ASVS 4.0": [ | ||
"2.10.4", | ||
"3.5.2", | ||
"6.4.1" | ||
], | ||
"STIG ASD_V5R3": [ | ||
"V-222642" | ||
] | ||
}, | ||
"defaultQualityProfiles": [ | ||
"Sonar way" | ||
], | ||
"quickfix": "unknown" | ||
} |
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,77 @@ | ||
include::../../../shared_content/secrets/description.adoc[] | ||
|
||
== Why is this an issue? | ||
|
||
include::../../../shared_content/secrets/rationale.adoc[] | ||
|
||
=== What is the potential impact? | ||
|
||
include::../../../shared_content/secrets/impact/private_key_disclosure.adoc[] | ||
|
||
include::../../../shared_content/secrets/impact/supply_chain_attack.adoc[] | ||
|
||
If a third party gets access to a keystore containingan Android upload key or app signing key, this person could sign and distribute malicious apps under the same identity as the original app. | ||
|
||
== How to fix it | ||
|
||
include::../../../shared_content/secrets/fix/store_separatly.adoc[] | ||
|
||
include::../../../shared_content/secrets/fix/revoke.adoc[] | ||
|
||
In most cases, if the key is used as part of a larger trust model (X509, PGP, | ||
etc), it is necessary to issue and publish a revocation certificate. Doing so | ||
will ensure that all people and assets that rely on this key for security | ||
operations are aware of its compromise and stop trusting it. | ||
|
||
include::../../../shared_content/secrets/fix/recent_use.adoc[] | ||
|
||
include::../../../shared_content/secrets/fix/vault.adoc[] | ||
|
||
=== Code examples | ||
|
||
==== Noncompliant code example | ||
|
||
[source,shell,diff-id=1,diff-type=noncompliant] | ||
---- | ||
keytool -genkey \ | ||
-keystore release.jks \ | ||
-alias release \ | ||
-keyalg RSA \ | ||
-keysize 2048 \ | ||
-validity 1000 \ | ||
-dname "CN=com.example" \ | ||
-storepass release # Noncompliant, keystore password is easy to guess | ||
---- | ||
|
||
==== Compliant solution | ||
|
||
Keychain files whould created using a strong password. | ||
|
||
[source,shell,diff-id=1,diff-type=compliant] | ||
---- | ||
echo $STRONG_PWD | keytool -genkey \ | ||
-keystore release.jks \ | ||
-alias release \ | ||
-keyalg RSA \ | ||
-keysize 2048 \ | ||
-validity 1000 \ | ||
-dname "CN=com.example" | ||
---- | ||
|
||
Files containing cryptographic key should not be commitied with the application codebase and should be distributed separatly. | ||
|
||
//=== How does this work? | ||
|
||
//=== Pitfalls | ||
|
||
//=== Going the extra mile | ||
|
||
== Resources | ||
|
||
include::../../../shared_content/secrets/resources/standards.adoc[] | ||
|
||
* OWASP - https://owasp.org/www-project-mobile-top-10/2023-risks/m1-improper-credential-usage[Mobile Top 10 2024 Category M1 - Improper Credential Usage] | ||
* OWASP - https://owasp.org/www-project-mobile-top-10/2023-risks/m2-inadequate-supply-chain-security[Mobile Top 10 2024 Category M2 - Inadequate Supply Chain Security] | ||
* OWASP - https://owasp.org/www-project-mobile-top-10/2023-risks/m10-insufficient-cryptography[Mobile Top 10 2024 Category M10 - Insufficient Cryptography] | ||
|
||
//=== Benchmarks |
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 @@ | ||
**Store cryptographic keys separately** | ||
|
||
Store private key separately from the main codebase, even if they are in a password protected format. | ||
It will avoid unecessary exposure and mitigate the risk of private key being leaked if the password is compromised. | ||
pierre-loup-tristant-sonarsource marked this conversation as resolved.
Show resolved
Hide resolved
|
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,27 @@ | ||
==== Cryptographic private key disclosure | ||
|
||
A cryptographic private key is a piece of sensitive information that is used in | ||
asymmetric cryptography. They are used in conjunction with public keys to secure | ||
communications and authenticate digital signatures. | ||
|
||
Private keys can be used to achieve two main cryptographic operations, | ||
encryption or digital signature. Those operations are the basis of multiple | ||
higher-level security mechanisms such as: | ||
|
||
* User authentication | ||
* Servers authentication, for example in the X509 trust model | ||
* E-mail encryption | ||
|
||
Disclosing a cryptographic private key to an unintended audience can have severe | ||
security consequences. The exact impact will vary depending on the role of the | ||
key and the assets it protects. | ||
|
||
For example, if the key is used in conjunction with an X509 certificate to | ||
authenticate a web server as part of TLS communications, attackers with network access will be able | ||
to impersonate that server. This leads to Man-In-The-Middle-Attacks that would | ||
pierre-loup-tristant-sonarsource marked this conversation as resolved.
Show resolved
Hide resolved
|
||
affect both the confidentiality and integrity of the communications from clients | ||
to that server. | ||
|
||
If the key was used as part of e-mail protocols, attackers might be able to send | ||
e-mails on behalf of the key owner or decrypt previously encrypted emails. This | ||
might lead to sensitive information disclosure and reputation loss. |
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.