authenticate_password

Function authenticate_password 

Source
pub async fn authenticate_password(
    socket: &mut ControlSocket,
    password: &str,
) -> Result<(), Error>
Expand description

Authenticates using a password.

Sends an AUTHENTICATE command with the password hex-encoded. The password must match the hash configured in Tor’s HashedControlPassword torrc option.

§Preconditions

  • The socket must be connected
  • Tor must be configured with HashedControlPassword
  • The password must match the configured hash

§Postconditions

  • On success: The socket is authenticated
  • On failure: Tor may disconnect the socket

§Arguments

  • socket - A connected control socket
  • password - The plaintext password to authenticate with

§Errors

Returns Error::Authentication with AuthError::IncorrectPassword if the password doesn’t match the configured hash.

§Security Considerations

  • The password is hex-encoded but transmitted in cleartext over the socket
  • For TCP connections, consider using a secure tunnel or localhost only
  • Unix domain sockets provide better security for local connections
  • The password is not stored after the function returns

§Example

use stem_rs::auth::authenticate_password;
use stem_rs::ControlSocket;

let mut socket = ControlSocket::connect_port("127.0.0.1:9051".parse()?).await?;
authenticate_password(&mut socket, "my_secure_password").await?;

§Protocol Details

The password is hex-encoded before sending:

AUTHENTICATE 6D795F7061737377 (hex of "my_passw")