Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a more conservative way to generate tracker keys? #977

Open
josecelano opened this issue Jul 30, 2024 · 0 comments
Open

Use a more conservative way to generate tracker keys? #977

josecelano opened this issue Jul 30, 2024 · 0 comments
Labels
Question / Discussion Community Feedback Security Publicly Connected to Security

Comments

@josecelano
Copy link
Member

We are using this function to generate random keys:

use rand::distributions::Alphanumeric;
use rand::{thread_rng, Rng};

pub fn generate(lifetime: Duration) -> ExpiringKey {
    let random_id: String = thread_rng()
        .sample_iter(&Alphanumeric)
        .take(AUTH_KEY_LENGTH)
        .map(char::from)
        .collect();

    ExpiringKey {
        key: random_id.parse::<Key>().unwrap(),
        valid_until: CurrentClock::now_add(&lifetime).unwrap(),
    }
}

In rand docs they say:

/// # Passwords
///
/// Users sometimes ask whether it is safe to use a string of random characters
/// as a password. In principle, all RNGs in Rand implementing `CryptoRng` are
/// suitable as a source of randomness for generating passwords (if they are
/// properly seeded), but it is more conservative to only use randomness
/// directly from the operating system via the `getrandom` crate, or the
/// corresponding bindings of a crypto library.
///
/// When generating passwords or keys, it is important to consider the threat
/// model and in some cases the memorability of the password. This is out of
/// scope of the Rand project, and therefore we defer to the following
/// references:
///
/// - [Wikipedia article on Password Strength](https://en.wikipedia.org/wiki/Password_strength)
/// - [Diceware for generating memorable passwords](https://en.wikipedia.org/wiki/Diceware)

It seems thread_rng implements CryptoRng, so it should be safe to use it.

See: https://rust-random.github.io/rand/src/rand/rngs/thread.rs.html#171

Should we use the getrandom crate as suggested by the rand crate?

cc @da2ce7

@josecelano josecelano added Security Publicly Connected to Security Question / Discussion Community Feedback labels Jul 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question / Discussion Community Feedback Security Publicly Connected to Security
Projects
None yet
Development

No branches or pull requests

1 participant