From c250cbeba49f86059a907dbdea74f2be323a1e65 Mon Sep 17 00:00:00 2001 From: The Dod Date: Sat, 11 Oct 2014 07:56:33 +0700 Subject: [PATCH] Prompt for tor controller password if needed We use getpass for this (i.e. text mode). This means that if you have password protection for your Tor controller (advised) and you want to run onionshare-gui, you need to do it from a terminal (so that you can enter the password). --- onionshare/onionshare.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/onionshare/onionshare.py b/onionshare/onionshare.py index 5c0acde9..6c28cea0 100644 --- a/onionshare/onionshare.py +++ b/onionshare/onionshare.py @@ -21,6 +21,7 @@ import os, sys, subprocess, time, argparse, inspect, shutil, socket, threading, import socks from stem.control import Controller +from stem.connection import MissingPassword, AuthenticationFailure from stem import SocketError import strings, helpers, web @@ -101,7 +102,17 @@ class OnionShare(object): pass if not controller: raise NoTor(strings._("cant_connect_ctrlport").format(tor_control_ports)) - controller.authenticate() + try: + controller.authenticate() + except MissingPassword: # We need a password for control port + from getpass import getpass + authed = False + while not authed: + try: + controller.authenticate(getpass('Tor control password: ')) + authed = True + except AuthenticationFailure: + pass # set up hidden service controller.set_options([