aboutsummaryrefslogtreecommitdiff
path: root/desktop
diff options
context:
space:
mode:
authorMicah Lee <micah@micahflee.com>2021-12-12 13:03:47 -0800
committerMicah Lee <micah@micahflee.com>2021-12-12 13:03:47 -0800
commit4b18cb7d0f5e17fa2ac7d64e69be72e53775b163 (patch)
tree45a4507f41cb73c2a77db2895b6290319aff6b4b /desktop
parent805998e962f3629cef3e4f33ba20880c6838a1de (diff)
parentd304005fce6e655922327994eb78adf75e0d91d3 (diff)
downloadonionshare-4b18cb7d0f5e17fa2ac7d64e69be72e53775b163.tar.gz
onionshare-4b18cb7d0f5e17fa2ac7d64e69be72e53775b163.zip
Merge branch 'develop' of github.com:micahflee/onionshare into develop
Diffstat (limited to 'desktop')
-rw-r--r--desktop/scripts/bridges/__init__.py82
-rwxr-xr-xdesktop/scripts/build-meek-client.py4
-rwxr-xr-xdesktop/scripts/get-tor-linux.py4
-rwxr-xr-xdesktop/scripts/get-tor-osx.py5
-rw-r--r--desktop/scripts/get-tor-windows.py5
5 files changed, 99 insertions, 1 deletions
diff --git a/desktop/scripts/bridges/__init__.py b/desktop/scripts/bridges/__init__.py
new file mode 100644
index 00000000..1477d24d
--- /dev/null
+++ b/desktop/scripts/bridges/__init__.py
@@ -0,0 +1,82 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+"""
+OnionShare | https://onionshare.org/
+
+Copyright (C) 2014-2021 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/>.
+"""
+
+import os
+import requests
+
+
+class UpdateTorBridges:
+ """
+ Update the built-in Tor Bridges in OnionShare's torrc templates.
+ """
+
+ def __init__(self, root_path):
+ self.root_path = root_path
+ torrc_template_dir = os.path.join(
+ self.root_path, os.pardir, "cli/onionshare_cli/resources"
+ )
+ endpoint = "https://bridges.torproject.org/moat/circumvention/builtin"
+ r = requests.post(
+ endpoint,
+ headers={"Content-Type": "application/vnd.api+json"},
+ )
+ if r.status_code != 200:
+ print(
+ f"There was a problem fetching the latest built-in bridges: status_code={r.status_code}"
+ )
+ return False
+
+ result = r.json()
+
+ if "errors" in result:
+ print(
+ f"There was a problem fetching the latest built-in bridges: errors={result['errors']}"
+ )
+ return False
+
+ for bridge_type in ["meek", "obfs4", "snowflake"]:
+ if result[bridge_type]:
+ if bridge_type == "meek":
+ torrc_template_extension = "meek_lite_azure"
+ else:
+ torrc_template_extension = bridge_type
+ torrc_template = os.path.join(
+ self.root_path,
+ torrc_template_dir,
+ f"torrc_template-{torrc_template_extension}",
+ )
+
+ with open(torrc_template, "w") as f:
+ f.write(f"# Enable built-in {bridge_type} bridge\n")
+ bridges = result[bridge_type]
+ # Sorts the bridges numerically by IP, since they come back in
+ # random order from the API each time, and create noisy git diff.
+ bridges.sort(key=lambda s: s.split()[1])
+ for item in bridges:
+ if bridge_type == "meek":
+ # obfs4proxy expects the bridge type to be meek_lite, and the url/front params
+ # are missing in the Tor API response, so we have to add them in ourselves.
+ bridge = item.replace("meek", "meek_lite")
+ f.write(
+ f"Bridge {bridge} url=https://meek.azureedge.net/ front=ajax.aspnetcdn.com\n"
+ )
+ else:
+ f.write(f"Bridge {item}\n")
diff --git a/desktop/scripts/build-meek-client.py b/desktop/scripts/build-meek-client.py
index af58173a..ee4d28ee 100755
--- a/desktop/scripts/build-meek-client.py
+++ b/desktop/scripts/build-meek-client.py
@@ -48,7 +48,9 @@ def main():
os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
)
if platform.system() == "Windows":
- dist_path = os.path.join(root_path, "src", "onionshare", "resources", "tor", "Tor")
+ dist_path = os.path.join(
+ root_path, "src", "onionshare", "resources", "tor", "Tor"
+ )
bin_filename = "meek-client.exe"
else:
dist_path = os.path.join(root_path, "src", "onionshare", "resources", "tor")
diff --git a/desktop/scripts/get-tor-linux.py b/desktop/scripts/get-tor-linux.py
index 51beb475..1f5e36fd 100755
--- a/desktop/scripts/get-tor-linux.py
+++ b/desktop/scripts/get-tor-linux.py
@@ -31,6 +31,7 @@ import hashlib
import shutil
import subprocess
import requests
+from bridges import UpdateTorBridges
def main():
@@ -126,6 +127,9 @@ def main():
print(f"Tor binaries extracted to: {dist_path}")
+ # Fetch the built-in bridges
+ UpdateTorBridges(root_path)
+
if __name__ == "__main__":
main()
diff --git a/desktop/scripts/get-tor-osx.py b/desktop/scripts/get-tor-osx.py
index 80d7aee8..c5c01836 100755
--- a/desktop/scripts/get-tor-osx.py
+++ b/desktop/scripts/get-tor-osx.py
@@ -32,6 +32,8 @@ import shutil
import subprocess
import requests
+from bridges import UpdateTorBridges
+
def main():
dmg_url = "https://dist.torproject.org/torbrowser/11.0a10/TorBrowser-11.0a10-osx64_en-US.dmg"
@@ -113,6 +115,9 @@ def main():
# Eject dmg
subprocess.call(["diskutil", "eject", "/Volumes/Tor Browser"])
+ # Fetch the built-in bridges
+ UpdateTorBridges(root_path)
+
if __name__ == "__main__":
main()
diff --git a/desktop/scripts/get-tor-windows.py b/desktop/scripts/get-tor-windows.py
index 8ca2e79f..69c98a1b 100644
--- a/desktop/scripts/get-tor-windows.py
+++ b/desktop/scripts/get-tor-windows.py
@@ -31,6 +31,8 @@ import shutil
import subprocess
import requests
+from bridges import UpdateTorBridges
+
def main():
exe_url = "https://dist.torproject.org/torbrowser/11.0a10/torbrowser-install-11.0a10_en-US.exe"
@@ -98,6 +100,9 @@ def main():
os.path.join(working_path, "Data"), os.path.join(dist_path, "Data", "Tor")
)
+ # Fetch the built-in bridges
+ UpdateTorBridges(root_path)
+
if __name__ == "__main__":
main()