-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Rust: Weak encryption algorithm query. #18226
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
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
bdb2f3d
Rust: Add placeholder query and tests for 'cipher' module.
geoffw0 6c4e0a9
Rust: A few more test cases.
geoffw0 07e3421
Rust: Add shared ConceptsShared.qll, CryptoAlgorithms.qll and CryptoA…
geoffw0 eeeb142
Rust: Implement the query.
geoffw0 94dbad7
Rust: Model for cipher traits.
geoffw0 6eb850c
Rust: Improve the model.
geoffw0 dd0fa79
Rust: Add qhelp.
geoffw0 de042ea
Merge branch 'main' into badcrypto
geoffw0 4e418d3
Rust: Update for latest main, and autoformat.
geoffw0 129f21a
Rust: Make a predicate private.
geoffw0 f637b3b
Apply suggestions from code review
geoffw0 4b93325
Merge branch 'main' into badcrypto
geoffw0 ad75906
Apply suggestions from code review
geoffw0 591db05
Rust: Formatting.
geoffw0 d2cfcb4
Update rust/ql/lib/codeql/rust/internal/ConceptsShared.qll
geoffw0 1d72b75
Rust: data-flow -> data flow.
geoffw0 611d04e
Rust: Revert stylistic change in shared file.
geoffw0 44a0ad2
Update data-flow -> data flow in all versions of ConceptsShared.qll.
geoffw0 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
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
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
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,57 @@ | ||
| /** | ||
| * Provides modeling for the `RustCrypto` family of crates (`cipher`, `digest` etc). | ||
| */ | ||
|
|
||
| private import rust | ||
| private import codeql.rust.Concepts | ||
| private import codeql.rust.dataflow.DataFlow | ||
|
|
||
| bindingset[algorithmName] | ||
| private string simplifyAlgorithmName(string algorithmName) { | ||
| // the cipher library gives triple-DES names like "TdesEee2" and "TdesEde2" | ||
| if algorithmName.matches("Tdes%") then result = "3des" else result = algorithmName | ||
| } | ||
|
|
||
| /** | ||
| * An operation that initializes a cipher through the `cipher::KeyInit` or | ||
| * `cipher::KeyIvInit` trait, for example `Des::new` or `cbc::Encryptor<des::Des>::new`. | ||
| */ | ||
| class StreamCipherInit extends Cryptography::CryptographicOperation::Range { | ||
| string algorithmName; | ||
|
|
||
| StreamCipherInit() { | ||
| // a call to `cipher::KeyInit::new`, `cipher::KeyInit::new_from_slice`, | ||
| // `cipher::KeyIvInit::new`, `cipher::KeyIvInit::new_from_slices` or `rc2::Rc2::new_with_eff_key_len`. | ||
| exists(PathExpr p, string rawAlgorithmName | | ||
| this.asExpr().getExpr().(CallExpr).getFunction() = p and | ||
| p.getResolvedCrateOrigin().matches("%/RustCrypto%") and | ||
| p.getPath().getPart().getNameRef().getText() = | ||
| ["new", "new_from_slice", "new_from_slices", "new_with_eff_key_len"] and | ||
| ( | ||
| rawAlgorithmName = p.getPath().getQualifier().getPart().getNameRef().getText() or | ||
| rawAlgorithmName = | ||
| p.getPath() | ||
| .getQualifier() | ||
| .getPart() | ||
| .getGenericArgList() | ||
| .getGenericArg(0) | ||
| .(TypeArg) | ||
| .getTypeRepr() | ||
| .(PathTypeRepr) | ||
| .getPath() | ||
| .getPart() | ||
| .getNameRef() | ||
| .getText() | ||
| ) and | ||
| algorithmName = simplifyAlgorithmName(rawAlgorithmName) | ||
| ) | ||
| } | ||
|
|
||
| override DataFlow::Node getInitialization() { result = this } | ||
|
|
||
| override Cryptography::CryptographicAlgorithm getAlgorithm() { result.matchesName(algorithmName) } | ||
|
|
||
| override DataFlow::Node getAnInput() { none() } | ||
|
|
||
| override Cryptography::BlockMode getBlockMode() { result = "" } | ||
| } | ||
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,7 @@ | ||
| /** | ||
| * This file contains imports required for the Rust version of `ConceptsShared.qll`. | ||
| * Since they are language-specific, they can't be placed directly in that file, as it is shared between languages. | ||
| */ | ||
|
|
||
| import codeql.rust.dataflow.DataFlow::DataFlow as DataFlow | ||
| import codeql.rust.security.CryptoAlgorithms as CryptoAlgorithms |
Oops, something went wrong.
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.