Mercurial > prosody-modules
annotate mod_onions/mod_onions.lua @ 5406:b86d80e21c60
mod_http_oauth2: Validate consistency of response and grant types
Ensure that these correlated fields make sense per RFC 7591 ยง 2.1, even
though we currently only check the response type during authorization.
This could probably all be deleted if (when!) we remove the implicit
grant, since then these things don't make any sense anymore.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 02 May 2023 16:34:31 +0200 |
parents | fa415cd9eeca |
children |
rev | line source |
---|---|
1780
b3e3ad35391a
mod_onions: Small fixes making bounce_sendq match mod_s2s again.
Thijs Alkemade <me@thijsalkema.de>
parents:
1617
diff
changeset
|
1 local prosody = prosody; |
b3e3ad35391a
mod_onions: Small fixes making bounce_sendq match mod_s2s again.
Thijs Alkemade <me@thijsalkema.de>
parents:
1617
diff
changeset
|
2 local core_process_stanza = prosody.core_process_stanza; |
b3e3ad35391a
mod_onions: Small fixes making bounce_sendq match mod_s2s again.
Thijs Alkemade <me@thijsalkema.de>
parents:
1617
diff
changeset
|
3 |
2880
05ebe377fc90
mod_onions: Use net.server API for creating a new connection instead of duplicating socket creation
Kim Alvefur <zash@zash.se>
parents:
2873
diff
changeset
|
4 local addclient = require "net.server".addclient; |
1060
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
5 local s2s_new_outgoing = require "core.s2smanager".new_outgoing; |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
6 local initialize_filters = require "util.filters".initialize; |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
7 local st = require "util.stanza"; |
1071
8f59b45fe6a7
mod_onions: Copy the code to find the bit module from mod_websockets.
Thijs Alkemade <me@thijsalkema.de>
parents:
1061
diff
changeset
|
8 |
1060
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
9 local portmanager = require "core.portmanager"; |
1071
8f59b45fe6a7
mod_onions: Copy the code to find the bit module from mod_websockets.
Thijs Alkemade <me@thijsalkema.de>
parents:
1061
diff
changeset
|
10 |
8f59b45fe6a7
mod_onions: Copy the code to find the bit module from mod_websockets.
Thijs Alkemade <me@thijsalkema.de>
parents:
1061
diff
changeset
|
11 local softreq = require "util.dependencies".softreq; |
8f59b45fe6a7
mod_onions: Copy the code to find the bit module from mod_websockets.
Thijs Alkemade <me@thijsalkema.de>
parents:
1061
diff
changeset
|
12 |
4946
fa415cd9eeca
mod_onions: Fix for bitop with Lua 5.4
moparisthebest <admin@moparisthebest.com>
parents:
4908
diff
changeset
|
13 local bit = assert(softreq "bit" or softreq "bit32" or softreq "util.bitcompat", "No bit module found. See https://prosody.im/doc/depends#bitop"); |
1071
8f59b45fe6a7
mod_onions: Copy the code to find the bit module from mod_websockets.
Thijs Alkemade <me@thijsalkema.de>
parents:
1061
diff
changeset
|
14 |
8f59b45fe6a7
mod_onions: Copy the code to find the bit module from mod_websockets.
Thijs Alkemade <me@thijsalkema.de>
parents:
1061
diff
changeset
|
15 local band = bit.band; |
8f59b45fe6a7
mod_onions: Copy the code to find the bit module from mod_websockets.
Thijs Alkemade <me@thijsalkema.de>
parents:
1061
diff
changeset
|
16 local rshift = bit.rshift; |
8f59b45fe6a7
mod_onions: Copy the code to find the bit module from mod_websockets.
Thijs Alkemade <me@thijsalkema.de>
parents:
1061
diff
changeset
|
17 local lshift = bit.lshift; |
8f59b45fe6a7
mod_onions: Copy the code to find the bit module from mod_websockets.
Thijs Alkemade <me@thijsalkema.de>
parents:
1061
diff
changeset
|
18 |
1060
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
19 local byte = string.byte; |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
20 local c = string.char; |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
21 |
1617
e0d8caffa209
mod_onions: Depend on mod_s2s to avoid a traceback when loaded before mod_s2s
Matthew Wild <mwild1@gmail.com>
parents:
1468
diff
changeset
|
22 module:depends("s2s"); |
e0d8caffa209
mod_onions: Depend on mod_s2s to avoid a traceback when loaded before mod_s2s
Matthew Wild <mwild1@gmail.com>
parents:
1468
diff
changeset
|
23 |
2344
c928b7ac75b7
mod_onions: Use typed config API
Kim Alvefur <zash@zash.se>
parents:
2306
diff
changeset
|
24 local proxy_ip = module:get_option_string("onions_socks5_host", "127.0.0.1"); |
c928b7ac75b7
mod_onions: Use typed config API
Kim Alvefur <zash@zash.se>
parents:
2306
diff
changeset
|
25 local proxy_port = module:get_option_number("onions_socks5_port", 9050); |
c928b7ac75b7
mod_onions: Use typed config API
Kim Alvefur <zash@zash.se>
parents:
2306
diff
changeset
|
26 local forbid_else = module:get_option_boolean("onions_only", false); |
c928b7ac75b7
mod_onions: Use typed config API
Kim Alvefur <zash@zash.se>
parents:
2306
diff
changeset
|
27 local torify_all = module:get_option_boolean("onions_tor_all", false); |
c928b7ac75b7
mod_onions: Use typed config API
Kim Alvefur <zash@zash.se>
parents:
2306
diff
changeset
|
28 local onions_map = module:get_option("onions_map", {}); |
1060
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
29 |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
30 local sessions = module:shared("sessions"); |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
31 |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
32 -- The socks5listener handles connection while still connecting to the proxy, |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
33 -- then it hands them over to the normal listener (in mod_s2s) |
1061
f4031e7ccec1
mod_onions: The SOCKS5 port is now a string, as it should be. Added a boolean option onions_tor_all to pass all s2s traffic through Tor.
Thijs Alkemade <me@thijsalkema.de>
parents:
1060
diff
changeset
|
34 local socks5listener = { default_port = proxy_port, default_mode = "*a", default_interface = "*" }; |
1060
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
35 |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
36 local function socks5_connect_sent(conn, data) |
1343
7dbde05b48a9
all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
1299
diff
changeset
|
37 |
1060
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
38 local session = sessions[conn]; |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
39 |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
40 if #data < 5 then |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
41 session.socks5_buffer = data; |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
42 return; |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
43 end |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
44 |
2704
5ab27d3741b4
mod_onions: Make variable local
Kim Alvefur <zash@zash.se>
parents:
2703
diff
changeset
|
45 local request_status = byte(data, 2); |
1060
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
46 |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
47 if not request_status == 0x00 then |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
48 module:log("debug", "Failed to connect to the SOCKS5 proxy. :("); |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
49 session:close(false); |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
50 return; |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
51 end |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
52 |
2873
9e693d433a41
mod_onions: Fix typo [codespell]
Kim Alvefur <zash@zash.se>
parents:
2704
diff
changeset
|
53 module:log("debug", "Successfully connected to SOCKS5 proxy."); |
1343
7dbde05b48a9
all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
1299
diff
changeset
|
54 |
1060
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
55 local response = byte(data, 4); |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
56 |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
57 if response == 0x01 then |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
58 if #data < 10 then |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
59 -- let's try again when we have enough |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
60 session.socks5_buffer = data; |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
61 return; |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
62 end |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
63 |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
64 -- this means the server tells us to connect on an IPv4 address |
2345
2df32ac11b31
mod_onions: Reduce line count for redirect check
Kim Alvefur <zash@zash.se>
parents:
2344
diff
changeset
|
65 local ip = string.format("%d.%d.%d.%d", byte(data, 5,8)); |
1071
8f59b45fe6a7
mod_onions: Copy the code to find the bit module from mod_websockets.
Thijs Alkemade <me@thijsalkema.de>
parents:
1061
diff
changeset
|
66 local port = band(byte(data, 9), lshift(byte(data, 10), 8)); |
2345
2df32ac11b31
mod_onions: Reduce line count for redirect check
Kim Alvefur <zash@zash.se>
parents:
2344
diff
changeset
|
67 module:log("debug", "Should connect to: %s:%d", ip, port); |
1060
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
68 |
2345
2df32ac11b31
mod_onions: Reduce line count for redirect check
Kim Alvefur <zash@zash.se>
parents:
2344
diff
changeset
|
69 if not (ip == "0.0.0.0" and port == 0) then |
1060
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
70 module:log("debug", "The SOCKS5 proxy tells us to connect to a different IP, don't know how. :("); |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
71 session:close(false); |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
72 return; |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
73 end |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
74 |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
75 -- Now the real s2s listener can take over the connection. |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
76 local listener = portmanager.get_service("s2s").listener; |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
77 |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
78 module:log("debug", "SOCKS5 done, handing over listening to "..tostring(listener)); |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
79 |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
80 session.socks5_handler = nil; |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
81 session.socks5_buffer = nil; |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
82 |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
83 local w, log = conn.send, session.log; |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
84 |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
85 local filter = initialize_filters(session); |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
86 |
1467
f10a3a5ba28f
mod_onions: Set the stream version to 1.0 on onionized streams, so TLS is offered.
Thijs Alkemade <me@thijsalkema.de>
parents:
1343
diff
changeset
|
87 session.version = 1; |
f10a3a5ba28f
mod_onions: Set the stream version to 1.0 on onionized streams, so TLS is offered.
Thijs Alkemade <me@thijsalkema.de>
parents:
1343
diff
changeset
|
88 |
1060
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
89 session.sends2s = function (t) |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
90 log("debug", "sending (s2s over socks5): %s", (t.top_tag and t:top_tag()) or t:match("^[^>]*>?")); |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
91 if t.name then |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
92 t = filter("stanzas/out", t); |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
93 end |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
94 if t then |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
95 t = filter("bytes/out", tostring(t)); |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
96 if t then |
1299
a7d6c6d2c7b5
mod_onions: Accepted patch that should fix problems when using libevent.
Thijs Alkemade <me@thijsalkema.de>
parents:
1071
diff
changeset
|
97 return conn:write(tostring(t)); |
1060
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
98 end |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
99 end |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
100 end |
1343
7dbde05b48a9
all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
1299
diff
changeset
|
101 |
1060
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
102 session.open_stream = function () |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
103 session.sends2s(st.stanza("stream:stream", { |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
104 xmlns='jabber:server', ["xmlns:db"]='jabber:server:dialback', |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
105 ["xmlns:stream"]='http://etherx.jabber.org/streams', |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
106 from=session.from_host, to=session.to_host, version='1.0', ["xml:lang"]='en'}):top_tag()); |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
107 end |
1343
7dbde05b48a9
all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
1299
diff
changeset
|
108 |
1060
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
109 conn.setlistener(conn, listener); |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
110 |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
111 listener.register_outgoing(conn, session); |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
112 |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
113 listener.onconnect(conn); |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
114 end |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
115 end |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
116 |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
117 local function socks5_handshake_sent(conn, data) |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
118 |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
119 local session = sessions[conn]; |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
120 |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
121 if #data < 2 then |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
122 session.socks5_buffer = data; |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
123 return; |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
124 end |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
125 |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
126 -- version, method |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
127 local request_status = byte(data, 2); |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
128 |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
129 module:log("debug", "SOCKS version: "..byte(data, 1)); |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
130 module:log("debug", "Response: "..request_status); |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
131 |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
132 if not request_status == 0x00 then |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
133 module:log("debug", "Failed to connect to the SOCKS5 proxy. :( It seems to require authentication."); |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
134 session:close(false); |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
135 return; |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
136 end |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
137 |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
138 module:log("debug", "Sending connect message."); |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
139 |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
140 -- version 5, connect, (reserved), type: domainname, (length, hostname), port |
1299
a7d6c6d2c7b5
mod_onions: Accepted patch that should fix problems when using libevent.
Thijs Alkemade <me@thijsalkema.de>
parents:
1071
diff
changeset
|
141 conn:write(c(5) .. c(1) .. c(0) .. c(3) .. c(#session.socks5_to) .. session.socks5_to); |
a7d6c6d2c7b5
mod_onions: Accepted patch that should fix problems when using libevent.
Thijs Alkemade <me@thijsalkema.de>
parents:
1071
diff
changeset
|
142 conn:write(c(rshift(session.socks5_port, 8)) .. c(band(session.socks5_port, 0xff))); |
1060
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
143 |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
144 session.socks5_handler = socks5_connect_sent; |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
145 end |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
146 |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
147 function socks5listener.onconnect(conn) |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
148 module:log("debug", "Connected to SOCKS5 proxy, sending SOCKS5 handshake."); |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
149 |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
150 -- Socks version 5, 1 method, no auth |
1299
a7d6c6d2c7b5
mod_onions: Accepted patch that should fix problems when using libevent.
Thijs Alkemade <me@thijsalkema.de>
parents:
1071
diff
changeset
|
151 conn:write(c(5) .. c(1) .. c(0)); |
1343
7dbde05b48a9
all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
1299
diff
changeset
|
152 |
1060
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
153 sessions[conn].socks5_handler = socks5_handshake_sent; |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
154 end |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
155 |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
156 function socks5listener.register_outgoing(conn, session) |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
157 session.direction = "outgoing"; |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
158 sessions[conn] = session; |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
159 end |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
160 |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
161 function socks5listener.ondisconnect(conn, err) |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
162 sessions[conn] = nil; |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
163 end |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
164 |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
165 function socks5listener.onincoming(conn, data) |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
166 local session = sessions[conn]; |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
167 |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
168 if session.socks5_buffer then |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
169 data = session.socks5_buffer .. data; |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
170 end |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
171 |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
172 if session.socks5_handler then |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
173 session.socks5_handler(conn, data); |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
174 end |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
175 end |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
176 |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
177 local function connect_socks5(host_session, connect_host, connect_port) |
1343
7dbde05b48a9
all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
1299
diff
changeset
|
178 |
1060
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
179 module:log("debug", "Connecting to " .. connect_host .. ":" .. connect_port); |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
180 |
1781
12ac88940fe3
mod_onions: Now allows configuration of an "onions_map", allowing administrator to manually specify alternate hidden services for clearnet addresses.
Thijs Alkemade <me@thijsalkema.de>
parents:
1780
diff
changeset
|
181 -- this is not necessarily the same as .to_host (it can be that this is from the onions_map) |
1060
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
182 host_session.socks5_to = connect_host; |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
183 host_session.socks5_port = connect_port; |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
184 |
2880
05ebe377fc90
mod_onions: Use net.server API for creating a new connection instead of duplicating socket creation
Kim Alvefur <zash@zash.se>
parents:
2873
diff
changeset
|
185 local conn = addclient(proxy_ip, proxy_port, socks5listener, "*a"); |
1060
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
186 |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
187 socks5listener.register_outgoing(conn, host_session); |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
188 |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
189 host_session.conn = conn; |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
190 end |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
191 |
1780
b3e3ad35391a
mod_onions: Small fixes making bounce_sendq match mod_s2s again.
Thijs Alkemade <me@thijsalkema.de>
parents:
1617
diff
changeset
|
192 local bouncy_stanzas = { message = true, presence = true, iq = true }; |
1060
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
193 local function bounce_sendq(session, reason) |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
194 local sendq = session.sendq; |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
195 if not sendq then return; end |
1780
b3e3ad35391a
mod_onions: Small fixes making bounce_sendq match mod_s2s again.
Thijs Alkemade <me@thijsalkema.de>
parents:
1617
diff
changeset
|
196 session.log("info", "Sending error replies for "..#sendq.." queued stanzas because of failed outgoing connection to "..tostring(session.to_host)); |
1060
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
197 local dummy = { |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
198 type = "s2sin"; |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
199 send = function(s) |
2881
824b0d7fa883
mod_onions: Fix unqualified use of debug.traceback
Kim Alvefur <zash@zash.se>
parents:
2880
diff
changeset
|
200 (session.log or log)("error", "Replying to to an s2s error reply, please report this! Traceback: %s", debug.traceback()); |
1060
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
201 end; |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
202 dummy = true; |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
203 }; |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
204 for i, data in ipairs(sendq) do |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
205 local reply = data[2]; |
1780
b3e3ad35391a
mod_onions: Small fixes making bounce_sendq match mod_s2s again.
Thijs Alkemade <me@thijsalkema.de>
parents:
1617
diff
changeset
|
206 if reply and not(reply.attr.xmlns) and bouncy_stanzas[reply.name] then |
1060
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
207 reply.attr.type = "error"; |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
208 reply:tag("error", {type = "cancel"}) |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
209 :tag("remote-server-not-found", {xmlns = "urn:ietf:params:xml:ns:xmpp-stanzas"}):up(); |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
210 if reason then |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
211 reply:tag("text", {xmlns = "urn:ietf:params:xml:ns:xmpp-stanzas"}) |
1780
b3e3ad35391a
mod_onions: Small fixes making bounce_sendq match mod_s2s again.
Thijs Alkemade <me@thijsalkema.de>
parents:
1617
diff
changeset
|
212 :text("Server-to-server connection failed: "..reason):up(); |
1060
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
213 end |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
214 core_process_stanza(dummy, reply); |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
215 end |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
216 sendq[i] = nil; |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
217 end |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
218 session.sendq = nil; |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
219 end |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
220 -- Try to intercept anything to *.onion |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
221 local function route_to_onion(event) |
1468
cf32265eb4c7
mod_onions: Actually define the variable "stanza" to contain "event.stanza", fixing problems of stanzas being dropped for outgoing connections.
Thijs Alkemade <me@thijsalkema.de>
parents:
1467
diff
changeset
|
222 local stanza = event.stanza; |
1781
12ac88940fe3
mod_onions: Now allows configuration of an "onions_map", allowing administrator to manually specify alternate hidden services for clearnet addresses.
Thijs Alkemade <me@thijsalkema.de>
parents:
1780
diff
changeset
|
223 local to_host = event.to_host; |
12ac88940fe3
mod_onions: Now allows configuration of an "onions_map", allowing administrator to manually specify alternate hidden services for clearnet addresses.
Thijs Alkemade <me@thijsalkema.de>
parents:
1780
diff
changeset
|
224 local onion_host = nil; |
12ac88940fe3
mod_onions: Now allows configuration of an "onions_map", allowing administrator to manually specify alternate hidden services for clearnet addresses.
Thijs Alkemade <me@thijsalkema.de>
parents:
1780
diff
changeset
|
225 local onion_port = nil; |
1060
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
226 |
2304
a881494238af
mod_onions: Remove capture of final period (stripped by util.jid)
Kim Alvefur <zash@zash.se>
parents:
2303
diff
changeset
|
227 if not to_host:find("%.onion$") then |
1781
12ac88940fe3
mod_onions: Now allows configuration of an "onions_map", allowing administrator to manually specify alternate hidden services for clearnet addresses.
Thijs Alkemade <me@thijsalkema.de>
parents:
1780
diff
changeset
|
228 if onions_map[to_host] then |
12ac88940fe3
mod_onions: Now allows configuration of an "onions_map", allowing administrator to manually specify alternate hidden services for clearnet addresses.
Thijs Alkemade <me@thijsalkema.de>
parents:
1780
diff
changeset
|
229 if type(onions_map[to_host]) == "string" then |
1910
720b291cb340
mod_onions: Patch from David Goulet: Fix onions_map when the target is a string.
Thijs Alkemade <me@thijsalkema.de>
parents:
1781
diff
changeset
|
230 onion_host = onions_map[to_host]; |
1781
12ac88940fe3
mod_onions: Now allows configuration of an "onions_map", allowing administrator to manually specify alternate hidden services for clearnet addresses.
Thijs Alkemade <me@thijsalkema.de>
parents:
1780
diff
changeset
|
231 else |
12ac88940fe3
mod_onions: Now allows configuration of an "onions_map", allowing administrator to manually specify alternate hidden services for clearnet addresses.
Thijs Alkemade <me@thijsalkema.de>
parents:
1780
diff
changeset
|
232 onion_host = onions_map[to_host].host; |
12ac88940fe3
mod_onions: Now allows configuration of an "onions_map", allowing administrator to manually specify alternate hidden services for clearnet addresses.
Thijs Alkemade <me@thijsalkema.de>
parents:
1780
diff
changeset
|
233 onion_port = onions_map[to_host].port; |
12ac88940fe3
mod_onions: Now allows configuration of an "onions_map", allowing administrator to manually specify alternate hidden services for clearnet addresses.
Thijs Alkemade <me@thijsalkema.de>
parents:
1780
diff
changeset
|
234 end |
12ac88940fe3
mod_onions: Now allows configuration of an "onions_map", allowing administrator to manually specify alternate hidden services for clearnet addresses.
Thijs Alkemade <me@thijsalkema.de>
parents:
1780
diff
changeset
|
235 elseif forbid_else then |
1780
b3e3ad35391a
mod_onions: Small fixes making bounce_sendq match mod_s2s again.
Thijs Alkemade <me@thijsalkema.de>
parents:
1617
diff
changeset
|
236 module:log("debug", event.to_host .. " is not an onion. Blocking it."); |
1060
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
237 return false; |
1061
f4031e7ccec1
mod_onions: The SOCKS5 port is now a string, as it should be. Added a boolean option onions_tor_all to pass all s2s traffic through Tor.
Thijs Alkemade <me@thijsalkema.de>
parents:
1060
diff
changeset
|
238 elseif not torify_all then |
1060
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
239 return; |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
240 end |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
241 end |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
242 |
1781
12ac88940fe3
mod_onions: Now allows configuration of an "onions_map", allowing administrator to manually specify alternate hidden services for clearnet addresses.
Thijs Alkemade <me@thijsalkema.de>
parents:
1780
diff
changeset
|
243 module:log("debug", "Onion routing something to ".. to_host); |
1060
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
244 |
1781
12ac88940fe3
mod_onions: Now allows configuration of an "onions_map", allowing administrator to manually specify alternate hidden services for clearnet addresses.
Thijs Alkemade <me@thijsalkema.de>
parents:
1780
diff
changeset
|
245 if hosts[event.from_host].s2sout[to_host] then |
1060
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
246 return; |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
247 end |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
248 |
1781
12ac88940fe3
mod_onions: Now allows configuration of an "onions_map", allowing administrator to manually specify alternate hidden services for clearnet addresses.
Thijs Alkemade <me@thijsalkema.de>
parents:
1780
diff
changeset
|
249 local host_session = s2s_new_outgoing(event.from_host, to_host); |
1060
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
250 |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
251 host_session.bounce_sendq = bounce_sendq; |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
252 host_session.sendq = { {tostring(stanza), stanza.attr and stanza.attr.type ~= "error" and stanza.attr.type ~= "result" and st.reply(stanza)} }; |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
253 |
1781
12ac88940fe3
mod_onions: Now allows configuration of an "onions_map", allowing administrator to manually specify alternate hidden services for clearnet addresses.
Thijs Alkemade <me@thijsalkema.de>
parents:
1780
diff
changeset
|
254 hosts[event.from_host].s2sout[to_host] = host_session; |
1060
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
255 |
1781
12ac88940fe3
mod_onions: Now allows configuration of an "onions_map", allowing administrator to manually specify alternate hidden services for clearnet addresses.
Thijs Alkemade <me@thijsalkema.de>
parents:
1780
diff
changeset
|
256 connect_socks5(host_session, onion_host or to_host, onion_port or 5269); |
1060
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
257 |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
258 return true; |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
259 end |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
260 |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
261 module:log("debug", "Onions ready and loaded"); |
25b83ed7838a
mod_onions: Added mod_onions. This module allows Prosody to make s2s connections to Tor hidden services.
Thijs Alkemade <me@thijsalkema.de>
parents:
diff
changeset
|
262 |
2305
7db4d3f5fb73
mod_onions: Hook event using moduleapi
Kim Alvefur <zash@zash.se>
parents:
2304
diff
changeset
|
263 module:hook("route/remote", route_to_onion, 200); |
2306
ad40c094e7d7
mod_onions: Prevent s2s_secure_auth policy enforcement from rejecting .onion connections
Kim Alvefur <zash@zash.se>
parents:
2305
diff
changeset
|
264 |
ad40c094e7d7
mod_onions: Prevent s2s_secure_auth policy enforcement from rejecting .onion connections
Kim Alvefur <zash@zash.se>
parents:
2305
diff
changeset
|
265 module:hook_global("s2s-check-certificate", function (event) |
ad40c094e7d7
mod_onions: Prevent s2s_secure_auth policy enforcement from rejecting .onion connections
Kim Alvefur <zash@zash.se>
parents:
2305
diff
changeset
|
266 local host = event.host; |
ad40c094e7d7
mod_onions: Prevent s2s_secure_auth policy enforcement from rejecting .onion connections
Kim Alvefur <zash@zash.se>
parents:
2305
diff
changeset
|
267 if host and host:find("%.onion$") then |
4908
44be2c6087f3
mod_onions: Add comment explaining s2s-check-certificate handler
Matthew Wild <mwild1@gmail.com>
parents:
2881
diff
changeset
|
268 -- This cancels the event chain without reporting any cert |
44be2c6087f3
mod_onions: Add comment explaining s2s-check-certificate handler
Matthew Wild <mwild1@gmail.com>
parents:
2881
diff
changeset
|
269 -- validation results. The connection will typically proceed |
44be2c6087f3
mod_onions: Add comment explaining s2s-check-certificate handler
Matthew Wild <mwild1@gmail.com>
parents:
2881
diff
changeset
|
270 -- to auth using dialback. |
2306
ad40c094e7d7
mod_onions: Prevent s2s_secure_auth policy enforcement from rejecting .onion connections
Kim Alvefur <zash@zash.se>
parents:
2305
diff
changeset
|
271 return true; |
ad40c094e7d7
mod_onions: Prevent s2s_secure_auth policy enforcement from rejecting .onion connections
Kim Alvefur <zash@zash.se>
parents:
2305
diff
changeset
|
272 end |
ad40c094e7d7
mod_onions: Prevent s2s_secure_auth policy enforcement from rejecting .onion connections
Kim Alvefur <zash@zash.se>
parents:
2305
diff
changeset
|
273 end); |
ad40c094e7d7
mod_onions: Prevent s2s_secure_auth policy enforcement from rejecting .onion connections
Kim Alvefur <zash@zash.se>
parents:
2305
diff
changeset
|
274 |