-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Rust: Weak encryption algorithm query. #18226
Conversation
…lgorithmNames.qll to Rust.
QHelp previews: rust/ql/src/queries/security/CWE-327/BrokenCryptoAlgorithm.qhelpUse of a broken or weak cryptographic algorithmUsing broken or weak cryptographic algorithms can leave data vulnerable to being decrypted or forged by an attacker. Many cryptographic algorithms provided by cryptography libraries are known to be weak, or flawed. Using such an algorithm means that encrypted or hashed data is less secure than it appears to be. This query alerts on any use of a weak cryptographic algorithm, that is not a hashing algorithm. Use of broken or weak cryptographic hash functions are handled by the RecommendationEnsure that you use a strong, modern cryptographic algorithm, such as AES-128 or RSA-2048. ExampleThe following code uses the let des_cipher = cbc::Encryptor::<des::Des>::new(key.into(), iv.into()); // BAD: weak encryption
let encryption_result = des_cipher.encrypt_padded_mut::<des::cipher::block_padding::Pkcs7>(data, data_len); Instead, we should use a strong modern algorithm. In this case, we have selected the 256-bit version of the AES algorithm. let aes_cipher = cbc::Encryptor::<aes::Aes256>::new(key.into(), iv.into()); // GOOD: strong encryption
let encryption_result = aes_cipher.encrypt_padded_mut::<aes::cipher::block_padding::Pkcs7>(data, data_len); References
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM ✨
A few comments for your consideration. Nothing major, apart from the link to the archive publication.
rust/ql/src/queries/security/CWE-327/BrokenCryptoAlgorithm.qhelp
Outdated
Show resolved
Hide resolved
rust/ql/src/queries/security/CWE-327/BrokenCryptoAlgorithm.qhelp
Outdated
Show resolved
Hide resolved
rust/ql/src/queries/security/CWE-327/BrokenCryptoAlgorithm.qhelp
Outdated
Show resolved
Hide resolved
rust/ql/src/queries/security/CWE-327/BrokenCryptoAlgorithm.qhelp
Outdated
Show resolved
Hide resolved
Co-authored-by: mc <[email protected]>
Thanks for your review @mchammer01. All suggestions accepted. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
DCA LGTM. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me. Syntax highlighting is missing for the Rust samples in the rendered QHelp. The blocks start with ```none
instead of ```rust
. I suppose we'll need to teach the qhelp renderer that .rs
files are rust
.
This query alerts on any use of a weak cryptographic algorithm, that is | ||
not a hashing algorithm. Use of broken or weak cryptographic hash | ||
functions are handled by the | ||
<code>rust/weak-sensitive-data-hashing</code> query. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This query doesn't exist yet, but I guess you are planning to add it shortly, so it's fine to leave it like this,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also a good point. We do indeed plan to add it soon, but I'll make a note to modify this if we do not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor QL stylistic comments.
Good point. I've created an issue for this, I think I know what to do but I don't have time to get on it right now. |
Co-authored-by: Tom Hvitved <[email protected]>
Thanks for the reviews - I've accepted the code suggestions, I think the other points warrant follow-up work. |
@geoffw0 I re-ran the qhelp preview workflow, the syntax highlighting looks better now. |
Co-authored-by: Simon Friis Vindum <[email protected]>
@@ -30,7 +30,7 @@ module Cryptography { | |||
class PasswordHashingAlgorithm = CryptoAlgorithms::PasswordHashingAlgorithm; | |||
|
|||
/** | |||
* A data-flow node that is an application of a cryptographic algorithm. For example, | |||
* A data flow node that is an application of a cryptographic algorithm. For example, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't forget to change the sync'd copies as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you happy that we do that? I didn't want to interfere with other languages unless there's some level of agreement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy with that, although if you like to leave things as-is, that's also fine with me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've done the change.
@paldepind the interface is still showing you as "requested changes", please could you approve ... or point out what I've missed? |
New weak encryption algorithm query for Rust (
rust/weak-cryptographic-algorithm
). This uses the same framework as for javascript, python and ruby - in particularConceptsShared.qll
,CryptoAlgorithms.qll
andCryptoAlgorithmNames.qll
- which paves the way for similar queries such as weak hashing and ... something to do with http as well by the looks of it.Limitations:
frameworks/RustCrypto.qll
is really clunky at the moment. We need to figure out a way to do this that is both (1) more readable and (2) more reliable - one of the tests defeats it with a simple type alias.TODO:
@RasmusWL - I'm told you're the right person to talk to about the shared concepts stuff. I'm interested to hear what you think our next priority should be.