From b0eb44f82f5e17413a51865abbf29dbd79b4c9cd Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Sat, 8 Apr 2017 17:29:00 -0700 Subject: [PATCH] Wrote script to download pre-built tor binary for Windows --- install/build_exe.bat | 6 ++- install/get-tor-windows.py | 78 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 install/get-tor-windows.py diff --git a/install/build_exe.bat b/install/build_exe.bat index 0763560a..c1b357fa 100644 --- a/install/build_exe.bat +++ b/install/build_exe.bat @@ -1,10 +1,12 @@ -REM delete old build files -rmdir /s /q build +REM delete old dist files rmdir /s /q dist REM build onionshare-gui.exe pyinstaller install\pyinstaller.spec -y +REM download tor +python install\get-tor-windows.py + REM sign onionshare-gui.exe signtool.exe sign /v /d "OnionShare" /a /tr http://timestamp.globalsign.com/scripts/timstamp.dll /fd sha256 dist\onionshare\onionshare-gui.exe diff --git a/install/get-tor-windows.py b/install/get-tor-windows.py new file mode 100644 index 00000000..2c069d4f --- /dev/null +++ b/install/get-tor-windows.py @@ -0,0 +1,78 @@ +# -*- coding: utf-8 -*- +""" +OnionShare | https://onionshare.org/ + +Copyright (C) 2017 Micah Lee + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +""" + +""" +This script downloads a pre-built tor binary to bundle with OnionShare. +In order to avoid a Windows gnupg dependency, I manually verify the signature +and hard-code the sha256 hash. +""" + +import inspect, os, sys, hashlib, zipfile, io, shutil +import urllib.request + +def main(): + zip_url = 'https://www.torproject.org/dist/torbrowser/6.5.1/tor-win32-0.2.9.10.zip' + zip_filename = 'tor-win32-0.2.9.10.zip' + expected_zip_sha256 = '56e639cd73c48f383fd638568e01ca07750211fca79c87e668cf8baccbf9d38a' + + # Build paths + root_path = os.path.dirname(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))) + working_path = os.path.join(os.path.join(root_path, 'build'), 'tor') + zip_path = os.path.join(working_path, zip_filename) + dist_path = os.path.join(os.path.join(os.path.join(root_path, 'dist'), 'onionshare'), 'tor') + + # Make sure the working folder exists + if not os.path.exists(working_path): + os.makedirs(working_path) + + # Make sure the zip is downloaded + if not os.path.exists(zip_path): + print("Downloading {}".format(zip_url)) + response = urllib.request.urlopen(zip_url) + zip_data = response.read() + open(zip_path, 'wb').write(zip_data) + zip_sha256 = hashlib.sha256(zip_data).hexdigest() + else: + zip_data = open(zip_path, 'rb').read() + zip_sha256 = hashlib.sha256(zip_data).hexdigest() + + # Compare the hash + if zip_sha256 != expected_zip_sha256: + print("ERROR! The sha256 doesn't match:") + print("expected: {}".format(expected_zip_sha256)) + print(" actual: {}".format(zip_sha256)) + sys.exit(-1) + + # Extract the zip + z = zipfile.ZipFile(io.BytesIO(zip_data)) + z.extractall(working_path) + + # Delete un-used files + os.remove(os.path.join(os.path.join(working_path, 'Tor'), 'tor-gencert.exe')) + + # Copy into dist + if os.path.exists(dist_path): + shutil.rmtree(dist_path) + os.makedirs(dist_path) + shutil.copytree( os.path.join(working_path, 'Tor'), os.path.join(dist_path, 'Tor') ) + shutil.copytree( os.path.join(working_path, 'Data'), os.path.join(dist_path, 'Data') ) + +if __name__ == '__main__': + main()