-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18226 from geoffw0/badcrypto
Rust: Weak encryption algorithm query.
- Loading branch information
Showing
20 changed files
with
772 additions
and
34 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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.