mirror of
https://github.com/onionshare/onionshare.git
synced 2025-08-06 05:14:13 -04:00
Make scripts to build PT binaries, and run those in CI
This commit is contained in:
parent
11529fc602
commit
b143ccc770
10 changed files with 187 additions and 336 deletions
|
@ -1,80 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
OnionShare | https://onionshare.org/
|
||||
|
||||
Copyright (C) 2014-2022 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 shutil
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
import inspect
|
||||
import platform
|
||||
|
||||
|
||||
def main():
|
||||
# Figure out the architecture and python path
|
||||
if "64 bit" in sys.version:
|
||||
python_arch = "win-amd64"
|
||||
else:
|
||||
python_arch = "win32"
|
||||
|
||||
if os.getlogin() == "circleci" and python_arch == "win32":
|
||||
go_path = "C:\\Program Files (x86)\\Go\\bin\\go"
|
||||
else:
|
||||
go_path = shutil.which("go")
|
||||
|
||||
if go_path is None:
|
||||
print("Install go: https://golang.org/doc/install")
|
||||
return
|
||||
|
||||
subprocess.run(
|
||||
[
|
||||
go_path,
|
||||
"install",
|
||||
"git.torproject.org/pluggable-transports/meek.git/meek-client@v0.37.0",
|
||||
]
|
||||
)
|
||||
|
||||
root_path = os.path.dirname(
|
||||
os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
|
||||
)
|
||||
if platform.system() == "Windows":
|
||||
dist_path = os.path.join(root_path, "onionshare", "resources", "tor", "Tor")
|
||||
bin_filename = "meek-client.exe"
|
||||
else:
|
||||
dist_path = os.path.join(root_path, "onionshare", "resources", "tor")
|
||||
bin_filename = "meek-client"
|
||||
|
||||
bin_path = os.path.join(os.path.expanduser("~"), "go", "bin", bin_filename)
|
||||
shutil.copyfile(
|
||||
os.path.join(bin_path),
|
||||
os.path.join(dist_path, bin_filename),
|
||||
)
|
||||
os.chmod(os.path.join(dist_path, bin_filename), 0o755)
|
||||
|
||||
print(f"Installed {bin_filename} in {dist_path}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
9
desktop/scripts/build-pt-meek.ps1
Normal file
9
desktop/scripts/build-pt-meek.ps1
Normal file
|
@ -0,0 +1,9 @@
|
|||
$env:MEEK_TAG = 'v0.37.0'
|
||||
|
||||
New-Item -ItemType Directory -Force -Path .\build\meek
|
||||
cd .\build\meek
|
||||
git clone https://git.torproject.org/pluggable-transports/meek.git
|
||||
cd meek
|
||||
git checkout $MEEK_TAG
|
||||
go build .\meek-client
|
||||
Move-Item -Path .\meek-client.exe -Destination ..\onionshare\resources\tor\meek-client.exe
|
9
desktop/scripts/build-pt-meek.sh
Executable file
9
desktop/scripts/build-pt-meek.sh
Executable file
|
@ -0,0 +1,9 @@
|
|||
#!/bin/bash
|
||||
MEEK_TAG=v0.37.0
|
||||
|
||||
mkdir -p ./build/meek
|
||||
cd ./build/meek
|
||||
git clone https://git.torproject.org/pluggable-transports/meek.git
|
||||
cd meek
|
||||
git checkout $MEEK_TAG
|
||||
go build -o ../../../onionshare/resources/tor/meek-client ./meek-client
|
9
desktop/scripts/build-pt-obfs4proxy.ps1
Normal file
9
desktop/scripts/build-pt-obfs4proxy.ps1
Normal file
|
@ -0,0 +1,9 @@
|
|||
$env:OBFS4PROXY_TAG = 'obfs4proxy-0.0.13'
|
||||
|
||||
New-Item -ItemType Directory -Force -Path .\build\obfs4proxy
|
||||
cd .\build\obfs4proxy
|
||||
git clone https://gitlab.com/yawning/obfs4
|
||||
cd obfs4
|
||||
git checkout $OBFS4PROXY_TAG
|
||||
go build .\obfs4proxy
|
||||
Move-Item -Path .\obfs4proxy.exe -Destination ..\onionshare\resources\tor\obfs4proxy.exe
|
9
desktop/scripts/build-pt-obfs4proxy.sh
Executable file
9
desktop/scripts/build-pt-obfs4proxy.sh
Executable file
|
@ -0,0 +1,9 @@
|
|||
#!/bin/bash
|
||||
OBFS4PROXY_TAG=obfs4proxy-0.0.13
|
||||
|
||||
mkdir -p ./build/obfs4proxy
|
||||
cd ./build/obfs4proxy
|
||||
git clone https://gitlab.com/yawning/obfs4 || echo "already cloned"
|
||||
cd obfs4
|
||||
git checkout $OBFS4PROXY_TAG
|
||||
go build -o ../../../onionshare/resources/tor/obfs4proxy ./obfs4proxy
|
9
desktop/scripts/build-pt-snowflake.ps1
Normal file
9
desktop/scripts/build-pt-snowflake.ps1
Normal file
|
@ -0,0 +1,9 @@
|
|||
$env:SNOWFLAKE_TAG = 'v2.2.0'
|
||||
|
||||
New-Item -ItemType Directory -Force -Path .\build\snowflake
|
||||
cd .\build\snowflake
|
||||
git clone https://git.torproject.org/pluggable-transports/snowflake.git
|
||||
cd snowflake
|
||||
git checkout $SNOWFLAKE_TAG
|
||||
go build .\client
|
||||
Move-Item -Path .\client.exe -Destination ..\onionshare\resources\tor\snowflake-client.exe
|
9
desktop/scripts/build-pt-snowflake.sh
Executable file
9
desktop/scripts/build-pt-snowflake.sh
Executable file
|
@ -0,0 +1,9 @@
|
|||
#!/bin/bash
|
||||
SNOWFLAKE_TAG=v2.2.0
|
||||
|
||||
mkdir -p ./build/snowflake
|
||||
cd ./build/snowflake
|
||||
git clone https://git.torproject.org/pluggable-transports/snowflake.git
|
||||
cd snowflake
|
||||
git checkout $SNOWFLAKE_TAG
|
||||
go build -o ../../../onionshare/resources/tor/snowflake-client ./client
|
|
@ -1,5 +1,4 @@
|
|||
#!/usr/bin/env python3
|
||||
import platform
|
||||
import inspect
|
||||
import os
|
||||
from re import M
|
||||
|
@ -8,18 +7,30 @@ import hashlib
|
|||
import shutil
|
||||
import subprocess
|
||||
import requests
|
||||
import click
|
||||
|
||||
torbrowser_version = "11.0.14"
|
||||
expected_exe_sha256 = "c14b979c81310ad039985e047dbb5b8058662bb3105b9022f7b9e0d18a29d0d6"
|
||||
expected_dmg_sha256 = "558ae5ab188f62feb04c6b2e7f43eae2361e8ec1718e0f4f927801411d911e22"
|
||||
expected_txz_sha256 = "b606924fdf8237e697cf95c229189da5875c190875d729769655c7b67aeb9aa6"
|
||||
expected_win32_sha256 = (
|
||||
"c14b979c81310ad039985e047dbb5b8058662bb3105b9022f7b9e0d18a29d0d6"
|
||||
)
|
||||
expected_win64_sha256 = (
|
||||
"ced3de06d089fbbeb8cee309971ac26983aba8eaf948fedce472d40cdd572301"
|
||||
)
|
||||
expected_macos_sha256 = (
|
||||
"558ae5ab188f62feb04c6b2e7f43eae2361e8ec1718e0f4f927801411d911e22"
|
||||
)
|
||||
expected_linux64_sha256 = (
|
||||
"b606924fdf8237e697cf95c229189da5875c190875d729769655c7b67aeb9aa6"
|
||||
)
|
||||
|
||||
exe_url = f"https://dist.torproject.org/torbrowser/{torbrowser_version}/torbrowser-install-{torbrowser_version}_en-US.exe"
|
||||
exe_filename = f"torbrowser-install-{torbrowser_version}_en-US.exe"
|
||||
dmg_url = f"https://dist.torproject.org/torbrowser/{torbrowser_version}/TorBrowser-{torbrowser_version}-osx64_en-US.dmg"
|
||||
dmg_filename = f"TorBrowser-{torbrowser_version}-osx64_en-US.dmg"
|
||||
tarball_url = f"https://dist.torproject.org/torbrowser/{torbrowser_version}/tor-browser-linux64-{torbrowser_version}_en-US.tar.xz"
|
||||
tarball_filename = f"tor-browser-linux64-{torbrowser_version}_en-US.tar.xz"
|
||||
win32_url = f"https://dist.torproject.org/torbrowser/{torbrowser_version}/torbrowser-install-{torbrowser_version}_en-US.exe"
|
||||
win32_filename = f"torbrowser-install-{torbrowser_version}_en-US.exe"
|
||||
win64_url = f"https://dist.torproject.org/torbrowser/{torbrowser_version}/torbrowser-install-win64-{torbrowser_version}_en-US.exe"
|
||||
win64_filename = f"torbrowser-install-win64-{torbrowser_version}_en-US.exe"
|
||||
macos_url = f"https://dist.torproject.org/torbrowser/{torbrowser_version}/TorBrowser-{torbrowser_version}-osx64_en-US.dmg"
|
||||
macos_filename = f"TorBrowser-{torbrowser_version}-osx64_en-US.dmg"
|
||||
linux64_url = f"https://dist.torproject.org/torbrowser/{torbrowser_version}/tor-browser-linux64-{torbrowser_version}_en-US.tar.xz"
|
||||
linux64_filename = f"tor-browser-linux64-{torbrowser_version}_en-US.tar.xz"
|
||||
|
||||
|
||||
# Common paths
|
||||
|
@ -29,9 +40,21 @@ root_path = os.path.dirname(
|
|||
working_path = os.path.join(root_path, "build", "tor")
|
||||
|
||||
|
||||
def get_tor_windows():
|
||||
def get_tor_windows(platform):
|
||||
if platform == "win32":
|
||||
win_url = win32_url
|
||||
win_filename = win32_filename
|
||||
expected_win_sha256 = expected_win32_sha256
|
||||
elif platform == "win64":
|
||||
win_url = win64_url
|
||||
win_filename = win64_filename
|
||||
expected_win_sha256 = expected_win64_sha256
|
||||
else:
|
||||
click.echo("invalid platform")
|
||||
return
|
||||
|
||||
# Build paths
|
||||
exe_path = os.path.join(working_path, exe_filename)
|
||||
win_path = os.path.join(working_path, win_filename)
|
||||
dist_path = os.path.join(root_path, "onionshare", "resources", "tor")
|
||||
|
||||
# Make sure the working folder exists
|
||||
|
@ -39,21 +62,21 @@ def get_tor_windows():
|
|||
os.makedirs(working_path)
|
||||
|
||||
# Make sure Tor Browser is downloaded
|
||||
if not os.path.exists(exe_path):
|
||||
print("Downloading {}".format(exe_url))
|
||||
r = requests.get(exe_url)
|
||||
open(exe_path, "wb").write(r.content)
|
||||
if not os.path.exists(win_path):
|
||||
print("Downloading {}".format(win_url))
|
||||
r = requests.get(win_url)
|
||||
open(win_path, "wb").write(r.content)
|
||||
exe_sha256 = hashlib.sha256(r.content).hexdigest()
|
||||
else:
|
||||
print("Already downloaded: {}".format(exe_path))
|
||||
exe_data = open(exe_path, "rb").read()
|
||||
exe_sha256 = hashlib.sha256(exe_data).hexdigest()
|
||||
print("Already downloaded: {}".format(win_path))
|
||||
win_data = open(win_path, "rb").read()
|
||||
win_sha256 = hashlib.sha256(win_data).hexdigest()
|
||||
|
||||
# Compare the hash
|
||||
if exe_sha256 != expected_exe_sha256:
|
||||
if win_sha256 != expected_win_sha256:
|
||||
print("ERROR! The sha256 doesn't match:")
|
||||
print("expected: {}".format(expected_exe_sha256))
|
||||
print(" actual: {}".format(exe_sha256))
|
||||
print("expected: {}".format(expected_win32_sha256))
|
||||
print(" actual: {}".format(win_sha256))
|
||||
sys.exit(-1)
|
||||
|
||||
# Extract the bits we need from the exe
|
||||
|
@ -62,7 +85,7 @@ def get_tor_windows():
|
|||
"7z",
|
||||
"e",
|
||||
"-y",
|
||||
exe_path,
|
||||
win_path,
|
||||
"Browser\\TorBrowser\\Tor",
|
||||
"-o%s" % os.path.join(working_path, "Tor"),
|
||||
]
|
||||
|
@ -72,7 +95,7 @@ def get_tor_windows():
|
|||
"7z",
|
||||
"e",
|
||||
"-y",
|
||||
exe_path,
|
||||
win_path,
|
||||
"Browser\\TorBrowser\\Data\\Tor\\geoip*",
|
||||
"-o%s" % os.path.join(working_path, "Data"),
|
||||
]
|
||||
|
@ -113,7 +136,7 @@ def get_tor_macos():
|
|||
dmg_tor_path = os.path.join(
|
||||
"/Volumes", "Tor Browser", "Tor Browser.app", "Contents"
|
||||
)
|
||||
dmg_path = os.path.join(working_path, dmg_filename)
|
||||
dmg_path = os.path.join(working_path, macos_filename)
|
||||
dist_path = os.path.join(root_path, "onionshare", "resources", "tor")
|
||||
if not os.path.exists(dist_path):
|
||||
os.makedirs(dist_path, exist_ok=True)
|
||||
|
@ -124,8 +147,8 @@ def get_tor_macos():
|
|||
|
||||
# Make sure the zip is downloaded
|
||||
if not os.path.exists(dmg_path):
|
||||
print("Downloading {}".format(dmg_url))
|
||||
r = requests.get(dmg_url)
|
||||
print("Downloading {}".format(macos_url))
|
||||
r = requests.get(macos_url)
|
||||
open(dmg_path, "wb").write(r.content)
|
||||
dmg_sha256 = hashlib.sha256(r.content).hexdigest()
|
||||
else:
|
||||
|
@ -133,9 +156,9 @@ def get_tor_macos():
|
|||
dmg_sha256 = hashlib.sha256(dmg_data).hexdigest()
|
||||
|
||||
# Compare the hash
|
||||
if dmg_sha256 != expected_dmg_sha256:
|
||||
if dmg_sha256 != expected_macos_sha256:
|
||||
print("ERROR! The sha256 doesn't match:")
|
||||
print("expected: {}".format(expected_dmg_sha256))
|
||||
print("expected: {}".format(expected_macos_sha256))
|
||||
print(" actual: {}".format(dmg_sha256))
|
||||
sys.exit(-1)
|
||||
|
||||
|
@ -182,9 +205,9 @@ def get_tor_macos():
|
|||
update_tor_bridges()
|
||||
|
||||
|
||||
def get_tor_linux():
|
||||
def get_tor_linux64():
|
||||
# Build paths
|
||||
tarball_path = os.path.join(working_path, tarball_filename)
|
||||
tarball_path = os.path.join(working_path, linux64_filename)
|
||||
dist_path = os.path.join(root_path, "onionshare", "resources", "tor")
|
||||
|
||||
# Make sure dirs exist
|
||||
|
@ -196,8 +219,8 @@ def get_tor_linux():
|
|||
|
||||
# Make sure the tarball is downloaded
|
||||
if not os.path.exists(tarball_path):
|
||||
print("Downloading {}".format(tarball_url))
|
||||
r = requests.get(tarball_url)
|
||||
print("Downloading {}".format(linux64_url))
|
||||
r = requests.get(linux64_url)
|
||||
open(tarball_path, "wb").write(r.content)
|
||||
tarball_sha256 = hashlib.sha256(r.content).hexdigest()
|
||||
else:
|
||||
|
@ -205,9 +228,9 @@ def get_tor_linux():
|
|||
tarball_sha256 = hashlib.sha256(tarball_data).hexdigest()
|
||||
|
||||
# Compare the hash
|
||||
if tarball_sha256 != expected_txz_sha256:
|
||||
if tarball_sha256 != expected_linux64_sha256:
|
||||
print("ERROR! The sha256 doesn't match:")
|
||||
print("expected: {}".format(expected_txz_sha256))
|
||||
print("expected: {}".format(expected_linux64_sha256))
|
||||
print(" actual: {}".format(tarball_sha256))
|
||||
sys.exit(-1)
|
||||
|
||||
|
@ -250,18 +273,6 @@ def get_tor_linux():
|
|||
os.path.join(tarball_tor_path, "Tor", "libstdc++", "libstdc++.so.6"),
|
||||
os.path.join(dist_path, "libstdc++.so.6"),
|
||||
)
|
||||
shutil.copyfile(
|
||||
os.path.join(tarball_tor_path, "Tor", "PluggableTransports", "obfs4proxy"),
|
||||
os.path.join(dist_path, "obfs4proxy"),
|
||||
)
|
||||
os.chmod(os.path.join(dist_path, "obfs4proxy"), 0o755)
|
||||
shutil.copyfile(
|
||||
os.path.join(
|
||||
tarball_tor_path, "Tor", "PluggableTransports", "snowflake-client"
|
||||
),
|
||||
os.path.join(dist_path, "snowflake-client"),
|
||||
)
|
||||
os.chmod(os.path.join(dist_path, "snowflake-client"), 0o755)
|
||||
|
||||
print(f"Tor binaries extracted to: {dist_path}")
|
||||
|
||||
|
@ -317,19 +328,27 @@ def update_tor_bridges():
|
|||
f.write(f"Bridge {item}\n")
|
||||
|
||||
|
||||
def main():
|
||||
@click.command()
|
||||
@click.argument("platform")
|
||||
def main(platform):
|
||||
"""
|
||||
Download Tor Browser and extract tor binaries
|
||||
"""
|
||||
system = platform.system()
|
||||
if system == "Windows":
|
||||
get_tor_windows()
|
||||
elif system == "Darwin":
|
||||
valid_platforms = ["win32", "win64", "macos", "linux64"]
|
||||
if platform not in valid_platforms:
|
||||
click.echo(f"platform must be one of: {valid_platforms}")
|
||||
return
|
||||
|
||||
if platform == "win32":
|
||||
get_tor_windows(platform)
|
||||
elif platform == "win64":
|
||||
get_tor_windows(platform)
|
||||
elif platform == "macos":
|
||||
get_tor_macos()
|
||||
elif system == "Linux":
|
||||
get_tor_linux()
|
||||
elif platform == "linux64":
|
||||
get_tor_linux64()
|
||||
else:
|
||||
print("Platform not supported")
|
||||
click.echo("invalid platform")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue