2020-11-04 18:57:14 -05:00
|
|
|
#!/usr/bin/env python3
|
2020-10-15 01:36:31 -04:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
OnionShare | https://onionshare.org/
|
|
|
|
|
|
|
|
Copyright (C) 2014-2020 Micah Lee, et al. <micah@micahflee.com>
|
|
|
|
|
|
|
|
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 Mac gnupg dependency, I manually verify the signature
|
|
|
|
and hard-code the sha256 hash.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import inspect
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import hashlib
|
|
|
|
import zipfile
|
|
|
|
import io
|
|
|
|
import shutil
|
|
|
|
import subprocess
|
|
|
|
import requests
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2020-11-04 18:57:14 -05:00
|
|
|
dmg_url = "https://archive.torproject.org/tor-package-archive/torbrowser/10.0.2/TorBrowser-10.0.2-osx64_en-US.dmg"
|
|
|
|
dmg_filename = "TorBrowser-10.0.2-osx64_en-US.dmg"
|
2020-10-15 01:36:31 -04:00
|
|
|
expected_dmg_sha256 = (
|
2020-11-04 18:57:14 -05:00
|
|
|
"ac8d28f6f8d92e220f72ef7b0cb2bba45d5e0d4b243dc50806e33e08278e7730"
|
2020-10-15 01:36:31 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
# Build paths
|
|
|
|
root_path = os.path.dirname(
|
|
|
|
os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
|
|
|
|
)
|
|
|
|
working_path = os.path.join(root_path, "build", "tor")
|
|
|
|
dmg_tor_path = os.path.join(
|
|
|
|
"/Volumes", "Tor Browser", "Tor Browser.app", "Contents"
|
|
|
|
)
|
|
|
|
dmg_path = os.path.join(working_path, dmg_filename)
|
2020-11-04 18:57:14 -05:00
|
|
|
dist_path = os.path.join(root_path, "src", "onionshare", "resources", "tor")
|
|
|
|
if not os.path.exists(dist_path):
|
|
|
|
os.makedirs(dist_path, exist_ok=True)
|
2020-10-15 01:36:31 -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
|
|
|
|
if not os.path.exists(dmg_path):
|
|
|
|
print("Downloading {}".format(dmg_url))
|
|
|
|
r = requests.get(dmg_url)
|
|
|
|
open(dmg_path, "wb").write(r.content)
|
|
|
|
dmg_sha256 = hashlib.sha256(r.content).hexdigest()
|
|
|
|
else:
|
|
|
|
dmg_data = open(dmg_path, "rb").read()
|
|
|
|
dmg_sha256 = hashlib.sha256(dmg_data).hexdigest()
|
|
|
|
|
|
|
|
# Compare the hash
|
|
|
|
if dmg_sha256 != expected_dmg_sha256:
|
|
|
|
print("ERROR! The sha256 doesn't match:")
|
|
|
|
print("expected: {}".format(expected_dmg_sha256))
|
|
|
|
print(" actual: {}".format(dmg_sha256))
|
|
|
|
sys.exit(-1)
|
|
|
|
|
|
|
|
# Mount the dmg, copy data to the working path
|
|
|
|
subprocess.call(["hdiutil", "attach", dmg_path])
|
|
|
|
|
|
|
|
# Copy into dist
|
|
|
|
shutil.copyfile(
|
|
|
|
os.path.join(dmg_tor_path, "Resources", "TorBrowser", "Tor", "geoip"),
|
2020-11-04 18:57:14 -05:00
|
|
|
os.path.join(dist_path, "geoip"),
|
2020-10-15 01:36:31 -04:00
|
|
|
)
|
|
|
|
shutil.copyfile(
|
|
|
|
os.path.join(dmg_tor_path, "Resources", "TorBrowser", "Tor", "geoip6"),
|
2020-11-04 18:57:14 -05:00
|
|
|
os.path.join(dist_path, "geoip6"),
|
2020-10-15 01:36:31 -04:00
|
|
|
)
|
|
|
|
shutil.copyfile(
|
|
|
|
os.path.join(dmg_tor_path, "MacOS", "Tor", "tor.real"),
|
2020-11-04 18:57:14 -05:00
|
|
|
os.path.join(dist_path, "tor"),
|
2020-10-15 01:36:31 -04:00
|
|
|
)
|
2020-11-04 18:57:14 -05:00
|
|
|
os.chmod(os.path.join(dist_path, "tor"), 0o755)
|
2020-10-15 01:36:31 -04:00
|
|
|
shutil.copyfile(
|
|
|
|
os.path.join(dmg_tor_path, "MacOS", "Tor", "libevent-2.1.7.dylib"),
|
2020-11-04 18:57:14 -05:00
|
|
|
os.path.join(dist_path, "libevent-2.1.7.dylib"),
|
2020-10-15 01:36:31 -04:00
|
|
|
)
|
|
|
|
# obfs4proxy binary
|
|
|
|
shutil.copyfile(
|
|
|
|
os.path.join(dmg_tor_path, "MacOS", "Tor", "PluggableTransports", "obfs4proxy"),
|
2020-11-04 18:57:14 -05:00
|
|
|
os.path.join(dist_path, "obfs4proxy"),
|
2020-10-15 01:36:31 -04:00
|
|
|
)
|
2020-11-04 18:57:14 -05:00
|
|
|
os.chmod(os.path.join(dist_path, "obfs4proxy"), 0o755)
|
2020-10-15 01:36:31 -04:00
|
|
|
|
|
|
|
# Eject dmg
|
|
|
|
subprocess.call(["diskutil", "eject", "/Volumes/Tor Browser"])
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|