pub enum AuthMethod {
None,
Password,
Cookie,
SafeCookie,
}Expand description
Authentication methods supported by Tor’s control protocol.
These methods are reported by Tor in response to a PROTOCOLINFO query.
The authenticate function tries methods in order of security preference:
NONE → SAFECOOKIE → COOKIE → PASSWORD.
§Security Comparison
| Method | Security Level | Use Case |
|---|---|---|
None | Lowest | Testing only, never in production |
Password | Medium | Remote access with strong password |
Cookie | High | Local access, older Tor versions |
SafeCookie | Highest | Local access, Tor 0.2.3+ |
§Example
use stem_rs::auth::AuthMethod;
let methods = vec![AuthMethod::Cookie, AuthMethod::SafeCookie];
assert!(methods.contains(&AuthMethod::SafeCookie));Variants§
None
No authentication required.
This method is available when Tor’s control port is open without any authentication configured. This is insecure and should only be used for testing or when the control port is bound to localhost and the system is trusted.
Corresponds to NULL in the PROTOCOLINFO response.
Password
Password authentication using HashedControlPassword.
Requires a password that matches the hash configured in Tor’s
HashedControlPassword torrc option. The password is hex-encoded
before transmission.
Corresponds to HASHEDPASSWORD in the PROTOCOLINFO response.
Cookie
Cookie file authentication using CookieAuthentication.
Authenticates by presenting the contents of Tor’s authentication cookie file (typically 32 bytes). The cookie path is provided in the PROTOCOLINFO response.
Corresponds to COOKIE in the PROTOCOLINFO response.
SafeCookie
HMAC challenge-response authentication (Tor 0.2.3+).
A more secure variant of cookie authentication that uses HMAC-SHA256 challenge-response to prevent replay attacks. The client sends a random nonce, receives a server nonce and hash, verifies the server’s response, then sends its own hash.
Corresponds to SAFECOOKIE in the PROTOCOLINFO response.
Implementations§
Source§impl AuthMethod
impl AuthMethod
Sourcepub fn parse(s: &str) -> Option<Self>
pub fn parse(s: &str) -> Option<Self>
Parses an authentication method from its PROTOCOLINFO string representation.
§Arguments
s- The method string from PROTOCOLINFO (case-insensitive)
§Returns
Some(AuthMethod) if recognized, None for unknown methods.
§Examples
use stem_rs::auth::AuthMethod;
assert_eq!(AuthMethod::parse("NULL"), Some(AuthMethod::None));
assert_eq!(AuthMethod::parse("HASHEDPASSWORD"), Some(AuthMethod::Password));
assert_eq!(AuthMethod::parse("cookie"), Some(AuthMethod::Cookie));
assert_eq!(AuthMethod::parse("UNKNOWN"), None);Trait Implementations§
Source§impl Clone for AuthMethod
impl Clone for AuthMethod
Source§fn clone(&self) -> AuthMethod
fn clone(&self) -> AuthMethod
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more