diff --git a/languages/rust/custom/.gitkeep b/languages/rust/custom/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/languages/rust/custom/src/CleartextLoggingOfKeyMaterial/CleartextLoggingOfKeyMaterial.md b/languages/rust/custom/src/CleartextLoggingOfKeyMaterial/CleartextLoggingOfKeyMaterial.md new file mode 100644 index 00000000..03ea6f69 --- /dev/null +++ b/languages/rust/custom/src/CleartextLoggingOfKeyMaterial/CleartextLoggingOfKeyMaterial.md @@ -0,0 +1,53 @@ +# Cleartext logging of cryptographic key material +Output written to the console or to a log is commonly retained in shared log storage, and is readable by operators, log aggregation services, and anyone else with access to those logs. If a cryptographic key is written to such output, an attacker who can read the logs can recover the key and use it to decrypt or forge the data that it protects. + +This query finds generated key material that is written to a log or to standard output or standard error, possibly after hex encoding. Results from key-generation APIs such as `KeyInit::generate_key` are already known to be keys, even when returned without being passed to a constructor. Generic randomly filled buffers, including results of helpers returning such buffers, must also flow to a cryptographic key API. The standard `rust/cleartext-logging` query relies on variable names to recognize sensitive data, and does not recognize names such as `key_bytes`. + + +## Recommendation +Do not write cryptographic keys to logs or to the console, even in encoded form. If you need to identify a key in diagnostic output, log a non-secret identifier for the key instead. + + +## Example +In the following example, a freshly generated AES-256-GCM key is hex-encoded and printed: + + +```rust +use ring::aead::{UnboundKey, AES_256_GCM}; +use ring::rand::{SecureRandom, SystemRandom}; + +fn make_key() -> UnboundKey { + let mut key_bytes = vec![0; AES_256_GCM.key_len()]; + SystemRandom::new().fill(&mut key_bytes).unwrap(); + println!("key_bytes = {}", hex::encode(&key_bytes)); // BAD: the key is written to stdout + UnboundKey::new(&AES_256_GCM, &key_bytes).unwrap() +} + +``` +In the following corrected example, only the key length is printed: + + +```rust +use ring::aead::{UnboundKey, AES_256_GCM}; +use ring::rand::{SecureRandom, SystemRandom}; + +fn make_key() -> UnboundKey { + let mut key_bytes = vec![0; AES_256_GCM.key_len()]; + SystemRandom::new().fill(&mut key_bytes).unwrap(); + println!("generated a {}-byte key", key_bytes.len()); // GOOD: only the key length is written + UnboundKey::new(&AES_256_GCM, &key_bytes).unwrap() +} + +``` + +## Known limitations + +For generic random buffers, both key-use and logging flows must be available from the same source in the global data-flow graph. Data-flow state and operation order can prevent some combinations from being correlated. The query does not infer this relationship from variable names or use of the same helper. + +Helpers are recognized only when the filled buffer flows locally to a return value, including explicit `return` expressions. Each call to such a helper is a separate source unless its result is itself locally returned by another wrapper. Those shared inner-call sources are suppressed to avoid correlating independent outer calls. Nested returning wrappers are not promoted to sources, so even logging and key use of the same outer-call result can be missed. Logging inside a helper that returns the filled buffer is also not covered by this call-site model. + +## References +* MITRE: [CWE-532: Insertion of Sensitive Information into Log File](https://cwe.mitre.org/data/definitions/532.html). +* OWASP: [Logging Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Logging_Cheat_Sheet.html). +* Common Weakness Enumeration: [CWE-312](https://cwe.mitre.org/data/definitions/312.html). +* Common Weakness Enumeration: [CWE-532](https://cwe.mitre.org/data/definitions/532.html). diff --git a/languages/rust/custom/src/CleartextLoggingOfKeyMaterial/CleartextLoggingOfKeyMaterial.qhelp b/languages/rust/custom/src/CleartextLoggingOfKeyMaterial/CleartextLoggingOfKeyMaterial.qhelp new file mode 100644 index 00000000..047545de --- /dev/null +++ b/languages/rust/custom/src/CleartextLoggingOfKeyMaterial/CleartextLoggingOfKeyMaterial.qhelp @@ -0,0 +1,74 @@ + + + + +

+Output written to the console or to a log is commonly retained in shared log +storage, and is readable by operators, log aggregation services, and anyone else +with access to those logs. If a cryptographic key is written to such output, an +attacker who can read the logs can recover the key and use it to decrypt or forge +the data that it protects. +

+

+This query finds generated key material that is written to a log or to standard +output or standard error, possibly after hex encoding. Results from key-generation +APIs such as KeyInit::generate_key are already known to be keys, even +when returned without being passed to a constructor. Generic randomly filled +buffers, including results of helpers returning such buffers, must also flow to a +cryptographic key API. The standard +rust/cleartext-logging query relies on variable names to recognize +sensitive data, and does not recognize names such as key_bytes. +

+
+ + +

+Do not write cryptographic keys to logs or to the console, even in encoded form. If +you need to identify a key in diagnostic output, log a non-secret identifier for +the key instead. +

+
+ + +

+In the following example, a freshly generated AES-256-GCM key is hex-encoded and +printed: +

+ +

+In the following corrected example, only the key length is printed: +

+ +
+ +
+

+For generic random buffers, both key-use and logging flows must be available from +the same source in the global data-flow graph. Data-flow state and operation order +can prevent some combinations from being correlated. The query does not infer this +relationship from variable names or use of the same helper. +

+

+Helpers are recognized only when the filled buffer flows locally to a return +value, including explicit return expressions. Each call to such a +helper is a separate source unless its result is itself locally returned by +another wrapper. Those shared inner-call sources are suppressed to avoid +correlating independent outer calls. Nested returning wrappers are not promoted +to sources, so even logging and key use of the same outer-call result can be +missed. Logging inside a helper that returns the filled buffer is also not covered +by this call-site model. +

+
+ + +
  • +MITRE: CWE-532: Insertion of Sensitive Information into Log File. +
  • +
  • +OWASP: Logging Cheat Sheet. +
  • +
    + +
    diff --git a/languages/rust/custom/src/CleartextLoggingOfKeyMaterial/CleartextLoggingOfKeyMaterial.ql b/languages/rust/custom/src/CleartextLoggingOfKeyMaterial/CleartextLoggingOfKeyMaterial.ql new file mode 100644 index 00000000..b1062bff --- /dev/null +++ b/languages/rust/custom/src/CleartextLoggingOfKeyMaterial/CleartextLoggingOfKeyMaterial.ql @@ -0,0 +1,130 @@ +/** + * @name Cleartext logging of cryptographic key material + * @description Writing a generated cryptographic key to a log or to the console + * exposes it to anyone who can read the output, allowing them to + * decrypt or forge the data it protects. + * @kind path-problem + * @problem.severity warning + * @security-severity 5.5 + * @precision medium + * @id rust/cleartext-logging-key-material + * @tags security + * external/cwe/cwe-312 + * external/cwe/cwe-532 + */ + +import rust +import codeql.rust.dataflow.DataFlow +import codeql.rust.dataflow.TaintTracking +import codeql.rust.security.CleartextLoggingExtensions +import common.CryptoKeyMaterial + +/** + * A buffer that has just been filled with random bytes. + */ +private class RandomlyFilledBuffer extends DataFlow::PostUpdateNode { + RandomlyFilledBuffer() { + exists(Expr buffer, Expr filled | + randomFillCall(_, buffer) and + (if buffer instanceof RefExpr then filled = buffer.(RefExpr).getExpr() else filled = buffer) and + this.getPreUpdateNode().asExpr() = filled + ) + } +} + +/** Holds if `node` flows locally to a return value of `wrapper`. */ +private predicate isReturnedBy(DataFlow::Node node, Callable wrapper) { + exists(DataFlow::Node returned | + returned.asExpr() = wrapper.getBody() + or + exists(ReturnExpr ret | + ret.getEnclosingCfgScope() = wrapper and returned.asExpr() = ret.getExpr() + ) + | + DataFlow::localFlow(node, returned) + ) +} + +/** A key returned by an API that specifically generates cryptographic keys. */ +private class GeneratedCryptographicKey extends DataFlow::Node { + GeneratedCryptographicKey() { + this.asExpr().(Call).getStaticTarget().getCanonicalPath() = + ["::generate_key", "::generate_key"] + } +} + +/** + * Generated material, with returned random buffers sourced at each wrapper call + * rather than conflating independent generated values at the fill in the helper. + */ +class GeneratedKeyMaterial extends DataFlow::Node { + GeneratedKeyMaterial() { + this instanceof GeneratedCryptographicKey + or + exists(RandomlyFilledBuffer buffer | + this = buffer and not isReturnedBy(buffer, _) + or + isReturnedBy(buffer, this.asExpr().(Call).getStaticTarget()) and + // Do not retain a shared inner-call source in unsupported nested wrappers. + not isReturnedBy(this, _) + ) + } +} + +/** + * A taint-tracking configuration for generated key material that flows to a + * cryptographic key sink and to a logging sink. + */ +module CleartextLoggingOfKeyMaterialConfig implements DataFlow::ConfigSig { + predicate isSource(DataFlow::Node source) { source instanceof GeneratedKeyMaterial } + + predicate isSink(DataFlow::Node sink) { + sink instanceof CleartextLogging::Sink + or + sink.(CryptographicKeySink).getKind() = ["key", "password"] + } + + predicate isBarrier(DataFlow::Node barrier) { + barrier instanceof CleartextLogging::Barrier + or + isNonRevealingProperty(barrier.asExpr()) + } + + predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) { + // flow from `a` to `&a` + node2.asExpr().(RefExpr).getExpr() = node1.asExpr() + or + keyMaterialConversionStep(node1, node2) + or + keyMaterialEncodingStep(node1, node2) + } + + predicate allowImplicitRead(DataFlow::Node node, DataFlow::ContentSet c) { + // flow out from tuple content at logging sinks + node instanceof CleartextLogging::Sink and + c.getAReadContent() instanceof DataFlow::TuplePositionContent + } +} + +module CleartextLoggingOfKeyMaterialFlow = + TaintTracking::Global; + +import CleartextLoggingOfKeyMaterialFlow::PathGraph + +from + CleartextLoggingOfKeyMaterialFlow::PathNode source, + CleartextLoggingOfKeyMaterialFlow::PathNode sink +where + CleartextLoggingOfKeyMaterialFlow::flowPath(source, sink) and + sink.getNode() instanceof CleartextLogging::Sink and + ( + // Key-generation APIs already establish that the value is a key. + source.getNode() instanceof GeneratedCryptographicKey + or + // Generic random buffers, including wrapper results, still require key use. + exists(CryptographicKeySink keySink | keySink.getKind() = ["key", "password"] | + CleartextLoggingOfKeyMaterialFlow::flow(source.getNode(), keySink) + ) + ) +select sink.getNode(), source, sink, "This operation writes $@ to a log.", source, + "generated cryptographic key material" diff --git a/languages/rust/custom/src/CleartextLoggingOfKeyMaterial/CleartextLoggingOfKeyMaterialBad.rs b/languages/rust/custom/src/CleartextLoggingOfKeyMaterial/CleartextLoggingOfKeyMaterialBad.rs new file mode 100644 index 00000000..bcc730dc --- /dev/null +++ b/languages/rust/custom/src/CleartextLoggingOfKeyMaterial/CleartextLoggingOfKeyMaterialBad.rs @@ -0,0 +1,9 @@ +use ring::aead::{UnboundKey, AES_256_GCM}; +use ring::rand::{SecureRandom, SystemRandom}; + +fn make_key() -> UnboundKey { + let mut key_bytes = vec![0; AES_256_GCM.key_len()]; + SystemRandom::new().fill(&mut key_bytes).unwrap(); + println!("key_bytes = {}", hex::encode(&key_bytes)); // BAD: the key is written to stdout + UnboundKey::new(&AES_256_GCM, &key_bytes).unwrap() +} diff --git a/languages/rust/custom/src/CleartextLoggingOfKeyMaterial/CleartextLoggingOfKeyMaterialGood.rs b/languages/rust/custom/src/CleartextLoggingOfKeyMaterial/CleartextLoggingOfKeyMaterialGood.rs new file mode 100644 index 00000000..83a819d4 --- /dev/null +++ b/languages/rust/custom/src/CleartextLoggingOfKeyMaterial/CleartextLoggingOfKeyMaterialGood.rs @@ -0,0 +1,9 @@ +use ring::aead::{UnboundKey, AES_256_GCM}; +use ring::rand::{SecureRandom, SystemRandom}; + +fn make_key() -> UnboundKey { + let mut key_bytes = vec![0; AES_256_GCM.key_len()]; + SystemRandom::new().fill(&mut key_bytes).unwrap(); + println!("generated a {}-byte key", key_bytes.len()); // GOOD: only the key length is written + UnboundKey::new(&AES_256_GCM, &key_bytes).unwrap() +} diff --git a/languages/rust/custom/src/HardcodedCryptographicKey/HardcodedCryptographicKey.md b/languages/rust/custom/src/HardcodedCryptographicKey/HardcodedCryptographicKey.md new file mode 100644 index 00000000..f7b24223 --- /dev/null +++ b/languages/rust/custom/src/HardcodedCryptographicKey/HardcodedCryptographicKey.md @@ -0,0 +1,46 @@ +# Hard-coded cryptographic key or passphrase +A cryptographic key or passphrase that is embedded in source code can be recovered by anyone with access to the source code or to the compiled binary. An attacker who recovers the key can decrypt data that it protects, or forge ciphertexts and authentication tags that the application will accept as genuine. + +This query finds constant values (literals, constant arrays, and repeated-value arrays) that flow to the key or passphrase argument of a cryptographic API. It complements the standard `rust/hard-coded-cryptographic-value` query by recognizing additional APIs from the `age`, `orion` and `ring` crates, and keys that are wrapped with `GenericArray::from` or `secrecy::Secret::new` before use. Results that the standard query already reports are not repeated. + + +## Recommendation +Do not embed keys or passphrases in source code. Generate keys with a cryptographically secure random number generator, or load them at runtime from a protected secret store such as a key management service, and rotate any key that has been committed to source control. + + +## Example +In the following example, an AES key is a fixed array of zero bytes: + + +```rust +use aes::cipher::{generic_array::GenericArray, BlockEncrypt, KeyInit}; +use aes::Aes128; + +fn encrypt(block: &mut [u8; 16]) { + let key = GenericArray::from([0u8; 16]); // BAD: the key is hard-coded + let cipher = Aes128::new(&key); + cipher.encrypt_block(GenericArray::from_mut_slice(block)); +} + +``` +In the following corrected example, the key is supplied at runtime from a protected secret store: + + +```rust +use aes::cipher::{generic_array::GenericArray, BlockEncrypt, KeyInit}; +use aes::Aes128; + +fn encrypt(block: &mut [u8; 16], key_bytes: [u8; 16]) { + // GOOD: the key is loaded at runtime from a protected secret store + let key = GenericArray::from(key_bytes); + let cipher = Aes128::new(&key); + cipher.encrypt_block(GenericArray::from_mut_slice(block)); +} + +``` + +## References +* MITRE: [CWE-321: Use of Hard-coded Cryptographic Key](https://cwe.mitre.org/data/definitions/321.html). +* OWASP: [Key Management Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Key_Management_Cheat_Sheet.html). +* Common Weakness Enumeration: [CWE-321](https://cwe.mitre.org/data/definitions/321.html). +* Common Weakness Enumeration: [CWE-798](https://cwe.mitre.org/data/definitions/798.html). diff --git a/languages/rust/custom/src/HardcodedCryptographicKey/HardcodedCryptographicKey.qhelp b/languages/rust/custom/src/HardcodedCryptographicKey/HardcodedCryptographicKey.qhelp new file mode 100644 index 00000000..64969743 --- /dev/null +++ b/languages/rust/custom/src/HardcodedCryptographicKey/HardcodedCryptographicKey.qhelp @@ -0,0 +1,54 @@ + + + + +

    +A cryptographic key or passphrase that is embedded in source code can be recovered +by anyone with access to the source code or to the compiled binary. An attacker who +recovers the key can decrypt data that it protects, or forge ciphertexts and +authentication tags that the application will accept as genuine. +

    +

    +This query finds constant values (literals, constant arrays, and repeated-value +arrays) that flow to the key or passphrase argument of a cryptographic API. It +complements the standard rust/hard-coded-cryptographic-value query by +recognizing additional APIs from the age, orion and +ring crates, and keys that are wrapped with +GenericArray::from or secrecy::Secret::new before use. +Results that the standard query already reports are not repeated. +

    +
    + + +

    +Do not embed keys or passphrases in source code. Generate keys with a +cryptographically secure random number generator, or load them at runtime from a +protected secret store such as a key management service, and rotate any key that +has been committed to source control. +

    +
    + + +

    +In the following example, an AES key is a fixed array of zero bytes: +

    + +

    +In the following corrected example, the key is supplied at runtime from a protected +secret store: +

    + +
    + + +
  • +MITRE: CWE-321: Use of Hard-coded Cryptographic Key. +
  • +
  • +OWASP: Key Management Cheat Sheet. +
  • +
    + +
    diff --git a/languages/rust/custom/src/HardcodedCryptographicKey/HardcodedCryptographicKey.ql b/languages/rust/custom/src/HardcodedCryptographicKey/HardcodedCryptographicKey.ql new file mode 100644 index 00000000..7418a25d --- /dev/null +++ b/languages/rust/custom/src/HardcodedCryptographicKey/HardcodedCryptographicKey.ql @@ -0,0 +1,88 @@ +/** + * @name Hard-coded cryptographic key or passphrase + * @description Using a hard-coded key or passphrase with a cryptographic API + * lets anyone with access to the source code or binary decrypt + * or forge protected data. + * @kind path-problem + * @problem.severity warning + * @security-severity 6.5 + * @precision medium + * @id rust/hardcoded-cryptographic-key + * @tags security + * external/cwe/cwe-321 + * external/cwe/cwe-798 + */ + +import rust +import codeql.rust.dataflow.DataFlow +import codeql.rust.dataflow.TaintTracking +import codeql.rust.security.HardcodedCryptographicValueExtensions +import common.CryptoKeyMaterial + +/** + * A taint-tracking configuration for hard-coded keys and passphrases flowing to + * cryptographic APIs, including APIs and conversions that are not modeled by + * `codeql/rust-all`. + */ +module HardcodedCryptographicKeyConfig implements DataFlow::ConfigSig { + predicate isSource(DataFlow::Node source) { + source instanceof HardcodedCryptographicValue::Source + } + + predicate isSink(DataFlow::Node sink) { sink instanceof CryptographicKeySink } + + predicate isBarrier(DataFlow::Node barrier) { + barrier instanceof HardcodedCryptographicValue::Barrier + or + // the buffer is overwritten with random bytes + isRandomlyFilledBuffer(barrier.asExpr()) + } + + predicate isBarrierIn(DataFlow::Node node) { + // make sources barriers so that we only report the closest instance + isSource(node) + } + + predicate isBarrierOut(DataFlow::Node node) { + // make sinks barriers so that we only report the closest instance + isSink(node) + } + + predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) { + keyMaterialConversionStep(node1, node2) + } +} + +module HardcodedCryptographicKeyFlow = TaintTracking::Global; + +/** + * The configuration used by the standard `rust/hard-coded-cryptographic-value` + * query, used to avoid reporting results that query already reports. + */ +module StandardHardcodedCryptographicValueConfig implements DataFlow::ConfigSig { + predicate isSource(DataFlow::Node source) { + source instanceof HardcodedCryptographicValue::Source + } + + predicate isSink(DataFlow::Node sink) { sink instanceof HardcodedCryptographicValue::Sink } + + predicate isBarrier(DataFlow::Node barrier) { + barrier instanceof HardcodedCryptographicValue::Barrier + } + + predicate isBarrierIn(DataFlow::Node node) { isSource(node) } + + predicate isBarrierOut(DataFlow::Node node) { isSink(node) } +} + +module StandardHardcodedCryptographicValueFlow = + TaintTracking::Global; + +import HardcodedCryptographicKeyFlow::PathGraph + +from HardcodedCryptographicKeyFlow::PathNode source, HardcodedCryptographicKeyFlow::PathNode sink +where + HardcodedCryptographicKeyFlow::flowPath(source, sink) and + not StandardHardcodedCryptographicValueFlow::flow(source.getNode(), sink.getNode()) +select source.getNode(), source, sink, "This hard-coded value is used as $@.", sink, + sink.getNode().(CryptographicKeySink).getKind().getDescription() diff --git a/languages/rust/custom/src/HardcodedCryptographicKey/HardcodedCryptographicKeyBad.rs b/languages/rust/custom/src/HardcodedCryptographicKey/HardcodedCryptographicKeyBad.rs new file mode 100644 index 00000000..2296a495 --- /dev/null +++ b/languages/rust/custom/src/HardcodedCryptographicKey/HardcodedCryptographicKeyBad.rs @@ -0,0 +1,8 @@ +use aes::cipher::{generic_array::GenericArray, BlockEncrypt, KeyInit}; +use aes::Aes128; + +fn encrypt(block: &mut [u8; 16]) { + let key = GenericArray::from([0u8; 16]); // BAD: the key is hard-coded + let cipher = Aes128::new(&key); + cipher.encrypt_block(GenericArray::from_mut_slice(block)); +} diff --git a/languages/rust/custom/src/HardcodedCryptographicKey/HardcodedCryptographicKeyGood.rs b/languages/rust/custom/src/HardcodedCryptographicKey/HardcodedCryptographicKeyGood.rs new file mode 100644 index 00000000..ec18ea34 --- /dev/null +++ b/languages/rust/custom/src/HardcodedCryptographicKey/HardcodedCryptographicKeyGood.rs @@ -0,0 +1,9 @@ +use aes::cipher::{generic_array::GenericArray, BlockEncrypt, KeyInit}; +use aes::Aes128; + +fn encrypt(block: &mut [u8; 16], key_bytes: [u8; 16]) { + // GOOD: the key is loaded at runtime from a protected secret store + let key = GenericArray::from(key_bytes); + let cipher = Aes128::new(&key); + cipher.encrypt_block(GenericArray::from_mut_slice(block)); +} diff --git a/languages/rust/custom/src/common/CryptoKeyMaterial.qll b/languages/rust/custom/src/common/CryptoKeyMaterial.qll new file mode 100644 index 00000000..0918b886 --- /dev/null +++ b/languages/rust/custom/src/common/CryptoKeyMaterial.qll @@ -0,0 +1,146 @@ +/** + * Provides classes and predicates for recognizing cryptographic key material in + * Rust code, complementing the models in `codeql/rust-all` for crates such as + * `age`, `orion`, `ring` and `generic-array`. + */ + +import rust +private import codeql.rust.dataflow.DataFlow +private import codeql.rust.security.HardcodedCryptographicValueExtensions + +/** + * Holds if `call` targets a function whose canonical path matches `pathRegex`. + */ +bindingset[pathRegex] +private predicate callTo(Call call, string pathRegex) { + call.getStaticTarget().getCanonicalPath().regexpMatch(pathRegex) +} + +/** + * An argument to a cryptographic API that is interpreted as secret key material + * (a key or passphrase), and that is not already modeled by `codeql/rust-all`. + */ +class AdditionalCryptographicKeySink extends DataFlow::Node { + CryptographicValueKind kind; + + AdditionalCryptographicKeySink() { + exists(Call call, int i | this.asExpr() = call.getPositionalArgument(i) | + // age: passphrase-based encryption and decryption + callTo(call, + [ + "::with_user_passphrase", + "::decrypt" + ]) and + i = 0 and + kind = "password" + or + // orion: secret keys and passwords constructed from raw bytes + callTo(call, "::from_slice") and + i = 0 and + kind = "key" + or + callTo(call, "::from_slice") and + i = 0 and + kind = "password" + or + // ring: AEAD, HMAC and HKDF keys constructed from raw bytes + callTo(call, + [ + "::new", "::new", + "::new_less_safe" + ]) and + i = 1 and + kind = "key" + ) + } + + /** Gets the kind of cryptographic value this sink is interpreted as. */ + CryptographicValueKind getKind() { result = kind } +} + +/** + * A value that is used as a cryptographic key or passphrase, either by an API + * modeled in `codeql/rust-all` or by an `AdditionalCryptographicKeySink`. + */ +class CryptographicKeySink extends DataFlow::Node { + CryptographicValueKind kind; + + CryptographicKeySink() { + kind = this.(AdditionalCryptographicKeySink).getKind() + or + kind = this.(HardcodedCryptographicValue::Sink).getKind() + } + + /** Gets the kind of cryptographic value this sink is interpreted as. */ + CryptographicValueKind getKind() { result = kind } +} + +/** + * Holds if `call` is a call to a random number generator API that fills + * `buffer` with random bytes. + */ +predicate randomFillCall(Call call, Expr buffer) { + callTo(call, + [ + "<_ as ring::rand::SecureRandom>::fill", "<[^>]+ as rand_core::RngCore>::fill_bytes", + "<[^>]+ as rand_core::RngCore>::try_fill_bytes", "<_ as rand::rng::Rng>::fill", + "<_ as rand::rng::Rng>::try_fill", "getrandom::fill", "getrandom::getrandom" + ]) and + buffer = call.getPositionalArgument(0) +} + +/** + * Holds if `e` is the buffer argument of a call that fills it with random + * bytes, or is nested inside such an argument (for example `key` in + * `&mut key`). + */ +predicate isRandomlyFilledBuffer(Expr e) { + exists(Expr buffer | randomFillCall(_, buffer) | e.getParentNode*() = buffer) +} + +/** + * Holds if there is a conversion from `node1` to `node2` that preserves key + * material and that is not otherwise modeled, such as + * `GenericArray::from([0u8; 16])` (whose `From` implementation is often not + * resolved) or `secrecy::Secret::new(s)`. + */ +predicate keyMaterialConversionStep(DataFlow::Node node1, DataFlow::Node node2) { + exists(Call call | + node1.asExpr() = call.getPositionalArgument(0) and + node2.asExpr() = call + | + // `T::from(x)` where the `From` implementation is not resolved + exists(Path path | path = call.(CallExpr).getFunction().(PathExpr).getPath() | + path.getSegment().getIdentifier().getText() = "from" and + exists(path.getQualifier()) and + not exists(call.getStaticTarget()) + ) + or + // secret wrappers from the `secrecy` crate + callTo(call, + [ + "::new", "::new", + "::from" + ]) + ) +} + +/** + * Holds if `node2` is an encoding (such as a hex string) of the key material + * in `node1`. + */ +predicate keyMaterialEncodingStep(DataFlow::Node node1, DataFlow::Node node2) { + exists(Call call | + callTo(call, ["hex::encode", "hex::encode_upper"]) and + node1.asExpr() = call.getPositionalArgument(0) and + node2.asExpr() = call + ) +} + +/** + * Holds if `e` computes a property of a value, such as its length, that does + * not reveal the value itself. + */ +predicate isNonRevealingProperty(Expr e) { + e.(MethodCallExpr).getIdentifier().getText() = ["len", "is_empty", "capacity"] +} diff --git a/languages/rust/custom/src/qlpack.yml b/languages/rust/custom/src/qlpack.yml new file mode 100644 index 00000000..0bb999d3 --- /dev/null +++ b/languages/rust/custom/src/qlpack.yml @@ -0,0 +1,5 @@ +name: languages-rust-custom-src +version: 0.0.2 +library: false +dependencies: + codeql/rust-all: "*" diff --git a/languages/rust/custom/test/.gitignore b/languages/rust/custom/test/.gitignore new file mode 100644 index 00000000..668592bc --- /dev/null +++ b/languages/rust/custom/test/.gitignore @@ -0,0 +1,5 @@ +# Generated by `codeql test run` / `codeql test extract` for Rust qltests +# (`Cargo.lock` is kept so that dependency versions are reproducible) +*/Cargo.toml +*/lib.rs +*/target/ diff --git a/languages/rust/custom/test/CleartextLoggingOfKeyMaterial/Cargo.lock b/languages/rust/custom/test/CleartextLoggingOfKeyMaterial/Cargo.lock new file mode 100644 index 00000000..bdfb2d9c --- /dev/null +++ b/languages/rust/custom/test/CleartextLoggingOfKeyMaterial/Cargo.lock @@ -0,0 +1,415 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "aead" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d122413f284cf2d62fb1b7db97e02edb8cda96d769b16e443a4f6195e35662b0" +dependencies = [ + "crypto-common", + "generic-array", +] + +[[package]] +name = "aes" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" +dependencies = [ + "cfg-if", + "cipher", + "cpufeatures", +] + +[[package]] +name = "aes-gcm" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "831010a0f742e1209b3bcea8fab6a8e149051ba6099432c8cb2cc117dec3ead1" +dependencies = [ + "aead", + "aes", + "cipher", + "ctr", + "ghash", + "subtle", +] + +[[package]] +name = "cc" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86e055fa6e3e40ad6187ba25b6855eeb635d5271f8e0f0e1e9a5826b8d75bea0" +dependencies = [ + "find-msvc-tools", + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600" + +[[package]] +name = "cipher" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" +dependencies = [ + "crypto-common", + "inout", +] + +[[package]] +name = "cpufeatures" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" +dependencies = [ + "libc", +] + +[[package]] +name = "crypto-common" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" +dependencies = [ + "generic-array", + "rand_core", + "typenum", +] + +[[package]] +name = "ctr" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0369ee1ad671834580515889b80f2ea915f23b8be8d0daa4bbaf2ac5c7590835" +dependencies = [ + "cipher", +] + +[[package]] +name = "find-msvc-tools" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c66915cc5391097de7a2b0b972e8505aa33c0df401fd3a6811dbdb32881ba48" + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "ghash" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0d8a4362ccb29cb0b265253fb0a2728f592895ee6854fd9bc13f2ffda266ff1" +dependencies = [ + "opaque-debug", + "polyval", +] + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "inout" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "879f10e63c20629ecabbb64a8010319738c66a5cd0c29b02d63d272b03751d01" +dependencies = [ + "generic-array", +] + +[[package]] +name = "libc" +version = "0.2.191" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a" + +[[package]] +name = "log" +version = "0.4.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d15f86d12da44cd8d4ec3c73984537eb7f4cadcb9776a575a0a8a05ca11005c" + +[[package]] +name = "opaque-debug" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" + +[[package]] +name = "polyval" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d1fe60d06143b2430aa532c94cfe9e29783047f06c0d7fd359a9a51b729fa25" +dependencies = [ + "cfg-if", + "cpufeatures", + "opaque-debug", + "universal-hash", +] + +[[package]] +name = "ppv-lite86" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "proc-macro2" +version = "1.0.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "ring" +version = "0.17.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "untrusted", + "windows-sys", +] + +[[package]] +name = "shlex" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.119" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "test" +version = "0.0.1" +dependencies = [ + "aes", + "aes-gcm", + "getrandom", + "hex", + "log", + "rand", + "ring", +] + +[[package]] +name = "typenum" +version = "1.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20" + +[[package]] +name = "unicode-ident" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563" + +[[package]] +name = "universal-hash" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc1de2c688dc15305988b563c3854064043356019f97a4b46276fe734c4f07ea" +dependencies = [ + "crypto-common", + "subtle", +] + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "zerocopy" +version = "0.8.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5fe1f8f1b06191a00962174c61aa5005e0bb391a6d80d07e24d115c01a92ed8" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.8.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "863ad3ac83293fb4d740aedbfdc9240dd8d1a50c1099acd76ce80ce7c7230c7f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] diff --git a/languages/rust/custom/test/CleartextLoggingOfKeyMaterial/CleartextLoggingOfKeyMaterial.expected b/languages/rust/custom/test/CleartextLoggingOfKeyMaterial/CleartextLoggingOfKeyMaterial.expected new file mode 100644 index 00000000..ce495baa --- /dev/null +++ b/languages/rust/custom/test/CleartextLoggingOfKeyMaterial/CleartextLoggingOfKeyMaterial.expected @@ -0,0 +1,228 @@ +#select +| test_aes.rs:8:11:8:42 | MacroExpr | test_aes.rs:7:31:7:39 | [post] key_bytes | test_aes.rs:8:11:8:42 | MacroExpr | This operation writes $@ to a log. | test_aes.rs:7:31:7:39 | [post] key_bytes | generated cryptographic key material | +| test_aes.rs:9:15:9:63 | MacroExpr | test_aes.rs:7:31:7:39 | [post] key_bytes | test_aes.rs:9:15:9:63 | MacroExpr | This operation writes $@ to a log. | test_aes.rs:7:31:7:39 | [post] key_bytes | generated cryptographic key material | +| test_aes_gcm.rs:6:14:6:52 | MacroExpr | test_aes_gcm.rs:5:15:5:44 | ...::generate_key(...) | test_aes_gcm.rs:6:14:6:52 | MacroExpr | This operation writes $@ to a log. | test_aes_gcm.rs:5:15:5:44 | ...::generate_key(...) | generated cryptographic key material | +| test_aes_gcm.rs:26:14:26:50 | MacroExpr | test_aes_gcm.rs:25:15:25:44 | ...::generate_key(...) | test_aes_gcm.rs:26:14:26:50 | MacroExpr | This operation writes $@ to a log. | test_aes_gcm.rs:25:15:25:44 | ...::generate_key(...) | generated cryptographic key material | +| test_rand.rs:7:14:7:40 | MacroExpr | test_rand.rs:6:27:6:29 | [post] key | test_rand.rs:7:14:7:40 | MacroExpr | This operation writes $@ to a log. | test_rand.rs:6:27:6:29 | [post] key | generated cryptographic key material | +| test_rand.rs:14:14:14:40 | MacroExpr | test_rand.rs:13:40:13:42 | [post] key | test_rand.rs:14:14:14:40 | MacroExpr | This operation writes $@ to a log. | test_rand.rs:13:40:13:42 | [post] key | generated cryptographic key material | +| test_rand.rs:34:14:34:40 | MacroExpr | test_rand.rs:33:31:33:33 | [post] key | test_rand.rs:34:14:34:40 | MacroExpr | This operation writes $@ to a log. | test_rand.rs:33:31:33:33 | [post] key | generated cryptographic key material | +| test_ring.rs:23:14:23:54 | MacroExpr | test_ring.rs:22:20:22:28 | [post] key_bytes | test_ring.rs:23:14:23:54 | MacroExpr | This operation writes $@ to a log. | test_ring.rs:22:20:22:28 | [post] key_bytes | generated cryptographic key material | +| test_ring.rs:69:14:69:41 | MacroExpr | test_ring.rs:68:15:68:28 | random_bytes(...) | test_ring.rs:69:14:69:41 | MacroExpr | This operation writes $@ to a log. | test_ring.rs:68:15:68:28 | random_bytes(...) | generated cryptographic key material | +| test_ring.rs:99:14:99:41 | MacroExpr | test_ring.rs:98:15:98:48 | explicitly_returned_random_bytes(...) | test_ring.rs:99:14:99:41 | MacroExpr | This operation writes $@ to a log. | test_ring.rs:98:15:98:48 | explicitly_returned_random_bytes(...) | generated cryptographic key material | +edges +| test_aes.rs:7:31:7:39 | [post] key_bytes | test_aes.rs:8:11:8:42 | MacroExpr | provenance | Sink:MaD:130 | +| test_aes.rs:7:31:7:39 | [post] key_bytes | test_aes.rs:9:54:9:62 | key_bytes | provenance | | +| test_aes.rs:9:36:9:63 | ...::encode_upper(...) | test_aes.rs:9:15:9:63 | MacroExpr | provenance | Sink:MaD:135 | +| test_aes.rs:9:54:9:62 | key_bytes | test_aes.rs:9:36:9:63 | ...::encode_upper(...) | provenance | Config | +| test_aes.rs:9:54:9:62 | key_bytes | test_aes.rs:10:42:10:50 | key_bytes | provenance | | +| test_aes.rs:10:41:10:50 | &key_bytes | test_aes.rs:10:41:10:50 | &key_bytes | provenance | Sink:MaD:293 | +| test_aes.rs:10:41:10:50 | &key_bytes [&ref] | test_aes.rs:10:41:10:50 | &key_bytes | provenance | Sink:MaD:293 | +| test_aes.rs:10:42:10:50 | key_bytes | test_aes.rs:10:41:10:50 | &key_bytes | provenance | Config | +| test_aes.rs:10:42:10:50 | key_bytes | test_aes.rs:10:41:10:50 | &key_bytes [&ref] | provenance | | +| test_aes_gcm.rs:5:9:5:11 | key | test_aes_gcm.rs:6:49:6:51 | key | provenance | | +| test_aes_gcm.rs:5:15:5:44 | ...::generate_key(...) | test_aes_gcm.rs:5:9:5:11 | key | provenance | | +| test_aes_gcm.rs:6:37:6:52 | ...::encode(...) | test_aes_gcm.rs:6:14:6:52 | MacroExpr | provenance | Sink:MaD:134 | +| test_aes_gcm.rs:6:49:6:51 | key | test_aes_gcm.rs:6:37:6:52 | ...::encode(...) | provenance | Config | +| test_aes_gcm.rs:6:49:6:51 | key | test_aes_gcm.rs:7:34:7:36 | key | provenance | | +| test_aes_gcm.rs:7:33:7:36 | &key | test_aes_gcm.rs:7:33:7:36 | &key | provenance | Sink:MaD:291 | +| test_aes_gcm.rs:7:33:7:36 | &key [&ref] | test_aes_gcm.rs:7:33:7:36 | &key | provenance | Sink:MaD:291 | +| test_aes_gcm.rs:7:34:7:36 | key | test_aes_gcm.rs:7:33:7:36 | &key | provenance | Config | +| test_aes_gcm.rs:7:34:7:36 | key | test_aes_gcm.rs:7:33:7:36 | &key [&ref] | provenance | | +| test_aes_gcm.rs:15:9:15:11 | key | test_aes_gcm.rs:16:34:16:36 | key | provenance | | +| test_aes_gcm.rs:15:15:15:44 | ...::generate_key(...) | test_aes_gcm.rs:15:9:15:11 | key | provenance | | +| test_aes_gcm.rs:16:33:16:36 | &key | test_aes_gcm.rs:16:33:16:36 | &key | provenance | Sink:MaD:291 | +| test_aes_gcm.rs:16:33:16:36 | &key [&ref] | test_aes_gcm.rs:16:33:16:36 | &key | provenance | Sink:MaD:291 | +| test_aes_gcm.rs:16:34:16:36 | key | test_aes_gcm.rs:16:33:16:36 | &key | provenance | Config | +| test_aes_gcm.rs:16:34:16:36 | key | test_aes_gcm.rs:16:33:16:36 | &key [&ref] | provenance | | +| test_aes_gcm.rs:25:9:25:11 | key | test_aes_gcm.rs:26:47:26:49 | key | provenance | | +| test_aes_gcm.rs:25:15:25:44 | ...::generate_key(...) | test_aes_gcm.rs:25:9:25:11 | key | provenance | | +| test_aes_gcm.rs:26:35:26:50 | ...::encode(...) | test_aes_gcm.rs:26:14:26:50 | MacroExpr | provenance | Sink:MaD:134 | +| test_aes_gcm.rs:26:47:26:49 | key | test_aes_gcm.rs:26:35:26:50 | ...::encode(...) | provenance | Config | +| test_rand.rs:6:27:6:29 | [post] key | test_rand.rs:7:37:7:39 | key | provenance | | +| test_rand.rs:7:25:7:40 | ...::encode(...) | test_rand.rs:7:14:7:40 | MacroExpr | provenance | Sink:MaD:134 | +| test_rand.rs:7:37:7:39 | key | test_rand.rs:7:25:7:40 | ...::encode(...) | provenance | Config | +| test_rand.rs:7:37:7:39 | key | test_rand.rs:8:44:8:46 | key | provenance | | +| test_rand.rs:8:44:8:46 | key | test_rand.rs:8:43:8:46 | &key | provenance | | +| test_rand.rs:8:44:8:46 | key | test_rand.rs:8:43:8:46 | &key | provenance | Config | +| test_rand.rs:13:40:13:42 | [post] key | test_rand.rs:14:37:14:39 | key | provenance | | +| test_rand.rs:14:25:14:40 | ...::encode(...) | test_rand.rs:14:14:14:40 | MacroExpr | provenance | Sink:MaD:134 | +| test_rand.rs:14:37:14:39 | key | test_rand.rs:14:25:14:40 | ...::encode(...) | provenance | Config | +| test_rand.rs:14:37:14:39 | key | test_rand.rs:15:44:15:46 | key | provenance | | +| test_rand.rs:15:44:15:46 | key | test_rand.rs:15:43:15:46 | &key | provenance | | +| test_rand.rs:15:44:15:46 | key | test_rand.rs:15:43:15:46 | &key | provenance | Config | +| test_rand.rs:20:27:20:36 | [post] request_id | test_rand.rs:21:44:21:53 | request_id | provenance | | +| test_rand.rs:21:32:21:54 | ...::encode(...) | test_rand.rs:21:14:21:54 | MacroExpr | provenance | Sink:MaD:134 | +| test_rand.rs:21:44:21:53 | request_id | test_rand.rs:21:32:21:54 | ...::encode(...) | provenance | Config | +| test_rand.rs:26:40:26:42 | [post] key | test_rand.rs:28:44:28:46 | key | provenance | | +| test_rand.rs:28:44:28:46 | key | test_rand.rs:28:43:28:46 | &key | provenance | | +| test_rand.rs:28:44:28:46 | key | test_rand.rs:28:43:28:46 | &key | provenance | Config | +| test_rand.rs:33:31:33:33 | [post] key | test_rand.rs:34:37:34:39 | key | provenance | | +| test_rand.rs:34:25:34:40 | ...::encode(...) | test_rand.rs:34:14:34:40 | MacroExpr | provenance | Sink:MaD:134 | +| test_rand.rs:34:37:34:39 | key | test_rand.rs:34:25:34:40 | ...::encode(...) | provenance | Config | +| test_rand.rs:34:37:34:39 | key | test_rand.rs:35:44:35:46 | key | provenance | | +| test_rand.rs:35:44:35:46 | key | test_rand.rs:35:43:35:46 | &key | provenance | | +| test_rand.rs:35:44:35:46 | key | test_rand.rs:35:43:35:46 | &key | provenance | Config | +| test_rand.rs:40:44:40:53 | [post] request_id | test_rand.rs:41:44:41:53 | request_id | provenance | | +| test_rand.rs:41:32:41:54 | ...::encode(...) | test_rand.rs:41:14:41:54 | MacroExpr | provenance | Sink:MaD:134 | +| test_rand.rs:41:44:41:53 | request_id | test_rand.rs:41:32:41:54 | ...::encode(...) | provenance | Config | +| test_ring.rs:22:20:22:28 | [post] key_bytes | test_ring.rs:23:45:23:53 | key_bytes | provenance | | +| test_ring.rs:23:32:23:54 | ...::encode(...) | test_ring.rs:23:14:23:54 | MacroExpr | provenance | Sink:MaD:134 | +| test_ring.rs:23:44:23:53 | &key_bytes | test_ring.rs:23:32:23:54 | ...::encode(...) | provenance | Config | +| test_ring.rs:23:44:23:53 | &key_bytes [&ref] | test_ring.rs:23:32:23:54 | ...::encode(...) | provenance | Config | +| test_ring.rs:23:45:23:53 | key_bytes | test_ring.rs:23:44:23:53 | &key_bytes | provenance | Config | +| test_ring.rs:23:45:23:53 | key_bytes | test_ring.rs:23:44:23:53 | &key_bytes [&ref] | provenance | | +| test_ring.rs:23:45:23:53 | key_bytes | test_ring.rs:25:54:25:62 | key_bytes | provenance | | +| test_ring.rs:25:54:25:62 | key_bytes | test_ring.rs:25:53:25:62 | &key_bytes | provenance | | +| test_ring.rs:25:54:25:62 | key_bytes | test_ring.rs:25:53:25:62 | &key_bytes | provenance | Config | +| test_ring.rs:37:20:37:28 | [post] key_bytes | test_ring.rs:40:55:40:63 | key_bytes | provenance | | +| test_ring.rs:40:55:40:63 | key_bytes | test_ring.rs:40:54:40:63 | &key_bytes | provenance | | +| test_ring.rs:40:55:40:63 | key_bytes | test_ring.rs:40:54:40:63 | &key_bytes | provenance | Config | +| test_ring.rs:47:20:47:29 | [post] request_id | test_ring.rs:49:45:49:54 | request_id | provenance | | +| test_ring.rs:49:33:49:55 | ...::encode(...) | test_ring.rs:49:14:49:55 | MacroExpr | provenance | Sink:MaD:134 | +| test_ring.rs:49:45:49:54 | request_id | test_ring.rs:49:33:49:55 | ...::encode(...) | provenance | Config | +| test_ring.rs:60:9:60:11 | key | test_ring.rs:61:44:61:46 | key | provenance | | +| test_ring.rs:60:15:60:28 | random_bytes(...) | test_ring.rs:60:9:60:11 | key | provenance | | +| test_ring.rs:61:44:61:46 | key | test_ring.rs:61:43:61:46 | &key | provenance | | +| test_ring.rs:61:44:61:46 | key | test_ring.rs:61:43:61:46 | &key | provenance | Config | +| test_ring.rs:62:9:62:18 | request_id | test_ring.rs:64:45:64:54 | request_id | provenance | | +| test_ring.rs:62:22:62:35 | random_bytes(...) | test_ring.rs:62:9:62:18 | request_id | provenance | | +| test_ring.rs:64:33:64:55 | ...::encode(...) | test_ring.rs:64:14:64:55 | MacroExpr | provenance | Sink:MaD:134 | +| test_ring.rs:64:45:64:54 | request_id | test_ring.rs:64:33:64:55 | ...::encode(...) | provenance | Config | +| test_ring.rs:68:9:68:11 | key | test_ring.rs:69:38:69:40 | key | provenance | | +| test_ring.rs:68:15:68:28 | random_bytes(...) | test_ring.rs:68:9:68:11 | key | provenance | | +| test_ring.rs:69:26:69:41 | ...::encode(...) | test_ring.rs:69:14:69:41 | MacroExpr | provenance | Sink:MaD:134 | +| test_ring.rs:69:38:69:40 | key | test_ring.rs:69:26:69:41 | ...::encode(...) | provenance | Config | +| test_ring.rs:69:38:69:40 | key | test_ring.rs:70:44:70:46 | key | provenance | | +| test_ring.rs:70:44:70:46 | key | test_ring.rs:70:43:70:46 | &key | provenance | | +| test_ring.rs:70:44:70:46 | key | test_ring.rs:70:43:70:46 | &key | provenance | Config | +| test_ring.rs:74:9:74:18 | request_id | test_ring.rs:76:45:76:54 | request_id | provenance | | +| test_ring.rs:74:22:74:35 | random_bytes(...) | test_ring.rs:74:9:74:18 | request_id | provenance | | +| test_ring.rs:76:33:76:55 | ...::encode(...) | test_ring.rs:76:14:76:55 | MacroExpr | provenance | Sink:MaD:134 | +| test_ring.rs:76:45:76:54 | request_id | test_ring.rs:76:33:76:55 | ...::encode(...) | provenance | Config | +| test_ring.rs:98:9:98:11 | key | test_ring.rs:99:38:99:40 | key | provenance | | +| test_ring.rs:98:15:98:48 | explicitly_returned_random_bytes(...) | test_ring.rs:98:9:98:11 | key | provenance | | +| test_ring.rs:99:26:99:41 | ...::encode(...) | test_ring.rs:99:14:99:41 | MacroExpr | provenance | Sink:MaD:134 | +| test_ring.rs:99:38:99:40 | key | test_ring.rs:99:26:99:41 | ...::encode(...) | provenance | Config | +| test_ring.rs:99:38:99:40 | key | test_ring.rs:100:44:100:46 | key | provenance | | +| test_ring.rs:100:44:100:46 | key | test_ring.rs:100:43:100:46 | &key | provenance | | +| test_ring.rs:100:44:100:46 | key | test_ring.rs:100:43:100:46 | &key | provenance | Config | +| test_ring.rs:104:9:104:11 | key | test_ring.rs:105:44:105:46 | key | provenance | | +| test_ring.rs:104:15:104:48 | explicitly_returned_random_bytes(...) | test_ring.rs:104:9:104:11 | key | provenance | | +| test_ring.rs:105:44:105:46 | key | test_ring.rs:105:43:105:46 | &key | provenance | | +| test_ring.rs:105:44:105:46 | key | test_ring.rs:105:43:105:46 | &key | provenance | Config | +| test_ring.rs:106:9:106:18 | request_id | test_ring.rs:107:45:107:54 | request_id | provenance | | +| test_ring.rs:106:22:106:55 | explicitly_returned_random_bytes(...) | test_ring.rs:106:9:106:18 | request_id | provenance | | +| test_ring.rs:107:33:107:55 | ...::encode(...) | test_ring.rs:107:14:107:55 | MacroExpr | provenance | Sink:MaD:134 | +| test_ring.rs:107:45:107:54 | request_id | test_ring.rs:107:33:107:55 | ...::encode(...) | provenance | Config | +nodes +| test_aes.rs:7:31:7:39 | [post] key_bytes | semmle.label | [post] key_bytes | +| test_aes.rs:8:11:8:42 | MacroExpr | semmle.label | MacroExpr | +| test_aes.rs:9:15:9:63 | MacroExpr | semmle.label | MacroExpr | +| test_aes.rs:9:36:9:63 | ...::encode_upper(...) | semmle.label | ...::encode_upper(...) | +| test_aes.rs:9:54:9:62 | key_bytes | semmle.label | key_bytes | +| test_aes.rs:10:41:10:50 | &key_bytes | semmle.label | &key_bytes | +| test_aes.rs:10:41:10:50 | &key_bytes | semmle.label | &key_bytes | +| test_aes.rs:10:41:10:50 | &key_bytes [&ref] | semmle.label | &key_bytes [&ref] | +| test_aes.rs:10:42:10:50 | key_bytes | semmle.label | key_bytes | +| test_aes_gcm.rs:5:9:5:11 | key | semmle.label | key | +| test_aes_gcm.rs:5:15:5:44 | ...::generate_key(...) | semmle.label | ...::generate_key(...) | +| test_aes_gcm.rs:6:14:6:52 | MacroExpr | semmle.label | MacroExpr | +| test_aes_gcm.rs:6:37:6:52 | ...::encode(...) | semmle.label | ...::encode(...) | +| test_aes_gcm.rs:6:49:6:51 | key | semmle.label | key | +| test_aes_gcm.rs:7:33:7:36 | &key | semmle.label | &key | +| test_aes_gcm.rs:7:33:7:36 | &key | semmle.label | &key | +| test_aes_gcm.rs:7:33:7:36 | &key [&ref] | semmle.label | &key [&ref] | +| test_aes_gcm.rs:7:34:7:36 | key | semmle.label | key | +| test_aes_gcm.rs:15:9:15:11 | key | semmle.label | key | +| test_aes_gcm.rs:15:15:15:44 | ...::generate_key(...) | semmle.label | ...::generate_key(...) | +| test_aes_gcm.rs:16:33:16:36 | &key | semmle.label | &key | +| test_aes_gcm.rs:16:33:16:36 | &key | semmle.label | &key | +| test_aes_gcm.rs:16:33:16:36 | &key [&ref] | semmle.label | &key [&ref] | +| test_aes_gcm.rs:16:34:16:36 | key | semmle.label | key | +| test_aes_gcm.rs:25:9:25:11 | key | semmle.label | key | +| test_aes_gcm.rs:25:15:25:44 | ...::generate_key(...) | semmle.label | ...::generate_key(...) | +| test_aes_gcm.rs:26:14:26:50 | MacroExpr | semmle.label | MacroExpr | +| test_aes_gcm.rs:26:35:26:50 | ...::encode(...) | semmle.label | ...::encode(...) | +| test_aes_gcm.rs:26:47:26:49 | key | semmle.label | key | +| test_rand.rs:6:27:6:29 | [post] key | semmle.label | [post] key | +| test_rand.rs:7:14:7:40 | MacroExpr | semmle.label | MacroExpr | +| test_rand.rs:7:25:7:40 | ...::encode(...) | semmle.label | ...::encode(...) | +| test_rand.rs:7:37:7:39 | key | semmle.label | key | +| test_rand.rs:8:43:8:46 | &key | semmle.label | &key | +| test_rand.rs:8:44:8:46 | key | semmle.label | key | +| test_rand.rs:13:40:13:42 | [post] key | semmle.label | [post] key | +| test_rand.rs:14:14:14:40 | MacroExpr | semmle.label | MacroExpr | +| test_rand.rs:14:25:14:40 | ...::encode(...) | semmle.label | ...::encode(...) | +| test_rand.rs:14:37:14:39 | key | semmle.label | key | +| test_rand.rs:15:43:15:46 | &key | semmle.label | &key | +| test_rand.rs:15:44:15:46 | key | semmle.label | key | +| test_rand.rs:20:27:20:36 | [post] request_id | semmle.label | [post] request_id | +| test_rand.rs:21:14:21:54 | MacroExpr | semmle.label | MacroExpr | +| test_rand.rs:21:32:21:54 | ...::encode(...) | semmle.label | ...::encode(...) | +| test_rand.rs:21:44:21:53 | request_id | semmle.label | request_id | +| test_rand.rs:26:40:26:42 | [post] key | semmle.label | [post] key | +| test_rand.rs:28:43:28:46 | &key | semmle.label | &key | +| test_rand.rs:28:44:28:46 | key | semmle.label | key | +| test_rand.rs:33:31:33:33 | [post] key | semmle.label | [post] key | +| test_rand.rs:34:14:34:40 | MacroExpr | semmle.label | MacroExpr | +| test_rand.rs:34:25:34:40 | ...::encode(...) | semmle.label | ...::encode(...) | +| test_rand.rs:34:37:34:39 | key | semmle.label | key | +| test_rand.rs:35:43:35:46 | &key | semmle.label | &key | +| test_rand.rs:35:44:35:46 | key | semmle.label | key | +| test_rand.rs:40:44:40:53 | [post] request_id | semmle.label | [post] request_id | +| test_rand.rs:41:14:41:54 | MacroExpr | semmle.label | MacroExpr | +| test_rand.rs:41:32:41:54 | ...::encode(...) | semmle.label | ...::encode(...) | +| test_rand.rs:41:44:41:53 | request_id | semmle.label | request_id | +| test_ring.rs:22:20:22:28 | [post] key_bytes | semmle.label | [post] key_bytes | +| test_ring.rs:23:14:23:54 | MacroExpr | semmle.label | MacroExpr | +| test_ring.rs:23:32:23:54 | ...::encode(...) | semmle.label | ...::encode(...) | +| test_ring.rs:23:44:23:53 | &key_bytes | semmle.label | &key_bytes | +| test_ring.rs:23:44:23:53 | &key_bytes [&ref] | semmle.label | &key_bytes [&ref] | +| test_ring.rs:23:45:23:53 | key_bytes | semmle.label | key_bytes | +| test_ring.rs:25:53:25:62 | &key_bytes | semmle.label | &key_bytes | +| test_ring.rs:25:54:25:62 | key_bytes | semmle.label | key_bytes | +| test_ring.rs:37:20:37:28 | [post] key_bytes | semmle.label | [post] key_bytes | +| test_ring.rs:40:54:40:63 | &key_bytes | semmle.label | &key_bytes | +| test_ring.rs:40:55:40:63 | key_bytes | semmle.label | key_bytes | +| test_ring.rs:47:20:47:29 | [post] request_id | semmle.label | [post] request_id | +| test_ring.rs:49:14:49:55 | MacroExpr | semmle.label | MacroExpr | +| test_ring.rs:49:33:49:55 | ...::encode(...) | semmle.label | ...::encode(...) | +| test_ring.rs:49:45:49:54 | request_id | semmle.label | request_id | +| test_ring.rs:60:9:60:11 | key | semmle.label | key | +| test_ring.rs:60:15:60:28 | random_bytes(...) | semmle.label | random_bytes(...) | +| test_ring.rs:61:43:61:46 | &key | semmle.label | &key | +| test_ring.rs:61:44:61:46 | key | semmle.label | key | +| test_ring.rs:62:9:62:18 | request_id | semmle.label | request_id | +| test_ring.rs:62:22:62:35 | random_bytes(...) | semmle.label | random_bytes(...) | +| test_ring.rs:64:14:64:55 | MacroExpr | semmle.label | MacroExpr | +| test_ring.rs:64:33:64:55 | ...::encode(...) | semmle.label | ...::encode(...) | +| test_ring.rs:64:45:64:54 | request_id | semmle.label | request_id | +| test_ring.rs:68:9:68:11 | key | semmle.label | key | +| test_ring.rs:68:15:68:28 | random_bytes(...) | semmle.label | random_bytes(...) | +| test_ring.rs:69:14:69:41 | MacroExpr | semmle.label | MacroExpr | +| test_ring.rs:69:26:69:41 | ...::encode(...) | semmle.label | ...::encode(...) | +| test_ring.rs:69:38:69:40 | key | semmle.label | key | +| test_ring.rs:70:43:70:46 | &key | semmle.label | &key | +| test_ring.rs:70:44:70:46 | key | semmle.label | key | +| test_ring.rs:74:9:74:18 | request_id | semmle.label | request_id | +| test_ring.rs:74:22:74:35 | random_bytes(...) | semmle.label | random_bytes(...) | +| test_ring.rs:76:14:76:55 | MacroExpr | semmle.label | MacroExpr | +| test_ring.rs:76:33:76:55 | ...::encode(...) | semmle.label | ...::encode(...) | +| test_ring.rs:76:45:76:54 | request_id | semmle.label | request_id | +| test_ring.rs:98:9:98:11 | key | semmle.label | key | +| test_ring.rs:98:15:98:48 | explicitly_returned_random_bytes(...) | semmle.label | explicitly_returned_random_bytes(...) | +| test_ring.rs:99:14:99:41 | MacroExpr | semmle.label | MacroExpr | +| test_ring.rs:99:26:99:41 | ...::encode(...) | semmle.label | ...::encode(...) | +| test_ring.rs:99:38:99:40 | key | semmle.label | key | +| test_ring.rs:100:43:100:46 | &key | semmle.label | &key | +| test_ring.rs:100:44:100:46 | key | semmle.label | key | +| test_ring.rs:104:9:104:11 | key | semmle.label | key | +| test_ring.rs:104:15:104:48 | explicitly_returned_random_bytes(...) | semmle.label | explicitly_returned_random_bytes(...) | +| test_ring.rs:105:43:105:46 | &key | semmle.label | &key | +| test_ring.rs:105:44:105:46 | key | semmle.label | key | +| test_ring.rs:106:9:106:18 | request_id | semmle.label | request_id | +| test_ring.rs:106:22:106:55 | explicitly_returned_random_bytes(...) | semmle.label | explicitly_returned_random_bytes(...) | +| test_ring.rs:107:14:107:55 | MacroExpr | semmle.label | MacroExpr | +| test_ring.rs:107:33:107:55 | ...::encode(...) | semmle.label | ...::encode(...) | +| test_ring.rs:107:45:107:54 | request_id | semmle.label | request_id | +subpaths diff --git a/languages/rust/custom/test/CleartextLoggingOfKeyMaterial/CleartextLoggingOfKeyMaterial.qlref b/languages/rust/custom/test/CleartextLoggingOfKeyMaterial/CleartextLoggingOfKeyMaterial.qlref new file mode 100644 index 00000000..07d56bab --- /dev/null +++ b/languages/rust/custom/test/CleartextLoggingOfKeyMaterial/CleartextLoggingOfKeyMaterial.qlref @@ -0,0 +1,2 @@ +query: CleartextLoggingOfKeyMaterial/CleartextLoggingOfKeyMaterial.ql +postprocess: utils/test/InlineExpectationsTestQuery.ql diff --git a/languages/rust/custom/test/CleartextLoggingOfKeyMaterial/options.yml b/languages/rust/custom/test/CleartextLoggingOfKeyMaterial/options.yml new file mode 100644 index 00000000..788736f4 --- /dev/null +++ b/languages/rust/custom/test/CleartextLoggingOfKeyMaterial/options.yml @@ -0,0 +1,9 @@ +qltest_cargo_check: true +qltest_dependencies: + - aes = { version = "0.8.4" } + - ring = { version = "0.17.8" } + - hex = { version = "0.4.3" } + - getrandom = { version = "0.2.15" } + - log = { version = "0.4.25" } + - aes-gcm = { version = "0.10.3" } + - rand = { version = "=0.8.5" } diff --git a/languages/rust/custom/test/CleartextLoggingOfKeyMaterial/test_aes.rs b/languages/rust/custom/test/CleartextLoggingOfKeyMaterial/test_aes.rs new file mode 100644 index 00000000..a1ce6b63 --- /dev/null +++ b/languages/rust/custom/test/CleartextLoggingOfKeyMaterial/test_aes.rs @@ -0,0 +1,13 @@ +use aes::cipher::{generic_array::GenericArray, BlockEncrypt, KeyInit}; +use aes::Aes128; +use log::info; + +pub fn test_aes_bad() { + let mut key_bytes = [0u8; 16]; + getrandom::getrandom(&mut key_bytes).unwrap(); // $ Source[rust/cleartext-logging-key-material] + info!("generated key: {:?}", key_bytes); // $ Alert[rust/cleartext-logging-key-material] + eprintln!("generated key: {}", hex::encode_upper(key_bytes)); // $ Alert[rust/cleartext-logging-key-material] + let cipher = Aes128::new_from_slice(&key_bytes).unwrap(); + let mut block = GenericArray::from([42u8; 16]); + cipher.encrypt_block(&mut block); +} diff --git a/languages/rust/custom/test/CleartextLoggingOfKeyMaterial/test_aes_gcm.rs b/languages/rust/custom/test/CleartextLoggingOfKeyMaterial/test_aes_gcm.rs new file mode 100644 index 00000000..2c181360 --- /dev/null +++ b/languages/rust/custom/test/CleartextLoggingOfKeyMaterial/test_aes_gcm.rs @@ -0,0 +1,38 @@ +use aes_gcm::aead::{Aead, AeadCore, KeyInit, OsRng}; +use aes_gcm::Aes256Gcm; + +pub fn test_aes_gcm_bad(plaintext: &[u8]) -> Vec { + let key = Aes256Gcm::generate_key(OsRng); // $ Source[rust/cleartext-logging-key-material] + println!("AES-256-GCM key: {}", hex::encode(key)); // $ Alert[rust/cleartext-logging-key-material] + let cipher = Aes256Gcm::new(&key); + let nonce = Aes256Gcm::generate_nonce(&mut OsRng); + // nonces are not secret: safe + println!("nonce: {}", hex::encode(nonce)); + cipher.encrypt(&nonce, plaintext).unwrap() +} + +pub fn test_aes_gcm_good(plaintext: &[u8]) -> Vec { + let key = Aes256Gcm::generate_key(OsRng); + let cipher = Aes256Gcm::new(&key); + let nonce = Aes256Gcm::generate_nonce(&mut OsRng); + let ciphertext = cipher.encrypt(&nonce, plaintext).unwrap(); + // ciphertext is not key material: safe + println!("ciphertext: {}", hex::encode(&ciphertext)); + ciphertext +} + +pub fn test_generate_key_logged_and_returned() -> aes_gcm::Key { + let key = Aes256Gcm::generate_key(OsRng); // $ Source[rust/cleartext-logging-key-material] + println!("generated key: {}", hex::encode(key)); // $ Alert[rust/cleartext-logging-key-material] + key +} + +pub fn test_generate_key_returned_without_logging() -> aes_gcm::Key { + Aes256Gcm::generate_key(OsRng) +} + +pub fn test_generate_key_length_logged() -> aes_gcm::Key { + let key = Aes256Gcm::generate_key(OsRng); + println!("key length: {}", key.len()); + key +} diff --git a/languages/rust/custom/test/CleartextLoggingOfKeyMaterial/test_rand.rs b/languages/rust/custom/test/CleartextLoggingOfKeyMaterial/test_rand.rs new file mode 100644 index 00000000..6e332210 --- /dev/null +++ b/languages/rust/custom/test/CleartextLoggingOfKeyMaterial/test_rand.rs @@ -0,0 +1,42 @@ +use rand::{rngs::OsRng, RngCore}; +use ring::aead::{UnboundKey, AES_256_GCM}; + +pub fn test_os_rng_logged_key() { + let mut key = [0u8; 32]; + OsRng.fill_bytes(&mut key); // $ Source[rust/cleartext-logging-key-material] + println!("key: {}", hex::encode(key)); // $ Alert[rust/cleartext-logging-key-material] + let _ = UnboundKey::new(&AES_256_GCM, &key); +} + +pub fn test_thread_rng_logged_key() { + let mut key = [0u8; 32]; + rand::thread_rng().fill_bytes(&mut key); // $ Source[rust/cleartext-logging-key-material] + println!("key: {}", hex::encode(key)); // $ Alert[rust/cleartext-logging-key-material] + let _ = UnboundKey::new(&AES_256_GCM, &key); +} + +pub fn test_os_rng_request_id() { + let mut request_id = [0u8; 32]; + OsRng.fill_bytes(&mut request_id); + println!("request id: {}", hex::encode(request_id)); +} + +pub fn test_thread_rng_key_not_logged() { + let mut key = [0u8; 32]; + rand::thread_rng().fill_bytes(&mut key); + println!("key length: {}", key.len()); + let _ = UnboundKey::new(&AES_256_GCM, &key); +} + +pub fn test_os_rng_try_logged_key() { + let mut key = [0u8; 32]; + OsRng.try_fill_bytes(&mut key).unwrap(); // $ Source[rust/cleartext-logging-key-material] + println!("key: {}", hex::encode(key)); // $ Alert[rust/cleartext-logging-key-material] + let _ = UnboundKey::new(&AES_256_GCM, &key); +} + +pub fn test_thread_rng_try_request_id() { + let mut request_id = [0u8; 32]; + rand::thread_rng().try_fill_bytes(&mut request_id).unwrap(); + println!("request id: {}", hex::encode(request_id)); +} diff --git a/languages/rust/custom/test/CleartextLoggingOfKeyMaterial/test_ring.rs b/languages/rust/custom/test/CleartextLoggingOfKeyMaterial/test_ring.rs new file mode 100644 index 00000000..0b65a7d1 --- /dev/null +++ b/languages/rust/custom/test/CleartextLoggingOfKeyMaterial/test_ring.rs @@ -0,0 +1,108 @@ +use ring::aead::{Aad, BoundKey, Nonce, NonceSequence, SealingKey, UnboundKey, AES_256_GCM, NONCE_LEN}; +use ring::error::Unspecified; +use ring::rand::{SecureRandom, SystemRandom}; + +struct CounterNonceSequence(u32); + +impl NonceSequence for CounterNonceSequence { + fn advance(&mut self) -> Result { + let mut nonce_bytes = vec![0; NONCE_LEN]; + let bytes = self.0.to_be_bytes(); + nonce_bytes[8..].copy_from_slice(&bytes); + // nonces are not secret: safe + println!("nonce_bytes = {}", hex::encode(&nonce_bytes)); + self.0 += 1; + Nonce::try_assume_unique_for_key(&nonce_bytes) + } +} + +pub fn test_ring_bad() -> Result<(), Unspecified> { + let rand = SystemRandom::new(); + let mut key_bytes = vec![0; AES_256_GCM.key_len()]; + rand.fill(&mut key_bytes)?; // $ Source[rust/cleartext-logging-key-material] + println!("key_bytes = {}", hex::encode(&key_bytes)); // $ Alert[rust/cleartext-logging-key-material] + + let unbound_key = UnboundKey::new(&AES_256_GCM, &key_bytes)?; + let mut sealing_key = SealingKey::new(unbound_key, CounterNonceSequence(1)); + let mut in_out = b"hello world".clone(); + let _tag = sealing_key.seal_in_place_separate_tag(Aad::from(b"additional public data"), &mut in_out)?; + // ciphertext is not key material: safe + println!("ciphertext = {}", hex::encode(&in_out)); + Ok(()) +} + +pub fn test_ring_good() -> Result<(), Unspecified> { + let rand = SystemRandom::new(); + let mut key_bytes = vec![0; AES_256_GCM.key_len()]; + rand.fill(&mut key_bytes)?; + // only the length is printed: safe + println!("key length = {}", key_bytes.len()); + let _unbound_key = UnboundKey::new(&AES_256_GCM, &key_bytes)?; + Ok(()) +} + +pub fn test_random_not_key() -> Result<(), Unspecified> { + let rand = SystemRandom::new(); + let mut request_id = [0u8; 16]; + rand.fill(&mut request_id)?; + // random bytes that are never used as a key: safe + println!("request id = {}", hex::encode(request_id)); + Ok(()) +} + +fn random_bytes() -> [u8; 32] { + let mut bytes = [0u8; 32]; + SystemRandom::new().fill(&mut bytes).unwrap(); + bytes +} + +pub fn test_independent_wrapper_results() { + let key = random_bytes(); + let _ = UnboundKey::new(&AES_256_GCM, &key); + let request_id = random_bytes(); + // This is a different generated value, not the key above. + println!("request id = {}", hex::encode(request_id)); +} + +pub fn test_logged_wrapper_key() { + let key = random_bytes(); // $ Source[rust/cleartext-logging-key-material] + println!("key = {}", hex::encode(key)); // $ Alert[rust/cleartext-logging-key-material] + let _ = UnboundKey::new(&AES_256_GCM, &key); +} + +pub fn test_logged_wrapper_non_key() { + let request_id = random_bytes(); + // A wrapper call is not inherently a key generation API. + println!("request id = {}", hex::encode(request_id)); +} + +fn nested_random_bytes() -> [u8; 32] { + random_bytes() +} + +pub fn test_independent_nested_wrapper_results() { + let key = nested_random_bytes(); + let _ = UnboundKey::new(&AES_256_GCM, &key); + let request_id = nested_random_bytes(); + // Independent outer calls must not share the inner random_bytes() source. + println!("request id = {}", hex::encode(request_id)); +} + +fn explicitly_returned_random_bytes() -> [u8; 32] { + let mut bytes = [0u8; 32]; + SystemRandom::new().fill(&mut bytes).unwrap(); + return bytes; +} + +pub fn test_logged_explicit_return_wrapper_key() { + let key = explicitly_returned_random_bytes(); // $ Source[rust/cleartext-logging-key-material] + println!("key = {}", hex::encode(key)); // $ Alert[rust/cleartext-logging-key-material] + let _ = UnboundKey::new(&AES_256_GCM, &key); +} + +pub fn test_independent_explicit_return_wrapper_results() { + let key = explicitly_returned_random_bytes(); + let _ = UnboundKey::new(&AES_256_GCM, &key); + let request_id = explicitly_returned_random_bytes(); + println!("request id = {}", hex::encode(request_id)); +} diff --git a/languages/rust/custom/test/HardcodedCryptographicKey/Cargo.lock b/languages/rust/custom/test/HardcodedCryptographicKey/Cargo.lock new file mode 100644 index 00000000..81350cf4 --- /dev/null +++ b/languages/rust/custom/test/HardcodedCryptographicKey/Cargo.lock @@ -0,0 +1,1419 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "aead" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d122413f284cf2d62fb1b7db97e02edb8cda96d769b16e443a4f6195e35662b0" +dependencies = [ + "crypto-common", + "generic-array", +] + +[[package]] +name = "aes" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" +dependencies = [ + "cfg-if", + "cipher", + "cpufeatures", +] + +[[package]] +name = "age" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a16cc55e640876ed7df4485dc02101bb44d318b0026ecc526cba616274270cc9" +dependencies = [ + "age-core", + "base64", + "bech32", + "chacha20poly1305", + "cookie-factory", + "hkdf", + "hmac", + "i18n-embed", + "i18n-embed-fl", + "lazy_static", + "nom", + "pin-project", + "rand 0.7.3", + "rand 0.8.5", + "rust-embed", + "scrypt", + "sha2", + "subtle", + "x25519-dalek", + "zeroize", +] + +[[package]] +name = "age-core" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3d2e815ac879dc23c1139e720d21c6cd4d1276345c772587285d965a69b8f32" +dependencies = [ + "base64", + "chacha20poly1305", + "cookie-factory", + "hkdf", + "io_tee", + "nom", + "rand 0.8.5", + "secrecy", + "sha2", +] + +[[package]] +name = "arc-swap" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "380962b3d93b99642e50b9febf72c071e97e8b32d86eae9cf4ef582bb960ae6e" +dependencies = [ + "rustversion", +] + +[[package]] +name = "base64" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" + +[[package]] +name = "basic-toml" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba62675e8242a4c4e806d12f11d136e626e6c8361d6b829310732241652a178a" +dependencies = [ + "serde", +] + +[[package]] +name = "bech32" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d86b93f97252c47b41663388e6d155714a9d0c398b99f1005cbc5f978b29f445" + +[[package]] +name = "bitflags" +version = "2.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06" + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "camellia" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3264e2574e9ef2b53ce6f536dea83a69ac0bc600b762d1523ff83fe07230ce30" +dependencies = [ + "byteorder", + "cipher", +] + +[[package]] +name = "cc" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86e055fa6e3e40ad6187ba25b6855eeb635d5271f8e0f0e1e9a5826b8d75bea0" +dependencies = [ + "find-msvc-tools", + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600" + +[[package]] +name = "chacha20" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3613f74bd2eac03dad61bd53dbe620703d4371614fe0bc3b9f04dd36fe4e818" +dependencies = [ + "cfg-if", + "cipher", + "cpufeatures", +] + +[[package]] +name = "chacha20poly1305" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10cd79432192d1c0f4e1a0fef9527696cc039165d729fb41b3f4f4f354c2dc35" +dependencies = [ + "aead", + "chacha20", + "cipher", + "poly1305", + "zeroize", +] + +[[package]] +name = "cipher" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" +dependencies = [ + "crypto-common", + "inout", + "zeroize", +] + +[[package]] +name = "cmov" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c9ea0ac24bc397ab3c98583a3c9ba74fa56b09a4449bbe172b9b1ddb016027a" + +[[package]] +name = "cookie-factory" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9885fa71e26b8ab7855e2ec7cae6e9b380edff76cd052e07c683a0319d51b3a2" +dependencies = [ + "futures", +] + +[[package]] +name = "cpufeatures" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" +dependencies = [ + "libc", +] + +[[package]] +name = "crypto-common" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "ct-codecs" +version = "1.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fd9f3db6f2cfef61c10613071955154ffdc9e515daebff26de4b54e35038fdd" + +[[package]] +name = "curve25519-dalek" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b9fdf9972b2bd6af2d913799d9ebc165ea4d2e65878e329d9c6b372c4491b61" +dependencies = [ + "byteorder", + "digest 0.9.0", + "rand_core 0.5.1", + "subtle", + "zeroize", +] + +[[package]] +name = "dashmap" +version = "5.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856" +dependencies = [ + "cfg-if", + "hashbrown", + "lock_api", + "once_cell", + "parking_lot_core", +] + +[[package]] +name = "digest" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +dependencies = [ + "generic-array", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", + "subtle", +] + +[[package]] +name = "displaydoc" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6232dd377dcc64799954cbd3a9bb882e9cdc1308ccd87b1c098f1fb2eaf82a8" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.9", +] + +[[package]] +name = "fiat-crypto" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64cd1e32ddd350061ae6edb1b082d7c54915b5c672c389143b9a63403a109f24" + +[[package]] +name = "find-crate" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59a98bbaacea1c0eb6a0876280051b892eb73594fd90cf3b20e9c817029c57d2" +dependencies = [ + "toml", +] + +[[package]] +name = "find-msvc-tools" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c66915cc5391097de7a2b0b972e8505aa33c0df401fd3a6811dbdb32881ba48" + +[[package]] +name = "fluent" +version = "0.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb74634707bebd0ce645a981148e8fb8c7bccd4c33c652aeffd28bf2f96d555a" +dependencies = [ + "fluent-bundle", + "unic-langid", +] + +[[package]] +name = "fluent-bundle" +version = "0.15.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fe0a21ee80050c678013f82edf4b705fe2f26f1f9877593d13198612503f493" +dependencies = [ + "fluent-langneg", + "fluent-syntax", + "intl-memoizer", + "intl_pluralrules", + "rustc-hash 1.1.0", + "self_cell 0.10.3", + "smallvec", + "unic-langid", +] + +[[package]] +name = "fluent-langneg" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7eebbe59450baee8282d71676f3bfed5689aeab00b27545e83e5f14b1195e8b0" +dependencies = [ + "unic-langid", +] + +[[package]] +name = "fluent-syntax" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a530c4694a6a8d528794ee9bbd8ba0122e779629ac908d15ad5a7ae7763a33d" +dependencies = [ + "thiserror", +] + +[[package]] +name = "futures" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a31d2a3fbaaeb2af2368bbdd904aa8e812d3c04a1ee10d3171f52d556e5d0a3" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f9e3d69d39e4862ffed03ed071a76f9a13ba1d9109d355b0f0aa6b15e393c4" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e" + +[[package]] +name = "futures-executor" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "031b47cf1a3c6cc8bc2fc76cd437f521619387907d469316e7c0bc278f1f5432" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53c0fa8157de1303bfffdaa1cc2a673bfffb60102f76b0ef4441659124373fed" + +[[package]] +name = "futures-macro" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb9654ba8355388abeb8dcb4fc62f511300867002afc858860463bdd9fe0c44" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.9", +] + +[[package]] +name = "futures-sink" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1944426bf7d03f1d14f708785e4b33efd750b36d48a157b836b3efc15ede8e1d" + +[[package]] +name = "futures-task" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd417de3d1d015fc3bfd2b1ea46dfc7bab72ef86f1cc7cc9c78e728b34a6d1fd" + +[[package]] +name = "futures-util" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d50a92467f8ba5dd6e3ee5d4bd04d73ab2e4e1c44474a0674821dfce14b79bc" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "slab", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" +dependencies = [ + "cfg-if", + "libc", + "wasi 0.9.0+wasi-snapshot-preview1", +] + +[[package]] +name = "getrandom" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" +dependencies = [ + "cfg-if", + "libc", + "wasi 0.11.1+wasi-snapshot-preview1", +] + +[[package]] +name = "getrandom" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099" +dependencies = [ + "cfg-if", + "libc", + "r-efi", +] + +[[package]] +name = "hashbrown" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "hkdf" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b5f8eb2ad728638ea2c7d47a21db23b7b58a72ed6a38256b8a1849f15fbbdf7" +dependencies = [ + "hmac", +] + +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest 0.10.7", +] + +[[package]] +name = "i18n-config" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e06b90c8a0d252e203c94344b21e35a30f3a3a85dc7db5af8f8df9f3e0c63ef" +dependencies = [ + "basic-toml", + "log", + "serde", + "serde_derive", + "thiserror", + "unic-langid", +] + +[[package]] +name = "i18n-embed" +version = "0.13.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92a86226a7a16632de6723449ee5fe70bac5af718bc642ee9ca2f0f6e14fa1fa" +dependencies = [ + "arc-swap", + "fluent", + "fluent-langneg", + "fluent-syntax", + "i18n-embed-impl", + "intl-memoizer", + "lazy_static", + "log", + "parking_lot", + "rust-embed", + "thiserror", + "unic-langid", + "walkdir", +] + +[[package]] +name = "i18n-embed-fl" +version = "0.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d26a3d3569737dfaac7fc1c4078e6af07471c3060b8e570bcd83cdd5f4685395" +dependencies = [ + "dashmap", + "find-crate", + "fluent", + "fluent-syntax", + "i18n-config", + "i18n-embed", + "lazy_static", + "proc-macro-error", + "proc-macro2", + "quote", + "strsim", + "syn 2.0.119", + "unic-langid", +] + +[[package]] +name = "i18n-embed-impl" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f2cc0e0523d1fe6fc2c6f66e5038624ea8091b3e7748b5e8e0c84b1698db6c2" +dependencies = [ + "find-crate", + "i18n-config", + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "inout" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "879f10e63c20629ecabbb64a8010319738c66a5cd0c29b02d63d272b03751d01" +dependencies = [ + "generic-array", +] + +[[package]] +name = "intl-memoizer" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "310da2e345f5eb861e7a07ee182262e94975051db9e4223e909ba90f392f163f" +dependencies = [ + "type-map", + "unic-langid", +] + +[[package]] +name = "intl_pluralrules" +version = "7.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "078ea7b7c29a2b4df841a7f6ac8775ff6074020c6776d48491ce2268e068f972" +dependencies = [ + "unic-langid", +] + +[[package]] +name = "io_tee" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b3f7cef34251886990511df1c61443aa928499d598a9473929ab5a90a527304" + +[[package]] +name = "lazy_static" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20870f649af7073d53e38067b2a84312175d56ea15217e1b15bc83506ec50afb" + +[[package]] +name = "libc" +version = "0.2.191" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a" + +[[package]] +name = "lock_api" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" +dependencies = [ + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d15f86d12da44cd8d4ec3c73984537eb7f4cadcb9776a575a0a8a05ca11005c" + +[[package]] +name = "memchr" +version = "2.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" + +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + +[[package]] +name = "once_cell" +version = "1.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" + +[[package]] +name = "opaque-debug" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" + +[[package]] +name = "orion" +version = "0.17.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be0ab36a035b13899701dd991f918616c31694c9219908807ee56d6562c60568" +dependencies = [ + "cmov", + "ct-codecs", + "fiat-crypto", + "getrandom 0.4.3", + "subtle", + "zeroize", +] + +[[package]] +name = "parking_lot" +version = "0.12.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-link", +] + +[[package]] +name = "pbkdf2" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83a0692ec44e4cf1ef28ca317f14f8f07da2d95ec3fa01f86e4467b725e60917" +dependencies = [ + "digest 0.10.7", +] + +[[package]] +name = "pin-project" +version = "1.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2466b2336ed02bcdca6b294417127b90ec92038d1d5c4fbeac971a922e0e0924" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c96395f0a926bc13b1c17622aaddda1ecb55d49c8f1bf9777e4d877800a43f8b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" + +[[package]] +name = "poly1305" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8159bd90725d2df49889a078b54f4f79e87f1f8a8444194cdca81d38f5393abf" +dependencies = [ + "cpufeatures", + "opaque-debug", + "universal-hash", +] + +[[package]] +name = "ppv-lite86" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn 1.0.109", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + +[[package]] +name = "proc-macro2" +version = "1.0.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "r-efi" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" + +[[package]] +name = "rand" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" +dependencies = [ + "getrandom 0.1.16", + "libc", + "rand_chacha 0.2.2", + "rand_core 0.5.1", + "rand_hc", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha 0.3.1", + "rand_core 0.6.4", +] + +[[package]] +name = "rand_chacha" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" +dependencies = [ + "ppv-lite86", + "rand_core 0.5.1", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core 0.6.4", +] + +[[package]] +name = "rand_core" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" +dependencies = [ + "getrandom 0.1.16", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom 0.2.17", +] + +[[package]] +name = "rand_hc" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" +dependencies = [ + "rand_core 0.5.1", +] + +[[package]] +name = "redox_syscall" +version = "0.5.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" +dependencies = [ + "bitflags", +] + +[[package]] +name = "ring" +version = "0.17.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" +dependencies = [ + "cc", + "cfg-if", + "getrandom 0.2.17", + "libc", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rust-embed" +version = "6.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a36224c3276f8c4ebc8c20f158eca7ca4359c8db89991c4925132aaaf6702661" +dependencies = [ + "rust-embed-impl", + "rust-embed-utils", + "walkdir", +] + +[[package]] +name = "rust-embed-impl" +version = "6.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49b94b81e5b2c284684141a2fb9e2a31be90638caf040bf9afbc5a0416afe1ac" +dependencies = [ + "proc-macro2", + "quote", + "rust-embed-utils", + "syn 2.0.119", + "walkdir", +] + +[[package]] +name = "rust-embed-utils" +version = "7.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d38ff6bf570dc3bb7100fce9f7b60c33fa71d80e88da3f2580df4ff2bdded74" +dependencies = [ + "sha2", + "walkdir", +] + +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + +[[package]] +name = "rustc-hash" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b1e7f9a428571be2dc5bc0505c13fb6bf936822b894ec87abf8a08a4e51742d" + +[[package]] +name = "rustversion" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f" + +[[package]] +name = "salsa20" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97a22f5af31f73a954c10289c93e8a50cc23d971e80ee446f1f6f7137a088213" +dependencies = [ + "cipher", +] + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "scrypt" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f9e24d2b632954ded8ab2ef9fea0a0c769ea56ea98bddbafbad22caeeadf45d" +dependencies = [ + "hmac", + "pbkdf2", + "salsa20", + "sha2", +] + +[[package]] +name = "secrecy" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9bd1c54ea06cfd2f6b63219704de0b9b4f72dcc2b8fdef820be6cd799780e91e" +dependencies = [ + "zeroize", +] + +[[package]] +name = "self_cell" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e14e4d63b804dc0c7ec4a1e52bcb63f02c7ac94476755aa579edac21e01f915d" +dependencies = [ + "self_cell 1.3.0", +] + +[[package]] +name = "self_cell" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ab42ca02749e120097e328d91d415325bdf43b1c72c4c8badf37375fe40a813" + +[[package]] +name = "serde" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.9", +] + +[[package]] +name = "sha2" +version = "0.10.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest 0.10.7", +] + +[[package]] +name = "shlex" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" + +[[package]] +name = "slab" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" + +[[package]] +name = "smallvec" +version = "1.16.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0d5d4b1981b8bbbb7aed204cae5726d683d5d6ac7e74ec54122ea28f315e7c8" + +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.119" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "3.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d78c8dee4c7bf0e14673097256fed6142ce9d3b85a408189d07482442145823b" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "test" +version = "0.0.1" +dependencies = [ + "aes", + "age", + "camellia", + "getrandom 0.2.17", + "hex", + "orion", + "rand 0.8.5", + "ring", +] + +[[package]] +name = "thiserror" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "tinystr" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abc840c238154d58f9e86b2792261edfde565a17696e1cda1a449de27979801a" +dependencies = [ + "displaydoc", + "serde_core", + "zerovec", +] + +[[package]] +name = "toml" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" +dependencies = [ + "serde", +] + +[[package]] +name = "type-map" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb30dbbd9036155e74adad6812e9898d03ec374946234fbcebd5dfc7b9187b90" +dependencies = [ + "rustc-hash 2.1.3", +] + +[[package]] +name = "typenum" +version = "1.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20" + +[[package]] +name = "unic-langid" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a28ba52c9b05311f4f6e62d5d9d46f094bd6e84cb8df7b3ef952748d752a7d05" +dependencies = [ + "unic-langid-impl", +] + +[[package]] +name = "unic-langid-impl" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dce1bf08044d4b7a94028c93786f8566047edc11110595914de93362559bc658" +dependencies = [ + "serde", + "tinystr", +] + +[[package]] +name = "unicode-ident" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563" + +[[package]] +name = "universal-hash" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc1de2c688dc15305988b563c3854064043356019f97a4b46276fe734c4f07ea" +dependencies = [ + "crypto-common", + "subtle", +] + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + +[[package]] +name = "wasi" +version = "0.9.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" + +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + +[[package]] +name = "winapi-util" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "x25519-dalek" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a0c105152107e3b96f6a00a65e86ce82d9b125230e1c4302940eca58ff71f4f" +dependencies = [ + "curve25519-dalek", + "rand_core 0.5.1", + "zeroize", +] + +[[package]] +name = "zerocopy" +version = "0.8.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5fe1f8f1b06191a00962174c61aa5005e0bb391a6d80d07e24d115c01a92ed8" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.8.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "863ad3ac83293fb4d740aedbfdc9240dd8d1a50c1099acd76ce80ce7c7230c7f" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "zerofrom" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ec05a11813ea801ff6d75110ad09cd0824ddba17dfe17128ea0d5f68e6c5272" + +[[package]] +name = "zeroize" +version = "1.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13084392c5e4bc371903e2935a5eaeed24905a7511356b883835e18a78f6879" +dependencies = [ + "zeroize_derive", +] + +[[package]] +name = "zeroize_derive" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c50655cbb0fe3fc43170059e702f1ce5e19b84cec58dc87b037a09935c2f328" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "zerovec" +version = "0.11.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f58a2799cfe9a1670c7ea8edbd52ef8edb93cb37a7f83bf31ba9e35d9dae6a40" +dependencies = [ + "serde", + "zerofrom", +] diff --git a/languages/rust/custom/test/HardcodedCryptographicKey/HardcodedCryptographicKey.expected b/languages/rust/custom/test/HardcodedCryptographicKey/HardcodedCryptographicKey.expected new file mode 100644 index 00000000..a8db2e76 --- /dev/null +++ b/languages/rust/custom/test/HardcodedCryptographicKey/HardcodedCryptographicKey.expected @@ -0,0 +1,136 @@ +#select +| test_aes.rs:5:34:5:87 | [...] | test_aes.rs:5:34:5:87 | [...] | test_aes.rs:7:30:7:33 | &key | This hard-coded value is used as $@. | test_aes.rs:7:30:7:33 | &key | a key | +| test_aes.rs:12:34:12:42 | [4u8; 16] | test_aes.rs:12:34:12:42 | [4u8; 16] | test_aes.rs:14:30:14:33 | &key | This hard-coded value is used as $@. | test_aes.rs:14:30:14:33 | &key | a key | +| test_age.rs:26:22:26:52 | "this is not a good passphrase... | test_age.rs:26:22:26:52 | "this is not a good passphrase... | test_age.rs:6:58:6:91 | ...::new(...) | This hard-coded value is used as $@. | test_age.rs:6:58:6:91 | ...::new(...) | a password | +| test_age.rs:26:22:26:52 | "this is not a good passphrase... | test_age.rs:26:22:26:52 | "this is not a good passphrase... | test_age.rs:20:40:20:74 | &... | This hard-coded value is used as $@. | test_age.rs:20:40:20:74 | &... | a password | +| test_age.rs:33:70:33:100 | "this is not a good passphrase... | test_age.rs:33:70:33:100 | "this is not a good passphrase... | test_age.rs:33:58:33:112 | ...::new(...) | This hard-coded value is used as $@. | test_age.rs:33:58:33:112 | ...::new(...) | a password | +| test_age.rs:44:53:44:83 | "this is not a good passphrase... | test_age.rs:44:53:44:83 | "this is not a good passphrase... | test_age.rs:44:40:44:96 | &... | This hard-coded value is used as $@. | test_age.rs:44:40:44:96 | &... | a password | +| test_camellia.rs:6:34:6:43 | [0_u8; 16] | test_camellia.rs:6:34:6:43 | [0_u8; 16] | test_camellia.rs:8:35:8:38 | &key | This hard-coded value is used as $@. | test_camellia.rs:8:35:8:38 | &key | a key | +| test_orion.rs:4:21:4:27 | [3; 32] | test_orion.rs:4:21:4:27 | [3; 32] | test_orion.rs:5:49:5:58 | &key_bytes | This hard-coded value is used as $@. | test_orion.rs:5:49:5:58 | &key_bytes | a key | +| test_orion.rs:13:43:13:77 | b"Hardcoded insecure secret!!!... | test_orion.rs:13:43:13:77 | b"Hardcoded insecure secret!!!... | test_orion.rs:13:43:13:77 | b"Hardcoded insecure secret!!!... | This hard-coded value is used as $@. | test_orion.rs:13:43:13:77 | b"Hardcoded insecure secret!!!... | a key | +| test_orion.rs:26:49:26:58 | b"hunter2" | test_orion.rs:26:49:26:58 | b"hunter2" | test_orion.rs:26:49:26:58 | b"hunter2" | This hard-coded value is used as $@. | test_orion.rs:26:49:26:58 | b"hunter2" | a password | +| test_rand.rs:17:15:17:23 | [7u8; 32] | test_rand.rs:17:15:17:23 | [7u8; 32] | test_rand.rs:20:43:20:46 | &key | This hard-coded value is used as $@. | test_rand.rs:20:43:20:46 | &key | a key | +| test_rand.rs:24:15:24:23 | [7u8; 32] | test_rand.rs:24:15:24:23 | [7u8; 32] | test_rand.rs:27:43:27:46 | &key | This hard-coded value is used as $@. | test_rand.rs:27:43:27:46 | &key | a key | +| test_rand.rs:37:15:37:23 | [7u8; 32] | test_rand.rs:37:15:37:23 | [7u8; 32] | test_rand.rs:40:43:40:46 | &key | This hard-coded value is used as $@. | test_rand.rs:40:43:40:46 | &key | a key | +| test_ring.rs:15:21:15:29 | [7u8; 32] | test_ring.rs:15:21:15:29 | [7u8; 32] | test_ring.rs:16:43:16:52 | &key_bytes | This hard-coded value is used as $@. | test_ring.rs:16:43:16:52 | &key_bytes | a key | +| test_ring.rs:20:49:20:76 | b"shared authentication key" | test_ring.rs:20:49:20:76 | b"shared authentication key" | test_ring.rs:20:49:20:76 | b"shared authentication key" | This hard-coded value is used as $@. | test_ring.rs:20:49:20:76 | b"shared authentication key" | a key | +edges +| test_aes.rs:5:9:5:11 | key | test_aes.rs:7:31:7:33 | key | provenance | | +| test_aes.rs:5:15:5:88 | ...::from(...) | test_aes.rs:5:9:5:11 | key | provenance | | +| test_aes.rs:5:34:5:87 | [...] | test_aes.rs:5:15:5:88 | ...::from(...) | provenance | Config | +| test_aes.rs:7:30:7:33 | &key [&ref] | test_aes.rs:7:30:7:33 | &key | provenance | Sink:MaD:291 | +| test_aes.rs:7:31:7:33 | key | test_aes.rs:7:30:7:33 | &key [&ref] | provenance | | +| test_aes.rs:12:9:12:11 | key | test_aes.rs:14:31:14:33 | key | provenance | | +| test_aes.rs:12:15:12:43 | ...::from(...) | test_aes.rs:12:9:12:11 | key | provenance | | +| test_aes.rs:12:34:12:42 | [4u8; 16] | test_aes.rs:12:15:12:43 | ...::from(...) | provenance | Config | +| test_aes.rs:14:30:14:33 | &key [&ref] | test_aes.rs:14:30:14:33 | &key | provenance | Sink:MaD:291 | +| test_aes.rs:14:31:14:33 | key | test_aes.rs:14:30:14:33 | &key [&ref] | provenance | | +| test_aes.rs:20:9:20:11 | key | test_aes.rs:22:48:22:50 | key | provenance | | +| test_aes.rs:20:15:20:100 | [...] | test_aes.rs:20:9:20:11 | key | provenance | | +| test_aes.rs:22:47:22:50 | &key [&ref] | test_aes.rs:22:47:22:50 | &key | provenance | Sink:MaD:293 | +| test_aes.rs:22:48:22:50 | key | test_aes.rs:22:47:22:50 | &key [&ref] | provenance | | +| test_age.rs:5:30:5:45 | ...: ... | test_age.rs:6:70:6:79 | passphrase | provenance | | +| test_age.rs:6:70:6:79 | passphrase | test_age.rs:6:70:6:90 | passphrase.to_owned() | provenance | MaD:369 | +| test_age.rs:6:70:6:90 | passphrase.to_owned() | test_age.rs:6:58:6:91 | ...::new(...) | provenance | Config | +| test_age.rs:14:33:14:48 | ...: ... | test_age.rs:20:53:20:62 | passphrase | provenance | | +| test_age.rs:20:41:20:74 | ...::new(...) | test_age.rs:20:40:20:74 | &... | provenance | | +| test_age.rs:20:53:20:62 | passphrase | test_age.rs:20:53:20:73 | passphrase.to_owned() | provenance | MaD:369 | +| test_age.rs:20:53:20:73 | passphrase.to_owned() | test_age.rs:20:41:20:74 | ...::new(...) | provenance | Config | +| test_age.rs:26:9:26:18 | passphrase | test_age.rs:27:47:27:56 | passphrase | provenance | | +| test_age.rs:26:9:26:18 | passphrase | test_age.rs:28:33:28:42 | passphrase | provenance | | +| test_age.rs:26:22:26:52 | "this is not a good passphrase... | test_age.rs:26:9:26:18 | passphrase | provenance | | +| test_age.rs:27:47:27:56 | passphrase | test_age.rs:5:30:5:45 | ...: ... | provenance | | +| test_age.rs:28:33:28:42 | passphrase | test_age.rs:14:33:14:48 | ...: ... | provenance | | +| test_age.rs:33:70:33:100 | "this is not a good passphrase... | test_age.rs:33:70:33:111 | "this is not a good passphrase....to_owned() | provenance | MaD:369 | +| test_age.rs:33:70:33:111 | "this is not a good passphrase....to_owned() | test_age.rs:33:58:33:112 | ...::new(...) | provenance | Config | +| test_age.rs:44:41:44:96 | ...::new(...) | test_age.rs:44:40:44:96 | &... | provenance | | +| test_age.rs:44:53:44:83 | "this is not a good passphrase... | test_age.rs:44:53:44:95 | "this is not a good passphrase....to_string() | provenance | MaD:364 | +| test_age.rs:44:53:44:95 | "this is not a good passphrase....to_string() | test_age.rs:44:41:44:96 | ...::new(...) | provenance | Config | +| test_camellia.rs:6:9:6:11 | key | test_camellia.rs:8:36:8:38 | key | provenance | | +| test_camellia.rs:6:15:6:44 | ...::from(...) | test_camellia.rs:6:9:6:11 | key | provenance | | +| test_camellia.rs:6:34:6:43 | [0_u8; 16] | test_camellia.rs:6:15:6:44 | ...::from(...) | provenance | Config | +| test_camellia.rs:8:35:8:38 | &key [&ref] | test_camellia.rs:8:35:8:38 | &key | provenance | Sink:MaD:291 | +| test_camellia.rs:8:36:8:38 | key | test_camellia.rs:8:35:8:38 | &key [&ref] | provenance | | +| test_orion.rs:4:9:4:17 | key_bytes | test_orion.rs:5:50:5:58 | key_bytes | provenance | | +| test_orion.rs:4:21:4:27 | [3; 32] | test_orion.rs:4:9:4:17 | key_bytes | provenance | | +| test_orion.rs:5:50:5:58 | key_bytes | test_orion.rs:5:49:5:58 | &key_bytes | provenance | | +| test_rand.rs:17:9:17:11 | key | test_rand.rs:20:44:20:46 | key | provenance | | +| test_rand.rs:17:15:17:23 | [7u8; 32] | test_rand.rs:17:9:17:11 | key | provenance | | +| test_rand.rs:20:44:20:46 | key | test_rand.rs:20:43:20:46 | &key | provenance | | +| test_rand.rs:24:9:24:11 | key | test_rand.rs:27:44:27:46 | key | provenance | | +| test_rand.rs:24:15:24:23 | [7u8; 32] | test_rand.rs:24:9:24:11 | key | provenance | | +| test_rand.rs:27:44:27:46 | key | test_rand.rs:27:43:27:46 | &key | provenance | | +| test_rand.rs:37:9:37:11 | key | test_rand.rs:40:44:40:46 | key | provenance | | +| test_rand.rs:37:15:37:23 | [7u8; 32] | test_rand.rs:37:9:37:11 | key | provenance | | +| test_rand.rs:40:44:40:46 | key | test_rand.rs:40:43:40:46 | &key | provenance | | +| test_ring.rs:15:9:15:17 | key_bytes | test_ring.rs:16:44:16:52 | key_bytes | provenance | | +| test_ring.rs:15:21:15:29 | [7u8; 32] | test_ring.rs:15:9:15:17 | key_bytes | provenance | | +| test_ring.rs:16:44:16:52 | key_bytes | test_ring.rs:16:43:16:52 | &key_bytes | provenance | | +nodes +| test_aes.rs:5:9:5:11 | key | semmle.label | key | +| test_aes.rs:5:15:5:88 | ...::from(...) | semmle.label | ...::from(...) | +| test_aes.rs:5:34:5:87 | [...] | semmle.label | [...] | +| test_aes.rs:7:30:7:33 | &key | semmle.label | &key | +| test_aes.rs:7:30:7:33 | &key [&ref] | semmle.label | &key [&ref] | +| test_aes.rs:7:31:7:33 | key | semmle.label | key | +| test_aes.rs:12:9:12:11 | key | semmle.label | key | +| test_aes.rs:12:15:12:43 | ...::from(...) | semmle.label | ...::from(...) | +| test_aes.rs:12:34:12:42 | [4u8; 16] | semmle.label | [4u8; 16] | +| test_aes.rs:14:30:14:33 | &key | semmle.label | &key | +| test_aes.rs:14:30:14:33 | &key [&ref] | semmle.label | &key [&ref] | +| test_aes.rs:14:31:14:33 | key | semmle.label | key | +| test_aes.rs:20:9:20:11 | key | semmle.label | key | +| test_aes.rs:20:15:20:100 | [...] | semmle.label | [...] | +| test_aes.rs:22:47:22:50 | &key | semmle.label | &key | +| test_aes.rs:22:47:22:50 | &key [&ref] | semmle.label | &key [&ref] | +| test_aes.rs:22:48:22:50 | key | semmle.label | key | +| test_age.rs:5:30:5:45 | ...: ... | semmle.label | ...: ... | +| test_age.rs:6:58:6:91 | ...::new(...) | semmle.label | ...::new(...) | +| test_age.rs:6:70:6:79 | passphrase | semmle.label | passphrase | +| test_age.rs:6:70:6:90 | passphrase.to_owned() | semmle.label | passphrase.to_owned() | +| test_age.rs:14:33:14:48 | ...: ... | semmle.label | ...: ... | +| test_age.rs:20:40:20:74 | &... | semmle.label | &... | +| test_age.rs:20:41:20:74 | ...::new(...) | semmle.label | ...::new(...) | +| test_age.rs:20:53:20:62 | passphrase | semmle.label | passphrase | +| test_age.rs:20:53:20:73 | passphrase.to_owned() | semmle.label | passphrase.to_owned() | +| test_age.rs:26:9:26:18 | passphrase | semmle.label | passphrase | +| test_age.rs:26:22:26:52 | "this is not a good passphrase... | semmle.label | "this is not a good passphrase... | +| test_age.rs:27:47:27:56 | passphrase | semmle.label | passphrase | +| test_age.rs:28:33:28:42 | passphrase | semmle.label | passphrase | +| test_age.rs:33:58:33:112 | ...::new(...) | semmle.label | ...::new(...) | +| test_age.rs:33:70:33:100 | "this is not a good passphrase... | semmle.label | "this is not a good passphrase... | +| test_age.rs:33:70:33:111 | "this is not a good passphrase....to_owned() | semmle.label | "this is not a good passphrase....to_owned() | +| test_age.rs:44:40:44:96 | &... | semmle.label | &... | +| test_age.rs:44:41:44:96 | ...::new(...) | semmle.label | ...::new(...) | +| test_age.rs:44:53:44:83 | "this is not a good passphrase... | semmle.label | "this is not a good passphrase... | +| test_age.rs:44:53:44:95 | "this is not a good passphrase....to_string() | semmle.label | "this is not a good passphrase....to_string() | +| test_camellia.rs:6:9:6:11 | key | semmle.label | key | +| test_camellia.rs:6:15:6:44 | ...::from(...) | semmle.label | ...::from(...) | +| test_camellia.rs:6:34:6:43 | [0_u8; 16] | semmle.label | [0_u8; 16] | +| test_camellia.rs:8:35:8:38 | &key | semmle.label | &key | +| test_camellia.rs:8:35:8:38 | &key [&ref] | semmle.label | &key [&ref] | +| test_camellia.rs:8:36:8:38 | key | semmle.label | key | +| test_orion.rs:4:9:4:17 | key_bytes | semmle.label | key_bytes | +| test_orion.rs:4:21:4:27 | [3; 32] | semmle.label | [3; 32] | +| test_orion.rs:5:49:5:58 | &key_bytes | semmle.label | &key_bytes | +| test_orion.rs:5:50:5:58 | key_bytes | semmle.label | key_bytes | +| test_orion.rs:13:43:13:77 | b"Hardcoded insecure secret!!!... | semmle.label | b"Hardcoded insecure secret!!!... | +| test_orion.rs:26:49:26:58 | b"hunter2" | semmle.label | b"hunter2" | +| test_rand.rs:17:9:17:11 | key | semmle.label | key | +| test_rand.rs:17:15:17:23 | [7u8; 32] | semmle.label | [7u8; 32] | +| test_rand.rs:20:43:20:46 | &key | semmle.label | &key | +| test_rand.rs:20:44:20:46 | key | semmle.label | key | +| test_rand.rs:24:9:24:11 | key | semmle.label | key | +| test_rand.rs:24:15:24:23 | [7u8; 32] | semmle.label | [7u8; 32] | +| test_rand.rs:27:43:27:46 | &key | semmle.label | &key | +| test_rand.rs:27:44:27:46 | key | semmle.label | key | +| test_rand.rs:37:9:37:11 | key | semmle.label | key | +| test_rand.rs:37:15:37:23 | [7u8; 32] | semmle.label | [7u8; 32] | +| test_rand.rs:40:43:40:46 | &key | semmle.label | &key | +| test_rand.rs:40:44:40:46 | key | semmle.label | key | +| test_ring.rs:15:9:15:17 | key_bytes | semmle.label | key_bytes | +| test_ring.rs:15:21:15:29 | [7u8; 32] | semmle.label | [7u8; 32] | +| test_ring.rs:16:43:16:52 | &key_bytes | semmle.label | &key_bytes | +| test_ring.rs:16:44:16:52 | key_bytes | semmle.label | key_bytes | +| test_ring.rs:20:49:20:76 | b"shared authentication key" | semmle.label | b"shared authentication key" | +subpaths diff --git a/languages/rust/custom/test/HardcodedCryptographicKey/HardcodedCryptographicKey.qlref b/languages/rust/custom/test/HardcodedCryptographicKey/HardcodedCryptographicKey.qlref new file mode 100644 index 00000000..86fd0e99 --- /dev/null +++ b/languages/rust/custom/test/HardcodedCryptographicKey/HardcodedCryptographicKey.qlref @@ -0,0 +1,2 @@ +query: HardcodedCryptographicKey/HardcodedCryptographicKey.ql +postprocess: utils/test/InlineExpectationsTestQuery.ql diff --git a/languages/rust/custom/test/HardcodedCryptographicKey/options.yml b/languages/rust/custom/test/HardcodedCryptographicKey/options.yml new file mode 100644 index 00000000..f14e61f7 --- /dev/null +++ b/languages/rust/custom/test/HardcodedCryptographicKey/options.yml @@ -0,0 +1,10 @@ +qltest_cargo_check: true +qltest_dependencies: + - aes = { version = "0.8.4" } + - camellia = { version = "0.1.0" } + - orion = { version = "0.17.6" } + - age = { version = "0.9" } + - ring = { version = "0.17.8" } + - hex = { version = "0.4.3" } + - getrandom = { version = "0.2.15" } + - rand = { version = "=0.8.5" } diff --git a/languages/rust/custom/test/HardcodedCryptographicKey/test_aes.rs b/languages/rust/custom/test/HardcodedCryptographicKey/test_aes.rs new file mode 100644 index 00000000..4c756afc --- /dev/null +++ b/languages/rust/custom/test/HardcodedCryptographicKey/test_aes.rs @@ -0,0 +1,37 @@ +use aes::cipher::{generic_array::GenericArray, BlockEncrypt, KeyInit}; +use aes::{Aes128, Aes192}; + +pub fn test_aes_bad_array_literal() { + let key = GenericArray::from([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]); // $ Alert[rust/hardcoded-cryptographic-key] + let mut block = GenericArray::from([42u8; 16]); + let cipher = Aes128::new(&key); // $ Sink + cipher.encrypt_block(&mut block); +} + +pub fn test_aes_bad_array_repeat() { + let key = GenericArray::from([4u8; 16]); // $ Alert[rust/hardcoded-cryptographic-key] + let mut block = GenericArray::from([42u8; 16]); + let cipher = Aes128::new(&key); // $ Sink + cipher.encrypt_block(&mut block); +} + +// already reported by the standard `rust/hard-coded-cryptographic-value` query, so not duplicated here +pub fn test_aes_bad_new_from_slice() { + let key = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]; + let mut block = GenericArray::from([42u8; 16]); + let cipher = match Aes192::new_from_slice(&key) { + Ok(cipher) => cipher, + Err(_) => return, + }; + cipher.encrypt_block(&mut block); +} + +// key loaded from a random source: safe +pub fn test_aes_good() { + let mut key_bytes = [0u8; 16]; + getrandom::getrandom(&mut key_bytes).unwrap(); + let key = GenericArray::from(key_bytes); + let mut block = GenericArray::from([42u8; 16]); + let cipher = Aes128::new(&key); + cipher.encrypt_block(&mut block); +} diff --git a/languages/rust/custom/test/HardcodedCryptographicKey/test_age.rs b/languages/rust/custom/test/HardcodedCryptographicKey/test_age.rs new file mode 100644 index 00000000..8fbbeaf1 --- /dev/null +++ b/languages/rust/custom/test/HardcodedCryptographicKey/test_age.rs @@ -0,0 +1,54 @@ +use age::secrecy::Secret; +use std::io::{Read, Write}; + +// Passphrase passed in from a hard-coded literal in the caller. +fn encrypt(plaintext: &[u8], passphrase: &str) -> Vec { + let encryptor = age::Encryptor::with_user_passphrase(Secret::new(passphrase.to_owned())); // $ Sink + let mut encrypted = vec![]; + let mut writer = encryptor.wrap_output(&mut encrypted).unwrap(); + writer.write_all(plaintext).unwrap(); + writer.finish().unwrap(); + encrypted +} + +fn decrypt(ciphertext: Vec, passphrase: &str) -> Vec { + let decryptor = match age::Decryptor::new(&ciphertext[..]).unwrap() { + age::Decryptor::Passphrase(d) => d, + _ => unreachable!(), + }; + let mut decrypted = vec![]; + let mut reader = decryptor.decrypt(&Secret::new(passphrase.to_owned()), None).unwrap(); // $ Sink + reader.read_to_end(&mut decrypted).unwrap(); + decrypted +} + +pub fn test_age_bad_indirect() { + let passphrase = "this is not a good passphrase"; // $ Alert[rust/hardcoded-cryptographic-key] + let ciphertext = encrypt(b"Hello world!", passphrase); + let _ = decrypt(ciphertext, passphrase); +} + +// Passphrase in-lined at the call site. +pub fn test_age_bad_inline(plaintext: &[u8]) -> Vec { + let encryptor = age::Encryptor::with_user_passphrase(Secret::new("this is not a good passphrase".to_owned())); // $ Alert[rust/hardcoded-cryptographic-key] + let mut encrypted = vec![]; + let mut writer = encryptor.wrap_output(&mut encrypted).unwrap(); + writer.write_all(plaintext).unwrap(); + writer.finish().unwrap(); + + let decryptor = match age::Decryptor::new(&encrypted[..]).unwrap() { + age::Decryptor::Passphrase(d) => d, + _ => unreachable!(), + }; + let mut decrypted = vec![]; + let mut reader = decryptor.decrypt(&Secret::new("this is not a good passphrase".to_string()), None).unwrap(); // $ Alert[rust/hardcoded-cryptographic-key] + reader.read_to_end(&mut decrypted).unwrap(); + decrypted +} + +// Passphrase loaded at runtime: safe. +pub fn test_age_good() { + let passphrase = std::env::var("AGE_PASSPHRASE").unwrap(); + let ciphertext = encrypt(b"Hello world!", &passphrase); + let _ = decrypt(ciphertext, &passphrase); +} diff --git a/languages/rust/custom/test/HardcodedCryptographicKey/test_camellia.rs b/languages/rust/custom/test/HardcodedCryptographicKey/test_camellia.rs new file mode 100644 index 00000000..abe1f111 --- /dev/null +++ b/languages/rust/custom/test/HardcodedCryptographicKey/test_camellia.rs @@ -0,0 +1,10 @@ +use camellia::cipher::generic_array::GenericArray; +use camellia::cipher::{BlockEncrypt, KeyInit}; +use camellia::Camellia128; + +pub fn test_camellia_bad() { + let key = GenericArray::from([0_u8; 16]); // $ Alert[rust/hardcoded-cryptographic-key] + let mut block = GenericArray::from(['a' as u8; 16]); + let cipher = Camellia128::new(&key); // $ Sink + cipher.encrypt_block(&mut block); +} diff --git a/languages/rust/custom/test/HardcodedCryptographicKey/test_orion.rs b/languages/rust/custom/test/HardcodedCryptographicKey/test_orion.rs new file mode 100644 index 00000000..c763ea8d --- /dev/null +++ b/languages/rust/custom/test/HardcodedCryptographicKey/test_orion.rs @@ -0,0 +1,28 @@ +use orion::{aead, auth, pwhash}; + +pub fn test_orion_aead_bad() { + let key_bytes = [3; 32]; // $ Alert[rust/hardcoded-cryptographic-key] + let key = match aead::SecretKey::from_slice(&key_bytes) { // $ Sink + Ok(key) => key, + Err(_) => return, + }; + let _ = aead::seal(&key, b"Some secret information"); +} + +pub fn test_orion_auth_bad() { + let key = auth::SecretKey::from_slice(b"Hardcoded insecure secret!!!!!!!").unwrap(); // $ Alert[rust/hardcoded-cryptographic-key] + let msg = "Some message.".as_bytes(); + let _ = auth::authenticate(&key, msg); +} + +// randomly generated key: safe +pub fn test_orion_auth_good() { + let key = auth::SecretKey::default(); + let msg = "Some message.".as_bytes(); + let _ = auth::authenticate(&key, msg); +} + +pub fn test_orion_pwhash_bad() { + let password = pwhash::Password::from_slice(b"hunter2").unwrap(); // $ Alert[rust/hardcoded-cryptographic-key] + let _ = pwhash::hash_password(&password, 3, 1 << 16); +} diff --git a/languages/rust/custom/test/HardcodedCryptographicKey/test_rand.rs b/languages/rust/custom/test/HardcodedCryptographicKey/test_rand.rs new file mode 100644 index 00000000..fce88898 --- /dev/null +++ b/languages/rust/custom/test/HardcodedCryptographicKey/test_rand.rs @@ -0,0 +1,41 @@ +use rand::{rngs::OsRng, RngCore}; +use ring::aead::{UnboundKey, AES_256_GCM}; + +pub fn test_os_rng_overwrites_constant() { + let mut key = [0u8; 32]; + OsRng.fill_bytes(&mut key); + let _ = UnboundKey::new(&AES_256_GCM, &key); +} + +pub fn test_thread_rng_overwrites_constant() { + let mut key = [0u8; 32]; + rand::thread_rng().fill_bytes(&mut key); + let _ = UnboundKey::new(&AES_256_GCM, &key); +} + +pub fn test_os_rng_does_not_overwrite_key() { + let key = [7u8; 32]; // $ Alert[rust/hardcoded-cryptographic-key] + let mut request_id = [0u8; 32]; + OsRng.fill_bytes(&mut request_id); + let _ = UnboundKey::new(&AES_256_GCM, &key); // $ Sink +} + +pub fn test_thread_rng_does_not_overwrite_key() { + let key = [7u8; 32]; // $ Alert[rust/hardcoded-cryptographic-key] + let mut request_id = [0u8; 32]; + rand::thread_rng().fill_bytes(&mut request_id); + let _ = UnboundKey::new(&AES_256_GCM, &key); // $ Sink +} + +pub fn test_os_rng_try_overwrites_constant() { + let mut key = [0u8; 32]; + OsRng.try_fill_bytes(&mut key).unwrap(); + let _ = UnboundKey::new(&AES_256_GCM, &key); +} + +pub fn test_thread_rng_try_does_not_overwrite_key() { + let key = [7u8; 32]; // $ Alert[rust/hardcoded-cryptographic-key] + let mut request_id = [0u8; 32]; + rand::thread_rng().try_fill_bytes(&mut request_id).unwrap(); + let _ = UnboundKey::new(&AES_256_GCM, &key); // $ Sink +} diff --git a/languages/rust/custom/test/HardcodedCryptographicKey/test_ring.rs b/languages/rust/custom/test/HardcodedCryptographicKey/test_ring.rs new file mode 100644 index 00000000..eda5f4fe --- /dev/null +++ b/languages/rust/custom/test/HardcodedCryptographicKey/test_ring.rs @@ -0,0 +1,27 @@ +use ring::aead::{UnboundKey, AES_256_GCM}; +use ring::hmac; +use ring::rand::{SecureRandom, SystemRandom}; + +// key buffer is overwritten with random bytes before use: safe +pub fn test_ring_good() { + let rand = SystemRandom::new(); + // initialized with a constant, then overwritten with random bytes + let mut key_bytes = vec![0; AES_256_GCM.key_len()]; + rand.fill(&mut key_bytes).unwrap(); + let _ = UnboundKey::new(&AES_256_GCM, &key_bytes); +} + +pub fn test_ring_bad() { + let key_bytes = [7u8; 32]; // $ Alert[rust/hardcoded-cryptographic-key] + let _ = UnboundKey::new(&AES_256_GCM, &key_bytes); // $ Sink +} + +pub fn test_ring_hmac_bad(msg: &[u8]) -> hmac::Tag { + let key = hmac::Key::new(hmac::HMAC_SHA256, b"shared authentication key"); // $ Alert[rust/hardcoded-cryptographic-key] + hmac::sign(&key, msg) +} + +pub fn test_ring_hmac_good(key_value: &[u8], msg: &[u8]) -> hmac::Tag { + let key = hmac::Key::new(hmac::HMAC_SHA256, key_value); + hmac::sign(&key, msg) +} diff --git a/languages/rust/custom/test/qlpack.yml b/languages/rust/custom/test/qlpack.yml new file mode 100644 index 00000000..a88924cb --- /dev/null +++ b/languages/rust/custom/test/qlpack.yml @@ -0,0 +1,5 @@ +name: languages-rust-custom-test +version: 0.0.2 +dependencies: + languages-rust-custom-src: ${workspace} +extractor: rust diff --git a/languages/rust/example/.gitkeep b/languages/rust/example/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/scripts/install-codeql-packs.sh b/scripts/install-codeql-packs.sh index 03481a93..40ea78c9 100755 --- a/scripts/install-codeql-packs.sh +++ b/scripts/install-codeql-packs.sh @@ -13,7 +13,7 @@ Install CodeQL packs for all packs discovered in the CodeQL workspace. OPTIONS: --language Install packs only for the specified language Valid values: actions, cpp, csharp, go, java, javascript, - python, ruby + python, ruby, rust -h, --help Show this help message By default, the script installs packs for all languages in the workspace. @@ -44,7 +44,7 @@ while [[ $# -gt 0 ]]; do done ## Validate language if provided -VALID_LANGUAGES=("actions" "cpp" "csharp" "go" "java" "javascript" "python" "ruby") +VALID_LANGUAGES=("actions" "cpp" "csharp" "go" "java" "javascript" "python" "ruby" "rust") if [[ -n "${LANGUAGE}" ]]; then LANGUAGE_VALID=false for valid_lang in "${VALID_LANGUAGES[@]}"; do