Fix meek-client in Windows

This commit is contained in:
Micah Lee 2021-11-07 12:12:12 -08:00
parent 472e383b7d
commit 9430439b5f
No known key found for this signature in database
GPG key ID: 403C2657CD994F73
4 changed files with 31 additions and 9 deletions

View file

@ -85,6 +85,10 @@ class Meek(object):
self.common.log("Meek", "start", "Starting meek client") self.common.log("Meek", "start", "Starting meek client")
if self.common.platform == "Windows": if self.common.platform == "Windows":
env = os.environ.copy()
for key in self.meek_env:
env[key] = self.meek_env[key]
# In Windows, hide console window when opening meek-client.exe subprocess # In Windows, hide console window when opening meek-client.exe subprocess
startupinfo = subprocess.STARTUPINFO() startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
@ -100,7 +104,7 @@ class Meek(object):
stderr=subprocess.PIPE, stderr=subprocess.PIPE,
startupinfo=startupinfo, startupinfo=startupinfo,
bufsize=1, bufsize=1,
env=self.meek_env, env=env,
text=True, text=True,
) )
else: else:
@ -129,6 +133,7 @@ class Meek(object):
# read stdout without blocking # read stdout without blocking
try: try:
line = q.get_nowait() line = q.get_nowait()
self.common.log("Meek", "start", line.strip())
except Empty: except Empty:
# no stdout yet? # no stdout yet?
pass pass
@ -143,6 +148,10 @@ class Meek(object):
) )
break break
if "CMETHOD-ERROR" in line:
self.cleanup()
raise MeekNotRunning()
if self.meek_port: if self.meek_port:
self.meek_proxies = { self.meek_proxies = {
"http": f"socks5h://{self.meek_host}:{self.meek_port}", "http": f"socks5h://{self.meek_host}:{self.meek_port}",
@ -150,6 +159,7 @@ class Meek(object):
} }
else: else:
self.common.log("Meek", "start", "Could not obtain the meek port") self.common.log("Meek", "start", "Could not obtain the meek port")
self.cleanup()
raise MeekNotRunning() raise MeekNotRunning()
def cleanup(self): def cleanup(self):

View file

@ -65,7 +65,7 @@ python scripts\get-tor-windows.py
### Compile dependencies ### Compile dependencies
Install Go. The simplest way to make sure everything works is to install Go by following [these instructions](https://golang.org/doc/install). Install Go. The simplest way to make sure everything works is to install Go by following [these instructions](https://golang.org/doc/install). (In Windows, make sure to install the 32-bit version of Go, such as `go1.17.3.windows-386.msi`.)
Download and compile `meek-client`: Download and compile `meek-client`:

View file

@ -28,6 +28,7 @@ import shutil
import os import os
import subprocess import subprocess
import inspect import inspect
import platform
def main(): def main():
@ -46,16 +47,21 @@ def main():
root_path = os.path.dirname( root_path = os.path.dirname(
os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
) )
dist_path = os.path.join(root_path, "src", "onionshare", "resources", "tor") if platform.system() == "Windows":
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")
bin_filename = "meek-client"
bin_path = os.path.expanduser("~/go/bin/meek-client") bin_path = os.path.join(os.path.expanduser("~"), "go", "bin", bin_filename)
shutil.copyfile( shutil.copyfile(
os.path.join(bin_path), os.path.join(bin_path),
os.path.join(dist_path, "meek-client"), os.path.join(dist_path, bin_filename),
) )
os.chmod(os.path.join(dist_path, "meek-client"), 0o755) os.chmod(os.path.join(dist_path, bin_filename), 0o755)
print(f"Installed meek-client in {dist_path}") print(f"Installed {bin_filename} in {dist_path}")
if __name__ == "__main__": if __name__ == "__main__":

View file

@ -26,7 +26,7 @@ import json
from . import strings from . import strings
from .gui_common import GuiCommon from .gui_common import GuiCommon
from onionshare_cli.meek import MeekNotFound from onionshare_cli.meek import MeekNotFound, MeekNotRunning
class MoatDialog(QtWidgets.QDialog): class MoatDialog(QtWidgets.QDialog):
@ -237,7 +237,13 @@ class MoatThread(QtCore.QThread):
try: try:
self.meek.start() self.meek.start()
except MeekNotFound: except MeekNotFound:
self.common.log("MoatThread", "run", f"Could not find the Meek Client") self.common.log("MoatThread", "run", f"Could not find meek-client")
self.bridgedb_error.emit()
return
except MeekNotRunning:
self.common.log(
"MoatThread", "run", f"Ran meek-client, but there was an error"
)
self.bridgedb_error.emit() self.bridgedb_error.emit()
return return