mirror of
https://github.com/onionshare/onionshare.git
synced 2025-01-10 11:47:27 -03:00
Add support for Tor control port authentication
This commit is contained in:
parent
5ebc745d60
commit
e46c4f510a
2 changed files with 17 additions and 4 deletions
|
@ -20,6 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from stem.control import Controller
|
from stem.control import Controller
|
||||||
from stem import SocketError
|
from stem import SocketError
|
||||||
|
from stem.connection import MissingPassword, UnreadableCookieFile
|
||||||
import os, sys, tempfile, shutil, urllib
|
import os, sys, tempfile, shutil, urllib
|
||||||
|
|
||||||
from . import socks
|
from . import socks
|
||||||
|
@ -54,22 +55,32 @@ class Onion(object):
|
||||||
self.cleanup_filenames = []
|
self.cleanup_filenames = []
|
||||||
self.service_id = None
|
self.service_id = None
|
||||||
|
|
||||||
# connect to the tor controlport
|
# if the TOR_CONTROL_PORT environment variable is set, use that
|
||||||
found_tor = False
|
# otherwise, default to Tor Browser, Tor Messenger, and system tor ports
|
||||||
self.c = None
|
|
||||||
env_port = os.environ.get('TOR_CONTROL_PORT')
|
env_port = os.environ.get('TOR_CONTROL_PORT')
|
||||||
if env_port:
|
if env_port:
|
||||||
ports = [int(env_port)]
|
ports = [int(env_port)]
|
||||||
else:
|
else:
|
||||||
ports = [9151, 9153, 9051]
|
ports = [9151, 9153, 9051]
|
||||||
|
|
||||||
|
# if the TOR_AUTHENTICATION_PASSWORD is set, use that to authenticate
|
||||||
|
password = os.environ.get('TOR_AUTHENTICATION_PASSWORD')
|
||||||
|
|
||||||
|
# connect to the tor controlport
|
||||||
|
found_tor = False
|
||||||
|
self.c = None
|
||||||
for port in ports:
|
for port in ports:
|
||||||
try:
|
try:
|
||||||
self.c = Controller.from_port(port=port)
|
self.c = Controller.from_port(port=port)
|
||||||
self.c.authenticate()
|
self.c.authenticate(password)
|
||||||
found_tor = True
|
found_tor = True
|
||||||
break
|
break
|
||||||
except SocketError:
|
except SocketError:
|
||||||
pass
|
pass
|
||||||
|
except MissingPassword:
|
||||||
|
raise NoTor(strings._("ctrlport_missing_password").format(str(ports)))
|
||||||
|
except UnreadableCookieFile:
|
||||||
|
raise NoTor(strings._("ctrlport_unreadable_cookie").format(str(ports)))
|
||||||
if not found_tor:
|
if not found_tor:
|
||||||
raise NoTor(strings._("cant_connect_ctrlport").format(str(ports)))
|
raise NoTor(strings._("cant_connect_ctrlport").format(str(ports)))
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
"connecting_ctrlport": "Connecting to Tor control port to set up onion service on port {0:d}.",
|
"connecting_ctrlport": "Connecting to Tor control port to set up onion service on port {0:d}.",
|
||||||
"cant_connect_ctrlport": "Can't connect to Tor control port on port {0:s}. OnionShare requires Tor Browser to be running in the background to work. If you don't have it you can get it from https://www.torproject.org/.",
|
"cant_connect_ctrlport": "Can't connect to Tor control port on port {0:s}. OnionShare requires Tor Browser to be running in the background to work. If you don't have it you can get it from https://www.torproject.org/.",
|
||||||
"cant_connect_socksport": "Can't connect to Tor SOCKS5 server on port {0:s}. OnionShare requires Tor Browser to be running in the background to work. If you don't have it you can get it from https://www.torproject.org/.",
|
"cant_connect_socksport": "Can't connect to Tor SOCKS5 server on port {0:s}. OnionShare requires Tor Browser to be running in the background to work. If you don't have it you can get it from https://www.torproject.org/.",
|
||||||
|
"ctrlport_missing_password": "Connected to Tor control port on port {0:s}, but you require a password. You must have the TOR_AUTHENTICATION_PASSWORD environment variable set. Or just open Tor Browser in the background.",
|
||||||
|
"ctrlport_unreadable_cookie": "Connected to Tor control port on port {0:s}, but your user does not have permission to authenticate. You might want to add a HashedControlPassword to your torrc, and set the TOR_AUTHENTICATION_PASSWORD environment variable. Or just open Tor Browser in the background.",
|
||||||
"preparing_files": "Preparing files to share.",
|
"preparing_files": "Preparing files to share.",
|
||||||
"wait_for_hs": "Waiting for HS to be ready:",
|
"wait_for_hs": "Waiting for HS to be ready:",
|
||||||
"wait_for_hs_trying": "Trying...",
|
"wait_for_hs_trying": "Trying...",
|
||||||
|
|
Loading…
Reference in a new issue