mirror of
https://github.com/onionshare/onionshare.git
synced 2025-10-11 12:48:47 -04:00
Extract tor and obfs4proxy executables from the main TorBrowser executable with 7-zip on Windows
This commit is contained in:
parent
f14521af6a
commit
e4eafd7aeb
5 changed files with 34 additions and 30 deletions
|
@ -24,18 +24,17 @@ 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 inspect, os, sys, hashlib, shutil, subprocess
|
||||
import urllib.request
|
||||
|
||||
def main():
|
||||
zip_url = 'https://archive.torproject.org/tor-package-archive/torbrowser/7.0.11/tor-win32-0.3.1.9.zip'
|
||||
zip_filename = 'tor-win32-0.3.1.9.zip'
|
||||
expected_zip_sha256 = 'faf28efb606455842bda66ca369287a116b6d6e5ad3720ebed9337da0717f1b4'
|
||||
|
||||
exe_url = 'https://archive.torproject.org/tor-package-archive/torbrowser/7.0.11/torbrowser-install-7.0.11_en-US.exe'
|
||||
exe_filename = 'torbrowser-install-7.0.11_en-US.exe'
|
||||
expected_exe_sha256 = 'a033eb9b9ed2ad389169b36a90946a8af8f05bd0c7bbd3e37678041331096624'
|
||||
# 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)
|
||||
exe_path = os.path.join(working_path, exe_filename)
|
||||
dist_path = os.path.join(os.path.join(os.path.join(root_path, 'dist'), 'onionshare'), 'tor')
|
||||
|
||||
# Make sure the working folder exists
|
||||
|
@ -43,36 +42,35 @@ def main():
|
|||
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()
|
||||
if not os.path.exists(exe_path):
|
||||
print("Downloading {}".format(exe_url))
|
||||
response = urllib.request.urlopen(exe_url)
|
||||
exe_data = response.read()
|
||||
open(exe_path, 'wb').write(exe_data)
|
||||
exe_sha256 = hashlib.sha256(exe_data).hexdigest()
|
||||
else:
|
||||
zip_data = open(zip_path, 'rb').read()
|
||||
zip_sha256 = hashlib.sha256(zip_data).hexdigest()
|
||||
exe_data = open(exe_path, 'rb').read()
|
||||
exe_sha256 = hashlib.sha256(exe_data).hexdigest()
|
||||
|
||||
# Compare the hash
|
||||
if zip_sha256 != expected_zip_sha256:
|
||||
if exe_sha256 != expected_exe_sha256:
|
||||
print("ERROR! The sha256 doesn't match:")
|
||||
print("expected: {}".format(expected_zip_sha256))
|
||||
print(" actual: {}".format(zip_sha256))
|
||||
print("expected: {}".format(expected_exe_sha256))
|
||||
print(" actual: {}".format(exe_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'))
|
||||
# Extract the bits we need from the exe
|
||||
cmd = ['7z', 'e', exe_path, 'Browser\TorBrowser\Tor', '-o%s' % os.path.join(working_path, 'Tor')]
|
||||
cmd2 = ['7z', 'e', exe_path, 'Browser\TorBrowser\Data\Tor\geoip*', '-o%s' % os.path.join(working_path, 'Data')]
|
||||
subprocess.Popen(cmd).wait()
|
||||
subprocess.Popen(cmd2).wait()
|
||||
|
||||
# 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') )
|
||||
shutil.copytree( os.path.join(working_path, 'Data'), os.path.join(dist_path, 'Data', 'Tor') )
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue