Project_Detail
All_Projects

TorPlusPlus

Bine but C++

View on GitHub
README.md

Tor++

Tor++ is a C++20 library for controlling Tor with a bine-style workflow:

  • start and stop a Tor process
  • authenticate on the control port
  • send raw Tor control commands
  • manage config and info queries
  • create and delete ephemeral onion services
  • persist and restore hidden-service identities
  • open outbound connections through Tor's SOCKS5 listener

This first cut targets Linux/POSIX systems and keeps the public API close to the practical features bine exposes while still providing a raw control-command escape hatch for the rest of Tor's controller surface.

Features

  • torpp::Tor::start(...) launches Tor, discovers the control port, and authenticates
  • torpp::ControlClient exposes PROTOCOLINFO, GETINFO, GETCONF, SETCONF, SAVECONF, SIGNAL, ADD_ONION, DEL_ONION, SETEVENTS, and generic raw commands
  • torpp::OnionService wraps ephemeral v3 onion services
  • torpp::HiddenServiceIdentity saves and reloads the private key blob Tor returns from ADD_ONION
  • torpp::Dialer opens outbound sockets through Tor's SOCKS5 proxy

Build

cmake -S . -B build
cmake --build build
ctest --test-dir build

Tor++ uses OpenSSL's crypto library for SAFECOOKIE authentication and HMAC handling.

Example

#include <torpp/tor.hpp>

#include <iostream>

int main() {
    torpp::Tor tor = torpp::Tor::start({});

    torpp::OnionServiceConfig config;
    config.port_mappings.push_back({80, "127.0.0.1:8080"});
    config.wait_for_publication = false;

    torpp::OnionService onion = tor.create_onion_service(config);
    onion.save_identity("service.key");

    std::cout << onion.address() << '\n';
}

See examples/basic_onion.cpp for a fuller sample.