Expand description
AUTHCHALLENGE response parsing.
This module parses responses from the AUTHCHALLENGE command, which is used
during SAFECOOKIE authentication. SAFECOOKIE is the most secure authentication
method for local Tor connections, using HMAC-SHA256 challenge-response.
§Protocol Overview
SAFECOOKIE authentication works as follows:
- Client sends
AUTHCHALLENGE SAFECOOKIE <client_nonce> - Server responds with
SERVERHASHandSERVERNONCE - Client computes
HMAC-SHA256(cookie || client_nonce || server_nonce) - Client sends
AUTHENTICATE <computed_hash>
§Response Format
250 AUTHCHALLENGE SERVERHASH=<64_hex_chars> SERVERNONCE=<64_hex_chars>Both values are 32-byte (256-bit) values encoded as 64 hexadecimal characters.
§Example
use stem_rs::response::{ControlMessage, AuthChallengeResponse};
let response_text = "250 AUTHCHALLENGE \
SERVERHASH=680A73C9836C4F557314EA1C4EDE54C285DB9DC89C83627401AEF9D7D27A95D5 \
SERVERNONCE=F8EA4B1F2C8B40EF1AF68860171605B910E3BBCABADF6FC3DB1FA064F4690E85\r\n";
let msg = ControlMessage::from_str(response_text, None, false).unwrap();
let response = AuthChallengeResponse::from_message(&msg).unwrap();
assert_eq!(response.server_hash.len(), 32);
assert_eq!(response.server_nonce.len(), 32);§Security Considerations
- The server hash proves the server knows the cookie file contents
- The server nonce prevents replay attacks
- Both values should be used exactly once per authentication attempt
- Failed authentication should trigger a new challenge with fresh nonces
§See Also
crate::auth::authenticate_safecookie: High-level SAFECOOKIE authenticationcrate::response::ProtocolInfoResponse: Determines available auth methods- Tor Control Protocol: AUTHCHALLENGE
Structs§
- Auth
Challenge Response - Parsed response from the AUTHCHALLENGE command.