mirror of
https://github.com/onionshare/onionshare.git
synced 2024-10-01 01:35:40 -04:00
Make macOS use Tor control ports instead of unix sockets to connect to the Tor controller
This commit is contained in:
parent
845d7f8564
commit
2cbe8979ab
@ -15,7 +15,6 @@ a = Analysis(
|
|||||||
('../share/torrc_template', 'share'),
|
('../share/torrc_template', 'share'),
|
||||||
('../share/torrc_template-obfs4', 'share'),
|
('../share/torrc_template-obfs4', 'share'),
|
||||||
('../share/torrc_template-meek_lite_azure', 'share'),
|
('../share/torrc_template-meek_lite_azure', 'share'),
|
||||||
('../share/torrc_template-windows', 'share'),
|
|
||||||
('../share/images/*', 'share/images'),
|
('../share/images/*', 'share/images'),
|
||||||
('../share/locale/*', 'share/locale'),
|
('../share/locale/*', 'share/locale'),
|
||||||
('../share/static/*', 'share/static'),
|
('../share/static/*', 'share/static'),
|
||||||
|
@ -170,36 +170,36 @@ class Onion(object):
|
|||||||
group_container_dir = os.path.expanduser('~/Library/Group Containers/com.micahflee.onionshare')
|
group_container_dir = os.path.expanduser('~/Library/Group Containers/com.micahflee.onionshare')
|
||||||
os.makedirs(group_container_dir, exist_ok=True)
|
os.makedirs(group_container_dir, exist_ok=True)
|
||||||
self.tor_data_directory = tempfile.TemporaryDirectory(dir=group_container_dir)
|
self.tor_data_directory = tempfile.TemporaryDirectory(dir=group_container_dir)
|
||||||
self.common.log('Onion', 'connect', 'tor_data_directory={}'.format(self.tor_data_directory))
|
self.common.log('Onion', 'connect', 'tor_data_directory={}'.format(self.tor_data_directory.name))
|
||||||
else:
|
else:
|
||||||
self.tor_data_directory = tempfile.TemporaryDirectory()
|
self.tor_data_directory = tempfile.TemporaryDirectory()
|
||||||
|
|
||||||
if self.common.platform == 'Windows':
|
# Create the torrc
|
||||||
# Windows needs to use network ports, doesn't support unix sockets
|
with open(self.common.get_resource_path('torrc_template')) as f:
|
||||||
torrc_template = open(self.common.get_resource_path('torrc_template-windows')).read()
|
torrc_template = f.read()
|
||||||
|
self.tor_cookie_auth_file = os.path.join(self.tor_data_directory.name, 'cookie')
|
||||||
|
try:
|
||||||
|
self.tor_socks_port = self.common.get_available_port(1000, 65535)
|
||||||
|
except:
|
||||||
|
raise OSError(strings._('no_available_port'))
|
||||||
|
self.tor_torrc = os.path.join(self.tor_data_directory.name, 'torrc')
|
||||||
|
|
||||||
|
if self.common.platform == 'Windows' or self.common.platform == "Darwin":
|
||||||
|
# Windows doesn't support unix sockets, so it must use a network port.
|
||||||
|
# macOS can't use unix sockets either because socket filenames are limited to
|
||||||
|
# 100 chars, and the macOS sandbox forces us to put the socket file in a place
|
||||||
|
# with a really long path.
|
||||||
|
torrc_template += 'ControlPort {{control_port}}\n'
|
||||||
try:
|
try:
|
||||||
self.tor_control_port = self.common.get_available_port(1000, 65535)
|
self.tor_control_port = self.common.get_available_port(1000, 65535)
|
||||||
except:
|
except:
|
||||||
raise OSError(strings._('no_available_port'))
|
raise OSError(strings._('no_available_port'))
|
||||||
self.tor_control_socket = None
|
self.tor_control_socket = None
|
||||||
self.tor_cookie_auth_file = os.path.join(self.tor_data_directory.name, 'cookie')
|
|
||||||
try:
|
|
||||||
self.tor_socks_port = self.common.get_available_port(1000, 65535)
|
|
||||||
except:
|
|
||||||
raise OSError(strings._('no_available_port'))
|
|
||||||
self.tor_torrc = os.path.join(self.tor_data_directory.name, 'torrc')
|
|
||||||
else:
|
else:
|
||||||
# Linux, Mac and BSD can use unix sockets
|
# Linux and BSD can use unix sockets
|
||||||
with open(self.common.get_resource_path('torrc_template')) as f:
|
torrc_template += 'ControlSocket {{control_socket}}\n'
|
||||||
torrc_template = f.read()
|
|
||||||
self.tor_control_port = None
|
self.tor_control_port = None
|
||||||
self.tor_control_socket = os.path.join(self.tor_data_directory.name, 'control_socket')
|
self.tor_control_socket = os.path.join(self.tor_data_directory.name, 'control_socket')
|
||||||
self.tor_cookie_auth_file = os.path.join(self.tor_data_directory.name, 'cookie')
|
|
||||||
try:
|
|
||||||
self.tor_socks_port = self.common.get_available_port(1000, 65535)
|
|
||||||
except:
|
|
||||||
raise OSError(strings._('no_available_port'))
|
|
||||||
self.tor_torrc = os.path.join(self.tor_data_directory.name, 'torrc')
|
|
||||||
|
|
||||||
torrc_template = torrc_template.replace('{{data_directory}}', self.tor_data_directory.name)
|
torrc_template = torrc_template.replace('{{data_directory}}', self.tor_data_directory.name)
|
||||||
torrc_template = torrc_template.replace('{{control_port}}', str(self.tor_control_port))
|
torrc_template = torrc_template.replace('{{control_port}}', str(self.tor_control_port))
|
||||||
@ -208,6 +208,7 @@ class Onion(object):
|
|||||||
torrc_template = torrc_template.replace('{{geo_ip_file}}', self.tor_geo_ip_file_path)
|
torrc_template = torrc_template.replace('{{geo_ip_file}}', self.tor_geo_ip_file_path)
|
||||||
torrc_template = torrc_template.replace('{{geo_ipv6_file}}', self.tor_geo_ipv6_file_path)
|
torrc_template = torrc_template.replace('{{geo_ipv6_file}}', self.tor_geo_ipv6_file_path)
|
||||||
torrc_template = torrc_template.replace('{{socks_port}}', str(self.tor_socks_port))
|
torrc_template = torrc_template.replace('{{socks_port}}', str(self.tor_socks_port))
|
||||||
|
|
||||||
with open(self.tor_torrc, 'w') as f:
|
with open(self.tor_torrc, 'w') as f:
|
||||||
f.write(torrc_template)
|
f.write(torrc_template)
|
||||||
|
|
||||||
@ -246,7 +247,7 @@ class Onion(object):
|
|||||||
|
|
||||||
# Connect to the controller
|
# Connect to the controller
|
||||||
try:
|
try:
|
||||||
if self.common.platform == 'Windows':
|
if self.common.platform == 'Windows' or self.common.platform == "Darwin":
|
||||||
self.c = Controller.from_port(port=self.tor_control_port)
|
self.c = Controller.from_port(port=self.tor_control_port)
|
||||||
self.c.authenticate()
|
self.c.authenticate()
|
||||||
else:
|
else:
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
DataDirectory {{data_directory}}
|
DataDirectory {{data_directory}}
|
||||||
SocksPort {{socks_port}}
|
SocksPort {{socks_port}}
|
||||||
ControlSocket {{control_socket}}
|
|
||||||
CookieAuthentication 1
|
CookieAuthentication 1
|
||||||
CookieAuthFile {{cookie_auth_file}}
|
CookieAuthFile {{cookie_auth_file}}
|
||||||
AvoidDiskWrites 1
|
AvoidDiskWrites 1
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
DataDirectory {{data_directory}}
|
|
||||||
SocksPort {{socks_port}}
|
|
||||||
ControlPort {{control_port}}
|
|
||||||
CookieAuthentication 1
|
|
||||||
CookieAuthFile {{cookie_auth_file}}
|
|
||||||
AvoidDiskWrites 1
|
|
||||||
Log notice stdout
|
|
||||||
GeoIPFile {{geo_ip_file}}
|
|
||||||
GeoIPv6File {{geo_ipv6_file}}
|
|
Loading…
Reference in New Issue
Block a user