2017-04-08 20:29:00 -04:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
OnionShare | https://onionshare.org/
|
|
|
|
|
2020-08-27 19:13:08 -04:00
|
|
|
Copyright (C) 2014-2020 Micah Lee, et al. <micah@micahflee.com>
|
2017-04-08 20:29:00 -04:00
|
|
|
|
|
|
|
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 <http://www.gnu.org/licenses/>.
|
|
|
|
"""
|
|
|
|
|
|
|
|
"""
|
|
|
|
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.
|
|
|
|
"""
|
|
|
|
|
2018-06-18 15:53:27 -04:00
|
|
|
import inspect
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import hashlib
|
|
|
|
import shutil
|
|
|
|
import subprocess
|
|
|
|
import requests
|
2017-04-08 20:29:00 -04:00
|
|
|
|
2019-10-13 00:01:25 -04:00
|
|
|
|
2017-04-08 20:29:00 -04:00
|
|
|
def main():
|
2019-10-13 00:01:25 -04:00
|
|
|
exe_url = "https://archive.torproject.org/tor-package-archive/torbrowser/8.5.5/torbrowser-install-8.5.5_en-US.exe"
|
|
|
|
exe_filename = "torbrowser-install-8.5.5_en-US.exe"
|
|
|
|
expected_exe_sha256 = (
|
|
|
|
"a3aa7e626d1d2365dcecc6f17055f467f31c4ff9558a769e51d4b90640e48bb0"
|
|
|
|
)
|
2017-04-08 20:29:00 -04:00
|
|
|
# Build paths
|
2019-10-13 00:01:25 -04:00
|
|
|
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")
|
2018-01-16 20:45:37 -05:00
|
|
|
exe_path = os.path.join(working_path, exe_filename)
|
2019-10-13 00:01:25 -04:00
|
|
|
dist_path = os.path.join(
|
|
|
|
os.path.join(os.path.join(root_path, "dist"), "onionshare"), "tor"
|
|
|
|
)
|
2017-04-08 20:29:00 -04:00
|
|
|
|
|
|
|
# Make sure the working folder exists
|
|
|
|
if not os.path.exists(working_path):
|
|
|
|
os.makedirs(working_path)
|
|
|
|
|
|
|
|
# Make sure the zip is downloaded
|
2018-01-16 20:45:37 -05:00
|
|
|
if not os.path.exists(exe_path):
|
|
|
|
print("Downloading {}".format(exe_url))
|
2018-06-18 15:53:27 -04:00
|
|
|
r = requests.get(exe_url)
|
2019-10-13 00:01:25 -04:00
|
|
|
open(exe_path, "wb").write(r.content)
|
2018-06-18 15:53:27 -04:00
|
|
|
exe_sha256 = hashlib.sha256(r.content).hexdigest()
|
2017-04-08 20:29:00 -04:00
|
|
|
else:
|
2019-10-13 00:01:25 -04:00
|
|
|
exe_data = open(exe_path, "rb").read()
|
2018-01-16 20:45:37 -05:00
|
|
|
exe_sha256 = hashlib.sha256(exe_data).hexdigest()
|
2017-04-08 20:29:00 -04:00
|
|
|
|
|
|
|
# Compare the hash
|
2018-01-16 20:45:37 -05:00
|
|
|
if exe_sha256 != expected_exe_sha256:
|
2017-04-08 20:29:00 -04:00
|
|
|
print("ERROR! The sha256 doesn't match:")
|
2018-01-16 20:45:37 -05:00
|
|
|
print("expected: {}".format(expected_exe_sha256))
|
|
|
|
print(" actual: {}".format(exe_sha256))
|
2017-04-08 20:29:00 -04:00
|
|
|
sys.exit(-1)
|
|
|
|
|
2018-01-16 20:45:37 -05:00
|
|
|
# Extract the bits we need from the exe
|
2019-10-13 00:01:25 -04:00
|
|
|
cmd = [
|
|
|
|
"7z",
|
|
|
|
"e",
|
|
|
|
"-y",
|
|
|
|
exe_path,
|
|
|
|
"Browser\TorBrowser\Tor",
|
|
|
|
"-o%s" % os.path.join(working_path, "Tor"),
|
|
|
|
]
|
|
|
|
cmd2 = [
|
|
|
|
"7z",
|
|
|
|
"e",
|
|
|
|
"-y",
|
|
|
|
exe_path,
|
|
|
|
"Browser\TorBrowser\Data\Tor\geoip*",
|
|
|
|
"-o%s" % os.path.join(working_path, "Data"),
|
|
|
|
]
|
2018-01-16 20:45:37 -05:00
|
|
|
subprocess.Popen(cmd).wait()
|
|
|
|
subprocess.Popen(cmd2).wait()
|
2017-04-08 20:29:00 -04:00
|
|
|
|
|
|
|
# Copy into dist
|
|
|
|
if os.path.exists(dist_path):
|
|
|
|
shutil.rmtree(dist_path)
|
|
|
|
os.makedirs(dist_path)
|
2019-10-13 00:01:25 -04:00
|
|
|
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", "Tor")
|
|
|
|
)
|
|
|
|
|
2017-04-08 20:29:00 -04:00
|
|
|
|
2019-10-13 00:01:25 -04:00
|
|
|
if __name__ == "__main__":
|
2017-04-08 20:29:00 -04:00
|
|
|
main()
|