Module auth

Source
Expand description

Tracker authentication services and structs.

This module contains functions to handle tracker keys. Tracker keys are tokens used to authenticate the tracker clients when the tracker runs in private or private_listed modes.

There are services to generate_key and verify_key_expiration authentication keys.

Authentication keys are used only by HTTP trackers. All keys have an expiration time, that means they are only valid during a period of time. After that time the expiring key will no longer be valid.

Keys are stored in this struct:

use torrust_tracker::core::auth::Key;
use torrust_tracker_primitives::DurationSinceUnixEpoch;

pub struct ExpiringKey {
    /// Random 32-char string. For example: `YZSl4lMZupRuOpSRC3krIKR5BPB14nrJ`
    pub key: Key,
    /// Timestamp, the key will be no longer valid after this timestamp
    pub valid_until: Option<DurationSinceUnixEpoch>,
}

You can generate a new key valid for 9999 seconds and 0 nanoseconds from the current time with the following:

use torrust_tracker::core::auth;
use std::time::Duration;

let expiring_key = auth::generate_key(Some(Duration::new(9999, 0)));

// And you can later verify it with:

assert!(auth::verify_key_expiration(&expiring_key).is_ok());

Structs§

Key
A token used for authentication.
PeerKey
An authentication key which can potentially have an expiration time. After that time is will automatically become invalid.

Enums§

Error
Verification error. Error returned when an PeerKey cannot be verified with the (crate::core::auth::verify_key) function.
ParseKeyError
Error returned when a key cannot be parsed from a string.

Functions§

generate_key
It generates a new random 32-char authentication PeerKey.
generate_permanent_key
It generates a new permanent random key PeerKey.
verify_key_expiration
It verifies an PeerKey. It checks if the expiration date has passed. Permanent keys without duration (None) do not expire.