Skip to content

Automatically create hidden service, listen on Tor #6586

@laanwj

Description

@laanwj

Starting with Tor version 0.2.7.1 it is possible, through Tor's control socket API, to create and destroy 'ephemeral' hidden services programmatically.
https://stem.torproject.org/api/control.html#stem.control.Controller.create_ephemeral_hidden_service

This means that if Tor is running (and proper authorization is available), bitcoin could automatically create a hidden service to listen on, without user manual configuration. That would positively affect the number of available .onion nodes.

This would involve the following, if enabled:

  • When the node is started, connect to Tor through control socket
  • Send create_ephemeral_hidden_service command
  • First time:
    • Make it create a hidden service key
    • Save the key in the data directory for later usage (optional: Could also use a new key every time. Better for privacy, less so for having stable identifiers, so this should be configurable)
  • Make it redirect port 8333 to the local port 8333 (or whatever port we're listening on). E.g.
response = controller.create_ephemeral_hidden_service({8333: 8333}, key_type='NEW', key_content='BEST', await_publication = True)
# Advertize <response.service_id>.onion
# Optionally save response.private_key, response.private_key_type
  • Keep control socket connection open for as long node is running. The hidden service will (by default) automatically go away when the connection is closed.

Challenges:

  • Except for experimentation we probably don't want to rely on a Python script. This means the create_ephemeral_hidden_service STEM interface has to be implemented in C++. Internal command is ADD_ONION, see https://gitweb.torproject.org/torspec.git/commit/?id=f5ff369 for the appropriate addition to torspec.

Edit: the controller.create_ephemeral_hidden_service will take a while (I suppose the reason is that it needs to generate a key) - maybe execute it in a thread and not in the main initialization.
Edit.2: FYI the part that takes significant time is not the key generation, but waiting for publication await_publication = True.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions