-
Notifications
You must be signed in to change notification settings - Fork 9
Add Security Rule for Detecting Small Cryptographic Key Sizes #131
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
ganeshpatro321
merged 11 commits into
coderabbitai:main
from
ESS-ENN:small-key-size-c-cpp
Jan 20, 2025
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
bb7b8e1
removed missing-secure-java
308e947
Merge branch 'coderabbitai:main' into main
ESS-ENN 46efd55
Merge branch 'coderabbitai:main' into main
ESS-ENN 3ac0204
Merge branch 'coderabbitai:main' into main
ESS-ENN 7caba92
Merge branch 'coderabbitai:main' into main
ESS-ENN d3a2776
Merge branch 'coderabbitai:main' into main
ESS-ENN 2e86380
Merge branch 'coderabbitai:main' into main
ESS-ENN b072db7
Merge branch 'coderabbitai:main' into main
ESS-ENN 1a79552
small-key-size-c
ESS-ENN 6ac3676
small-key-size-cpp
ESS-ENN d9d5c56
Adding ast-grep-essentials: true to small-key-size rule for both c an…
ESS-ENN 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
id: small-key-size-c | ||
language: c | ||
severity: warning | ||
message: >- | ||
$KEY_FUNCTION` is using a key size of only $KEY_BITS bits. This is | ||
less than the recommended key size of 2048 bits. | ||
note: >- | ||
[CWE-326]: Inadequate Encryption Strength | ||
[OWASP A02:2021]: Cryptographic Failures | ||
[OWASP A03:2017]: Sensitive Data Exposure | ||
[REFERENCES] | ||
https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-131Ar2.pdf | ||
https://owasp.org/Top10/A02_2021-Cryptographic_Failures | ||
ast-grep-essentials: true | ||
|
||
rule: | ||
kind: call_expression | ||
all: | ||
- has: | ||
stopBy: end | ||
kind: identifier | ||
regex: ^(DH_generate_parameters_ex|DSA_generate_parameters_ex|EVP_PKEY_CTX_set_dh_paramgen_prime_len|EVP_PKEY_CTX_set_dsa_paramgen_bits|EVP_PKEY_CTX_set_rsa_keygen_bits|RSA_generate_key_ex|RSA_generate_key_fips)$ | ||
- not: | ||
has: | ||
stopBy: end | ||
kind: field_identifier | ||
regex: ^(DH_generate_parameters_ex|DSA_generate_parameters_ex|EVP_PKEY_CTX_set_dh_paramgen_prime_len|EVP_PKEY_CTX_set_dsa_paramgen_bits|EVP_PKEY_CTX_set_rsa_keygen_bits|RSA_generate_key_ex|RSA_generate_key_fips)$ | ||
- has: | ||
stopBy: neighbor | ||
kind: argument_list | ||
has: | ||
stopBy: neighbor | ||
any: | ||
- kind: number_literal | ||
- kind: binary_expression | ||
- kind: unary_expression | ||
nthChild: 2 | ||
regex: ^([+-]*\(*[+-]*((0|[1-9][0-9]{0,2}|1[0-9]{3}|20[0-3][0-9]|204[0-7])(\.[0-9]+)?|((0|[1-9][0-9]{0,2}|1[0-9]{3}|20[0-3][0-9]|204[0-7])(\.[0-9]+)?\/[1-9][0-9]*)|(\.[0-9]+)|(\.[0-9]+\/[1-9][0-9]*))\)*)$ | ||
- not: | ||
has: | ||
stopBy: end | ||
kind: ERROR | ||
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,42 @@ | ||
id: small-key-size-cpp | ||
language: cpp | ||
severity: warning | ||
ESS-ENN marked this conversation as resolved.
Show resolved
Hide resolved
|
||
message: >- | ||
$KEY_FUNCTION` is using a key size of only $KEY_BITS bits. This is | ||
less than the recommended key size of 2048 bits. | ||
note: >- | ||
[CWE-326]: Inadequate Encryption Strength | ||
[OWASP A02:2021]: Cryptographic Failures | ||
[OWASP A03:2017]: Sensitive Data Exposure | ||
[REFERENCES] | ||
https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-131Ar2.pdf | ||
https://owasp.org/Top10/A02_2021-Cryptographic_Failures | ||
ast-grep-essentials: true | ||
|
||
rule: | ||
kind: call_expression | ||
all: | ||
- has: | ||
stopBy: end | ||
kind: identifier | ||
regex: ^(DH_generate_parameters_ex|DSA_generate_parameters_ex|EVP_PKEY_CTX_set_dh_paramgen_prime_len|EVP_PKEY_CTX_set_dsa_paramgen_bits|EVP_PKEY_CTX_set_rsa_keygen_bits|RSA_generate_key_ex|RSA_generate_key_fips)$ | ||
- not: | ||
has: | ||
stopBy: end | ||
kind: field_identifier | ||
regex: ^(DH_generate_parameters_ex|DSA_generate_parameters_ex|EVP_PKEY_CTX_set_dh_paramgen_prime_len|EVP_PKEY_CTX_set_dsa_paramgen_bits|EVP_PKEY_CTX_set_rsa_keygen_bits|RSA_generate_key_ex|RSA_generate_key_fips)$ | ||
- has: | ||
stopBy: neighbor | ||
kind: argument_list | ||
has: | ||
stopBy: neighbor | ||
any: | ||
- kind: number_literal | ||
- kind: binary_expression | ||
- kind: unary_expression | ||
nthChild: 2 | ||
regex: ^([+-]*\(*[+-]*((0|[1-9][0-9]{0,2}|1[0-9]{3}|20[0-3][0-9]|204[0-7])(\.[0-9]+)?|((0|[1-9][0-9]{0,2}|1[0-9]{3}|20[0-3][0-9]|204[0-7])(\.[0-9]+)?\/[1-9][0-9]*)|(\.[0-9]+)|(\.[0-9]+\/[1-9][0-9]*))\)*)$ | ||
- not: | ||
has: | ||
stopBy: end | ||
kind: ERROR |
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,23 @@ | ||
id: small-key-size-c | ||
snapshots: | ||
? | | ||
void foo() { | ||
DH_generate_parameters_ex(NULL, 1024); | ||
} | ||
: labels: | ||
- source: DH_generate_parameters_ex(NULL, 1024) | ||
style: primary | ||
start: 15 | ||
end: 52 | ||
- source: DH_generate_parameters_ex | ||
style: secondary | ||
start: 15 | ||
end: 40 | ||
- source: '1024' | ||
style: secondary | ||
start: 47 | ||
end: 51 | ||
- source: (NULL, 1024) | ||
style: secondary | ||
start: 40 | ||
end: 52 |
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,23 @@ | ||
id: small-key-size-cpp | ||
snapshots: | ||
? | | ||
void foo() { | ||
DH_generate_parameters_ex(NULL, 1024); | ||
} | ||
: labels: | ||
- source: DH_generate_parameters_ex(NULL, 1024) | ||
style: primary | ||
start: 15 | ||
end: 52 | ||
- source: DH_generate_parameters_ex | ||
style: secondary | ||
start: 15 | ||
end: 40 | ||
- source: '1024' | ||
style: secondary | ||
start: 47 | ||
end: 51 | ||
- source: (NULL, 1024) | ||
style: secondary | ||
start: 40 | ||
end: 52 |
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,14 @@ | ||
id: small-key-size-c | ||
valid: | ||
- | | ||
void foo() { | ||
DH_generate_parameters_ex(NULL, 2049); | ||
} | ||
|
||
invalid: | ||
- | | ||
void foo() { | ||
DH_generate_parameters_ex(NULL, 1024); | ||
} | ||
|
||
|
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,14 @@ | ||
id: small-key-size-cpp | ||
valid: | ||
- | | ||
void foo() { | ||
DH_generate_parameters_ex(NULL, 2049); | ||
} | ||
|
||
invalid: | ||
- | | ||
void foo() { | ||
DH_generate_parameters_ex(NULL, 1024); | ||
} | ||
|
||
|
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.