#tor #api-client #service #lib #server-api #authenticate

bin+lib tor-client-lib

A client library for the Tor API

6 releases

0.2.1 Feb 19, 2024
0.2.0 Feb 15, 2024
0.1.3 Feb 14, 2024
0.1.1 Jan 26, 2024

#681 in Cryptography

Download history 13/week @ 2024-01-22 171/week @ 2024-02-12 141/week @ 2024-02-19 29/week @ 2024-02-26 7/week @ 2024-03-04 21/week @ 2024-03-11 15/week @ 2024-03-18 91/week @ 2024-04-01

128 downloads per month
Used in voynich

MIT/Apache

72KB
1.5K SLoC

Tor Client Library

This is a client library for Tor, which allows you to interact programmatically with a Tor server, using its API.

Crates.io Docs Badge License License GitHub Actions Workflow Status

Installation

To add it to your existing project:

cargo add tor_client_lib

Commands Supported

This library currently supports a small (but useful) subset of the full API, namely:

  • AUTHENTICATE
  • AUTHCHALLENGE
  • GETINFO
  • PROTOCOLINFO
  • ADD_ONION
  • DEL_ONION

If you’d like to see more functions supported, please either submit an issue request or a PR.

Example Code

use tor_client_lib::{
	control_connection::TorControlConnection,
    error::TorError,
    auth::TorAuthentication
};

// Connect to the Tor service running locally
let mut control_connection = TorControlConnection::connect("127.0.0.1:9051").await?;

// Authenticate to the Tor server
control_connection.authenticate(TorAuthentication::SafeCookie(None)).await?;

// Call the "GETINFO" command to get the Tor version number
let tor_version = control_connection.get_info("version").await?;

CLI

The repo includes a simple CLI for sending commands to Tor. To use it, run:

cargo run

For example:

% cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.07s
     Running `target/debug/tor-cli`
Welcome to Tor CLI v0.1.0
Tor CLI> connect
Connected to localhost:9051
Tor CLI> authenticate cookie
Authenticated
Tor CLI> get_info version
["0.4.6.10"]

Dependencies

~18–32MB
~458K SLoC