summaryrefslogtreecommitdiff
path: root/onionshare
diff options
context:
space:
mode:
authorMiguel Jacq <mig@mig5.net>2018-01-14 20:24:02 +1100
committerMiguel Jacq <mig@mig5.net>2018-01-14 20:24:02 +1100
commitd9e6650a19f252061ea6b6b2bf6ed34fb43b27a8 (patch)
tree4521e86006f0055cbfc04cfe74e6683d5f90d4ef /onionshare
parent2e5b9b37a9c0a3d57659bb229fdc839b77fca442 (diff)
parenta75faea407f206fb5c591003eeaba98682b254dc (diff)
downloadonionshare-d9e6650a19f252061ea6b6b2bf6ed34fb43b27a8.tar.gz
onionshare-d9e6650a19f252061ea6b6b2bf6ed34fb43b27a8.zip
Merge branch 'master' into check_is_valid_file
Diffstat (limited to 'onionshare')
-rw-r--r--onionshare/common.py2
-rw-r--r--onionshare/onion.py61
2 files changed, 40 insertions, 23 deletions
diff --git a/onionshare/common.py b/onionshare/common.py
index 6916f886..562c71f2 100644
--- a/onionshare/common.py
+++ b/onionshare/common.py
@@ -104,7 +104,7 @@ def get_tor_paths():
tor_path = os.path.join(base_path, 'Resources', 'Tor', 'tor')
tor_geo_ip_file_path = os.path.join(base_path, 'Resources', 'Tor', 'geoip')
tor_geo_ipv6_file_path = os.path.join(base_path, 'Resources', 'Tor', 'geoip6')
- elif p == 'OpenBSD':
+ elif p == 'OpenBSD' or p == 'FreeBSD':
tor_path = '/usr/local/bin/tor'
tor_geo_ip_file_path = '/usr/local/share/tor/geoip'
tor_geo_ipv6_file_path = '/usr/local/share/tor/geoip6'
diff --git a/onionshare/onion.py b/onionshare/onion.py
index 2f79719b..a3aee7a5 100644
--- a/onionshare/onion.py
+++ b/onionshare/onion.py
@@ -254,8 +254,8 @@ class Onion(object):
break
time.sleep(0.2)
- # Timeout after 45 seconds
- if time.time() - start_ts > 45:
+ # Timeout after 90 seconds
+ if time.time() - start_ts > 90:
print("")
self.tor_proc.terminate()
raise BundledTorTimeout(strings._('settings_error_bundled_tor_timeout'))
@@ -375,6 +375,17 @@ class Onion(object):
# ephemeral stealth onion services are not supported
self.supports_stealth = False
+
+ def is_authenticated(self):
+ """
+ Returns True if the Tor connection is still working, or False otherwise.
+ """
+ if self.c is not None:
+ return self.c.is_authenticated()
+ else:
+ return False
+
+
def start_onion_service(self, port):
"""
Start a onion service on port 80, pointing to the given port, and
@@ -406,16 +417,19 @@ class Onion(object):
except ProtocolError:
raise TorErrorProtocolError(strings._('error_tor_protocol_error'))
- self.service_id = res.content()[0][2].split('=')[1]
+ self.service_id = res.service_id
onion_host = self.service_id + '.onion'
if self.stealth:
auth_cookie = res.content()[2][2].split('=')[1].split(':')[1]
self.auth_string = 'HidServAuth {} {}'.format(onion_host, auth_cookie)
- return onion_host
+ if onion_host is not None:
+ return onion_host
+ else:
+ raise TorErrorProtocolError(strings._('error_tor_protocol_error'))
- def cleanup(self):
+ def cleanup(self, stop_tor=True):
"""
Stop onion services that were created earlier. If there's a tor subprocess running, kill it.
"""
@@ -429,25 +443,28 @@ class Onion(object):
pass
self.service_id = None
- # Stop tor process
- if self.tor_proc:
- self.tor_proc.terminate()
- time.sleep(0.2)
- if not self.tor_proc.poll():
- self.tor_proc.kill()
- self.tor_proc = None
+ if stop_tor:
+ # Stop tor process
+ if self.tor_proc:
+ self.tor_proc.terminate()
+ time.sleep(0.2)
+ if not self.tor_proc.poll():
+ try:
+ self.tor_proc.kill()
+ except:
+ pass
+ self.tor_proc = None
- # Reset other Onion settings
- self.connected_to_tor = False
- self.stealth = False
- self.service_id = None
+ # Reset other Onion settings
+ self.connected_to_tor = False
+ self.stealth = False
- try:
- # Delete the temporary tor data directory
- self.tor_data_directory.cleanup()
- except AttributeError:
- # Skip if cleanup was somehow run before connect
- pass
+ try:
+ # Delete the temporary tor data directory
+ self.tor_data_directory.cleanup()
+ except AttributeError:
+ # Skip if cleanup was somehow run before connect
+ pass
def get_tor_socks_port(self):
"""