diff --git a/onionshare/helpers.py b/onionshare/helpers.py index c6d29f0b..ae58488a 100644 --- a/onionshare/helpers.py +++ b/onionshare/helpers.py @@ -18,6 +18,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . """ import sys, os, inspect, hashlib, base64, hmac, platform, zipfile, tempfile, math, time +from random import SystemRandom def get_platform(): @@ -26,6 +27,7 @@ def get_platform(): """ return platform.system() + def get_resource_path(filename): """ Returns the absolute path of a resource, regardless of whether OnionShare is installed @@ -49,6 +51,7 @@ def get_resource_path(filename): return os.path.join(resources_dir, filename) + def get_version(): """ Returns the version of OnionShare that is running. @@ -88,6 +91,17 @@ def random_string(num_bytes, output_len=None): return s[:output_len] +def build_slug(): + """ + Returns a random string made from two words from the wordlist, such as "deter-trig". + """ + wordlist = open(get_resource_path('wordlist.txt')).read().split('\n') + wordlist.remove('') + + r = SystemRandom() + return '-'.join(r.choice(wordlist) for x in range(2)) + + def human_readable_filesize(b): """ Returns filesize in a human readable format. diff --git a/onionshare/onionshare.py b/onionshare/onionshare.py index 34e64b05..0ccf394e 100644 --- a/onionshare/onionshare.py +++ b/onionshare/onionshare.py @@ -169,6 +169,9 @@ def main(cwd=None): ready = app.hs.wait_for_hs(app.onion_host) if not ready: sys.exit() + else: + # Wait for web.generate_slug() to finish running + time.sleep(0.2) print(strings._("give_this_url")) print('http://{0:s}/{1:s}'.format(app.onion_host, web.slug)) diff --git a/onionshare/web.py b/onionshare/web.py index e1f8050d..ebff67b2 100644 --- a/onionshare/web.py +++ b/onionshare/web.py @@ -92,7 +92,7 @@ def add_request(request_type, path, data=None): slug = None def generate_slug(): global slug - slug = helpers.random_string(16) + slug = helpers.build_slug() download_count = 0