Skip to content

Commit eeeb142

Browse files
committed
Rust: Implement the query.
1 parent 07e3421 commit eeeb142

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

rust/ql/lib/codeql/rust/Concepts.qll

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,32 @@ module SqlSanitization {
172172
*/
173173
abstract class Range extends DataFlow::Node { }
174174
}
175+
176+
/**
177+
* Provides models for cryptographic things.
178+
*/
179+
module Cryptography {
180+
private import codeql.rust.internal.ConceptsShared::Cryptography as SC
181+
182+
/**
183+
* A data-flow node that is an application of a cryptographic algorithm. For example,
184+
* encryption, decryption, signature-validation.
185+
*
186+
* Extend this class to refine existing API models. If you want to model new APIs,
187+
* extend `CryptographicOperation::Range` instead.
188+
*/
189+
class CryptographicOperation extends SC::CryptographicOperation instanceof CryptographicOperation::Range
190+
{ }
191+
192+
class EncryptionAlgorithm = SC::EncryptionAlgorithm;
193+
194+
class HashingAlgorithm = SC::HashingAlgorithm;
195+
196+
class PasswordHashingAlgorithm = SC::PasswordHashingAlgorithm;
197+
198+
module CryptographicOperation = SC::CryptographicOperation;
199+
200+
class BlockMode = SC::BlockMode;
201+
202+
class CryptographicAlgorithm = SC::CryptographicAlgorithm;
203+
}

rust/ql/src/queries/security/CWE-327/BrokenCryptoAlgorithm.ql

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,15 @@
1111
*/
1212

1313
import rust
14+
import codeql.rust.Concepts
1415

15-
from int i
16-
where none()
17-
select i
16+
from Cryptography::CryptographicOperation operation, string msgPrefix
17+
where
18+
exists(Cryptography::EncryptionAlgorithm algorithm | algorithm = operation.getAlgorithm() |
19+
algorithm.isWeak() and
20+
msgPrefix = "The cryptographic algorithm " + algorithm.getName()
21+
)
22+
or
23+
operation.getBlockMode().isWeak() and msgPrefix = "The block mode " + operation.getBlockMode()
24+
select operation, "$@ is broken or weak, and should not be used.", operation.getInitialization(),
25+
msgPrefix

0 commit comments

Comments
 (0)