onionshare_cli 2.6.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- onionshare_cli/__init__.py +538 -0
- onionshare_cli/censorship.py +311 -0
- onionshare_cli/common.py +624 -0
- onionshare_cli/meek.py +199 -0
- onionshare_cli/mode_settings.py +150 -0
- onionshare_cli/onion.py +964 -0
- onionshare_cli/onionshare.py +91 -0
- onionshare_cli/resources/static/css/style.css +432 -0
- onionshare_cli/resources/static/img/ajax.gif +0 -0
- onionshare_cli/resources/static/img/favicon.ico +0 -0
- onionshare_cli/resources/static/img/logo.png +0 -0
- onionshare_cli/resources/static/img/logo_large.png +0 -0
- onionshare_cli/resources/static/img/web_file.png +0 -0
- onionshare_cli/resources/static/img/web_folder.png +0 -0
- onionshare_cli/resources/static/js/chat.js +188 -0
- onionshare_cli/resources/static/js/jquery-3.5.1.min.js +2 -0
- onionshare_cli/resources/static/js/receive.js +141 -0
- onionshare_cli/resources/static/js/send.js +79 -0
- onionshare_cli/resources/static/js/socket.io.js +9 -0
- onionshare_cli/resources/static/js/socket.io.min.js +7 -0
- onionshare_cli/resources/templates/403.html +21 -0
- onionshare_cli/resources/templates/404.html +21 -0
- onionshare_cli/resources/templates/405.html +21 -0
- onionshare_cli/resources/templates/500.html +21 -0
- onionshare_cli/resources/templates/chat.html +47 -0
- onionshare_cli/resources/templates/denied.html +14 -0
- onionshare_cli/resources/templates/listing.html +60 -0
- onionshare_cli/resources/templates/receive.html +66 -0
- onionshare_cli/resources/templates/send.html +70 -0
- onionshare_cli/resources/templates/thankyou.html +27 -0
- onionshare_cli/resources/torrc_template +12 -0
- onionshare_cli/resources/torrc_template-meek_lite_azure +2 -0
- onionshare_cli/resources/torrc_template-obfs4 +12 -0
- onionshare_cli/resources/torrc_template-snowflake +3 -0
- onionshare_cli/resources/version.txt +1 -0
- onionshare_cli/resources/wordlist.txt +7776 -0
- onionshare_cli/settings.py +209 -0
- onionshare_cli/web/__init__.py +21 -0
- onionshare_cli/web/chat_mode.py +190 -0
- onionshare_cli/web/receive_mode.py +630 -0
- onionshare_cli/web/send_base_mode.py +360 -0
- onionshare_cli/web/share_mode.py +599 -0
- onionshare_cli/web/web.py +409 -0
- onionshare_cli/web/website_mode.py +122 -0
- onionshare_cli-2.6.1.dist-info/METADATA +44 -0
- onionshare_cli-2.6.1.dist-info/RECORD +48 -0
- onionshare_cli-2.6.1.dist-info/WHEEL +4 -0
- onionshare_cli-2.6.1.dist-info/entry_points.txt +3 -0
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
OnionShare | https://onionshare.org/
|
|
4
|
+
|
|
5
|
+
Copyright (C) 2014-2022 Micah Lee, et al. <micah@micahflee.com>
|
|
6
|
+
|
|
7
|
+
This program is free software: you can redistribute it and/or modify
|
|
8
|
+
it under the terms of the GNU General Public License as published by
|
|
9
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
10
|
+
(at your option) any later version.
|
|
11
|
+
|
|
12
|
+
This program is distributed in the hope that it will be useful,
|
|
13
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15
|
+
GNU General Public License for more details.
|
|
16
|
+
|
|
17
|
+
You should have received a copy of the GNU General Public License
|
|
18
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
19
|
+
"""
|
|
20
|
+
import requests
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class CensorshipCircumventionError(Exception):
|
|
24
|
+
"""
|
|
25
|
+
There was a problem connecting to the Tor CensorshipCircumvention API.
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class CensorshipCircumvention(object):
|
|
30
|
+
"""
|
|
31
|
+
Connect to the Tor Moat APIs to retrieve censorship
|
|
32
|
+
circumvention recommendations or the latest bridges.
|
|
33
|
+
|
|
34
|
+
We support reaching this API over Tor, or Meek
|
|
35
|
+
(domain fronting) if Tor is not connected.
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
def __init__(self, common, meek=None, onion=None):
|
|
39
|
+
"""
|
|
40
|
+
Set up the CensorshipCircumvention object to hold
|
|
41
|
+
common and meek objects.
|
|
42
|
+
"""
|
|
43
|
+
self.common = common
|
|
44
|
+
self.common.log("CensorshipCircumvention", "__init__")
|
|
45
|
+
self.api_proxies = {}
|
|
46
|
+
if meek:
|
|
47
|
+
self.meek = meek
|
|
48
|
+
self.common.log(
|
|
49
|
+
"CensorshipCircumvention",
|
|
50
|
+
"__init__",
|
|
51
|
+
"Using Meek with CensorshipCircumvention API",
|
|
52
|
+
)
|
|
53
|
+
self.api_proxies = self.meek.meek_proxies
|
|
54
|
+
if onion:
|
|
55
|
+
self.onion = onion
|
|
56
|
+
if not self.onion.is_authenticated:
|
|
57
|
+
return False
|
|
58
|
+
else:
|
|
59
|
+
self.common.log(
|
|
60
|
+
"CensorshipCircumvention",
|
|
61
|
+
"__init__",
|
|
62
|
+
"Using Tor with CensorshipCircumvention API",
|
|
63
|
+
)
|
|
64
|
+
(socks_address, socks_port) = self.onion.get_tor_socks_port()
|
|
65
|
+
self.api_proxies = {
|
|
66
|
+
"http": f"socks5h://{socks_address}:{socks_port}",
|
|
67
|
+
"https": f"socks5h://{socks_address}:{socks_port}",
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
def request_map(self, country=False):
|
|
71
|
+
"""
|
|
72
|
+
Retrieves the Circumvention map from Tor Project and store it
|
|
73
|
+
locally for further look-ups if required.
|
|
74
|
+
|
|
75
|
+
Optionally pass a country code in order to get recommended settings
|
|
76
|
+
just for that country.
|
|
77
|
+
|
|
78
|
+
Note that this API endpoint doesn't return actual bridges,
|
|
79
|
+
it just returns the recommended bridge type countries.
|
|
80
|
+
"""
|
|
81
|
+
self.common.log("CensorshipCircumvention", "request_map", f"country={country}")
|
|
82
|
+
if not self.api_proxies:
|
|
83
|
+
return False
|
|
84
|
+
endpoint = "https://bridges.torproject.org/moat/circumvention/map"
|
|
85
|
+
data = {}
|
|
86
|
+
if country:
|
|
87
|
+
data = {"country": country}
|
|
88
|
+
|
|
89
|
+
try:
|
|
90
|
+
r = requests.post(
|
|
91
|
+
endpoint,
|
|
92
|
+
json=data,
|
|
93
|
+
headers={"Content-Type": "application/vnd.api+json"},
|
|
94
|
+
proxies=self.api_proxies,
|
|
95
|
+
)
|
|
96
|
+
if r.status_code != 200:
|
|
97
|
+
self.common.log(
|
|
98
|
+
"CensorshipCircumvention",
|
|
99
|
+
"request_map",
|
|
100
|
+
f"status_code={r.status_code}",
|
|
101
|
+
)
|
|
102
|
+
return False
|
|
103
|
+
|
|
104
|
+
result = r.json()
|
|
105
|
+
|
|
106
|
+
if "errors" in result:
|
|
107
|
+
self.common.log(
|
|
108
|
+
"CensorshipCircumvention",
|
|
109
|
+
"request_map",
|
|
110
|
+
f"errors={result['errors']}",
|
|
111
|
+
)
|
|
112
|
+
return False
|
|
113
|
+
|
|
114
|
+
return result
|
|
115
|
+
except requests.exceptions.RequestException as e:
|
|
116
|
+
raise CensorshipCircumventionError(e)
|
|
117
|
+
|
|
118
|
+
def request_settings(self, country=False, transports=False):
|
|
119
|
+
"""
|
|
120
|
+
Retrieves the Circumvention Settings from Tor Project, which
|
|
121
|
+
will return recommended settings based on the country code of
|
|
122
|
+
the requesting IP.
|
|
123
|
+
|
|
124
|
+
Optionally, a country code can be specified in order to override
|
|
125
|
+
the IP detection.
|
|
126
|
+
|
|
127
|
+
Optionally, a list of transports can be specified in order to
|
|
128
|
+
return recommended settings for just that transport type.
|
|
129
|
+
"""
|
|
130
|
+
self.common.log(
|
|
131
|
+
"CensorshipCircumvention",
|
|
132
|
+
"request_settings",
|
|
133
|
+
f"country={country}, transports={transports}",
|
|
134
|
+
)
|
|
135
|
+
if not self.api_proxies:
|
|
136
|
+
return False
|
|
137
|
+
endpoint = "https://bridges.torproject.org/moat/circumvention/settings"
|
|
138
|
+
data = {}
|
|
139
|
+
if country:
|
|
140
|
+
self.common.log(
|
|
141
|
+
"CensorshipCircumvention",
|
|
142
|
+
"request_settings",
|
|
143
|
+
f"Trying to obtain bridges for country={country}",
|
|
144
|
+
)
|
|
145
|
+
data = {"country": country}
|
|
146
|
+
if transports:
|
|
147
|
+
data.append({"transports": transports})
|
|
148
|
+
try:
|
|
149
|
+
r = requests.post(
|
|
150
|
+
endpoint,
|
|
151
|
+
json=data,
|
|
152
|
+
headers={"Content-Type": "application/vnd.api+json"},
|
|
153
|
+
proxies=self.api_proxies,
|
|
154
|
+
)
|
|
155
|
+
if r.status_code != 200:
|
|
156
|
+
self.common.log(
|
|
157
|
+
"CensorshipCircumvention",
|
|
158
|
+
"request_settings",
|
|
159
|
+
f"status_code={r.status_code}",
|
|
160
|
+
)
|
|
161
|
+
return False
|
|
162
|
+
|
|
163
|
+
result = r.json()
|
|
164
|
+
self.common.log(
|
|
165
|
+
"CensorshipCircumvention",
|
|
166
|
+
"request_settings",
|
|
167
|
+
f"result={result}",
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
if "errors" in result:
|
|
171
|
+
self.common.log(
|
|
172
|
+
"CensorshipCircumvention",
|
|
173
|
+
"request_settings",
|
|
174
|
+
f"errors={result['errors']}",
|
|
175
|
+
)
|
|
176
|
+
return False
|
|
177
|
+
|
|
178
|
+
# There are no settings - perhaps this country doesn't require censorship circumvention?
|
|
179
|
+
# This is not really an error, so we can just check if False and assume direct Tor
|
|
180
|
+
# connection will work.
|
|
181
|
+
if not "settings" in result or result["settings"] is None:
|
|
182
|
+
self.common.log(
|
|
183
|
+
"CensorshipCircumvention",
|
|
184
|
+
"request_settings",
|
|
185
|
+
"No settings found for this country",
|
|
186
|
+
)
|
|
187
|
+
return False
|
|
188
|
+
|
|
189
|
+
return result
|
|
190
|
+
except requests.exceptions.RequestException as e:
|
|
191
|
+
raise CensorshipCircumventionError(e)
|
|
192
|
+
|
|
193
|
+
def request_builtin_bridges(self):
|
|
194
|
+
"""
|
|
195
|
+
Retrieves the list of built-in bridges from the Tor Project.
|
|
196
|
+
"""
|
|
197
|
+
if not self.api_proxies:
|
|
198
|
+
return False
|
|
199
|
+
endpoint = "https://bridges.torproject.org/moat/circumvention/builtin"
|
|
200
|
+
try:
|
|
201
|
+
r = requests.post(
|
|
202
|
+
endpoint,
|
|
203
|
+
headers={"Content-Type": "application/vnd.api+json"},
|
|
204
|
+
proxies=self.api_proxies,
|
|
205
|
+
)
|
|
206
|
+
if r.status_code != 200:
|
|
207
|
+
self.common.log(
|
|
208
|
+
"CensorshipCircumvention",
|
|
209
|
+
"request_builtin_bridges",
|
|
210
|
+
f"status_code={r.status_code}",
|
|
211
|
+
)
|
|
212
|
+
return False
|
|
213
|
+
|
|
214
|
+
result = r.json()
|
|
215
|
+
|
|
216
|
+
if "errors" in result:
|
|
217
|
+
self.common.log(
|
|
218
|
+
"CensorshipCircumvention",
|
|
219
|
+
"request_builtin_bridges",
|
|
220
|
+
f"errors={result['errors']}",
|
|
221
|
+
)
|
|
222
|
+
return False
|
|
223
|
+
|
|
224
|
+
return result
|
|
225
|
+
except requests.exceptions.RequestException as e:
|
|
226
|
+
raise CensorshipCircumventionError(e)
|
|
227
|
+
|
|
228
|
+
def save_settings(self, settings, bridge_settings):
|
|
229
|
+
"""
|
|
230
|
+
Checks the bridges and saves them in settings.
|
|
231
|
+
"""
|
|
232
|
+
self.common.log(
|
|
233
|
+
"CensorshipCircumvention",
|
|
234
|
+
"save_settings",
|
|
235
|
+
f"bridge_settings: {bridge_settings}",
|
|
236
|
+
)
|
|
237
|
+
|
|
238
|
+
bridges_ok = False
|
|
239
|
+
self.settings = settings
|
|
240
|
+
|
|
241
|
+
# @TODO there might be several bridge types recommended.
|
|
242
|
+
# Should we attempt to iterate over each type if one of them fails to connect?
|
|
243
|
+
# But if so, how to stop it starting 3 separate Tor connection threads?
|
|
244
|
+
# for bridges in request_bridges["settings"]:
|
|
245
|
+
bridges = bridge_settings["settings"][0]["bridges"]
|
|
246
|
+
bridge_strings = bridges["bridge_strings"]
|
|
247
|
+
|
|
248
|
+
self.settings.set("bridges_type", "custom")
|
|
249
|
+
|
|
250
|
+
# Sanity check the bridges provided from the Tor API before saving
|
|
251
|
+
bridges_checked = self.common.check_bridges_valid(bridge_strings)
|
|
252
|
+
|
|
253
|
+
if bridges_checked:
|
|
254
|
+
self.settings.set("bridges_custom", "\n".join(bridges_checked))
|
|
255
|
+
bridges_ok = True
|
|
256
|
+
|
|
257
|
+
# If we got any good bridges, save them to settings and return.
|
|
258
|
+
if bridges_ok:
|
|
259
|
+
self.common.log(
|
|
260
|
+
"CensorshipCircumvention",
|
|
261
|
+
"save_settings",
|
|
262
|
+
"Saving settings with automatically-obtained bridges",
|
|
263
|
+
)
|
|
264
|
+
self.settings.set("bridges_enabled", True)
|
|
265
|
+
self.settings.save()
|
|
266
|
+
return True
|
|
267
|
+
else:
|
|
268
|
+
self.common.log(
|
|
269
|
+
"CensorshipCircumvention",
|
|
270
|
+
"save_settings",
|
|
271
|
+
"Could not use any of the obtained bridges.",
|
|
272
|
+
)
|
|
273
|
+
return False
|
|
274
|
+
|
|
275
|
+
def request_default_bridges(self):
|
|
276
|
+
"""
|
|
277
|
+
Retrieves the list of default fall-back bridges from the Tor Project.
|
|
278
|
+
|
|
279
|
+
These are intended for when no censorship settings were found for a
|
|
280
|
+
specific country, but maybe there was some connection issue anyway.
|
|
281
|
+
"""
|
|
282
|
+
if not self.api_proxies:
|
|
283
|
+
return False
|
|
284
|
+
endpoint = "https://bridges.torproject.org/moat/circumvention/defaults"
|
|
285
|
+
try:
|
|
286
|
+
r = requests.get(
|
|
287
|
+
endpoint,
|
|
288
|
+
headers={"Content-Type": "application/vnd.api+json"},
|
|
289
|
+
proxies=self.api_proxies,
|
|
290
|
+
)
|
|
291
|
+
if r.status_code != 200:
|
|
292
|
+
self.common.log(
|
|
293
|
+
"CensorshipCircumvention",
|
|
294
|
+
"request_default_bridges",
|
|
295
|
+
f"status_code={r.status_code}",
|
|
296
|
+
)
|
|
297
|
+
return False
|
|
298
|
+
|
|
299
|
+
result = r.json()
|
|
300
|
+
|
|
301
|
+
if "errors" in result:
|
|
302
|
+
self.common.log(
|
|
303
|
+
"CensorshipCircumvention",
|
|
304
|
+
"request_default_bridges",
|
|
305
|
+
f"errors={result['errors']}",
|
|
306
|
+
)
|
|
307
|
+
return False
|
|
308
|
+
|
|
309
|
+
return result
|
|
310
|
+
except requests.exceptions.RequestException as e:
|
|
311
|
+
raise CensorshipCircumventionError(e)
|