Mercurial > prosody-modules
annotate mod_onions/mod_onions.lua @ 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.
author | Thijs Alkemade <me@thijsalkema.de> |
---|---|
date | Mon, 10 Jun 2013 21:39:48 +0200 |
parents | 25b83ed7838a |
children | 8f59b45fe6a7 |
rev | line source |
---|---|
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
|
1 local wrapclient = require "net.server".wrapclient; |
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
|
2 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
|
3 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
|
4 local bit = require "bit32"; |
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 st = require "util.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
|
6 local portmanager = require "core.portmanager"; |
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 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
|
8 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
|
9 |
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
|
10 local proxy_ip = module:get_option("onions_socks5_host") or "127.0.0.1"; |
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
|
11 local proxy_port = module:get_option("onions_socks5_port") or 9050; |
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
|
12 local forbid_else = module:get_option("onions_only") or 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
|
13 local torify_all = module:get_option("onions_tor_all") or false; |
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
|
14 |
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
|
15 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
|
16 |
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
|
17 -- 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
|
18 -- 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
|
19 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
|
20 |
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 local function socks5_connect_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
|
22 |
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
|
23 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
|
24 |
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
|
25 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
|
26 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
|
27 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
|
28 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
|
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 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
|
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 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
|
33 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
|
34 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
|
35 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
|
36 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
|
37 |
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 module:log("debug", "Succesfully connected to 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
|
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 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
|
41 |
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 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
|
43 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
|
44 -- 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
|
45 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
|
46 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
|
47 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
|
48 |
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 -- this means the server tells us to connect on an IPv4 address |
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 local ip1 = byte(data, 5); |
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 local ip2 = byte(data, 6); |
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 local ip3 = byte(data, 7); |
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
|
53 local ip4 = byte(data, 8); |
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
|
54 local port = bit.band(byte(data, 9), bit.lshift(byte(data, 10), 8)); |
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 module:log("debug", "Should connect to: "..ip1.."."..ip2.."."..ip3.."."..ip4..":"..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
|
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 not (ip1 == 0 and ip2 == 0 and ip3 == 0 and ip4 == 0 and port == 0) 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 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
|
59 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
|
60 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
|
61 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
|
62 |
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 -- 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
|
64 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
|
65 |
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
|
66 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
|
67 |
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 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
|
69 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
|
70 |
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 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
|
72 |
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 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
|
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 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
|
76 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
|
77 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
|
78 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
|
79 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
|
80 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
|
81 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
|
82 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
|
83 return w(conn, 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
|
84 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
|
85 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
|
86 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
|
87 |
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
|
88 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
|
89 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
|
90 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
|
91 ["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
|
92 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
|
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 |
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 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
|
96 |
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
|
97 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
|
98 |
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 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
|
100 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
|
101 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
|
102 |
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 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
|
104 |
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 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
|
106 |
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 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
|
108 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
|
109 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
|
110 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
|
111 |
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 -- 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
|
113 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
|
114 |
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 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
|
116 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
|
117 |
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 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
|
119 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
|
120 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
|
121 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
|
122 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
|
123 |
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 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
|
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 5, connect, (reserved), type: domainname, (length, hostname), 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
|
127 conn:send(c(5) .. c(1) .. c(0) .. c(3) .. c(#session.socks5_to) .. session.socks5_to); |
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 conn:send(c(bit.rshift(session.socks5_port, 8)) .. c(bit.band(session.socks5_port, 0xff))); |
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 |
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 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
|
131 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
|
132 |
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 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
|
134 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
|
135 |
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 -- Socks version 5, 1 method, no auth |
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 conn:send(c(5) .. c(1) .. c(0)); |
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 |
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 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
|
140 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
|
141 |
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
|
142 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
|
143 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
|
144 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
|
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.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
|
148 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
|
149 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
|
150 |
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
|
151 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
|
152 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
|
153 |
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 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
|
155 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
|
156 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
|
157 |
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 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
|
159 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
|
160 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
|
161 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
|
162 |
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 local function connect_socks5(host_session, 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
|
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 local conn, handler = socket.tcp(); |
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 |
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 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
|
168 |
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 -- this is not necessarily the same as .to_host (it can be that this is a SRV record) |
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 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
|
171 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
|
172 |
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 conn:settimeout(0); |
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 |
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 local success, err = conn:connect(proxy_ip, proxy_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
|
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 conn = wrapclient(conn, connect_host, connect_port, socks5listener, "*a"); |
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
|
178 |
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 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
|
180 |
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
|
181 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
|
182 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
|
183 |
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 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
|
185 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
|
186 if not sendq then return; 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
|
187 session.log("info", "sending error replies for "..#sendq.." queued stanzas because of failed outgoing connection to "..tostring(session.to_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
|
188 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
|
189 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
|
190 send = function(s) |
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 (session.log or log)("error", "Replying to to an s2s error reply, please report this! Traceback: %s", traceback()); |
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
|
192 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
|
193 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
|
194 }; |
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 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
|
196 local reply = 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
|
197 if reply and not(reply.attr.xmlns) 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
|
198 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
|
199 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
|
200 :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
|
201 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
|
202 reply:tag("text", {xmlns = "urn:ietf:params:xml:ns:xmpp-stanzas"}) |
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 :text("Server-to-server connection failed: "..reason):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
|
204 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
|
205 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
|
206 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
|
207 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
|
208 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
|
209 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
|
210 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
|
211 |
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
|
212 -- 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
|
213 local function route_to_onion(event) |
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 |
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 if not event.to_host:find(".onion(.?)$") 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
|
216 if forbid_else 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
|
217 module:log("debug", event.to_host .. " is not an onion. Blocking it."); |
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 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
|
219 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
|
220 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
|
221 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
|
222 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
|
223 |
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
|
224 module:log("debug", "Onion routing something to ".. event.to_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
|
225 |
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 if hosts[event.from_host].s2sout[event.to_host] 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
|
227 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
|
228 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
|
229 |
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
|
230 local host_session = s2s_new_outgoing(event.from_host, event.to_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
|
231 |
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
|
232 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
|
233 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
|
234 |
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
|
235 hosts[event.from_host].s2sout[event.to_host] = 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
|
236 |
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 connect_socks5(host_session, event.to_host, 5269); |
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
|
238 |
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 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
|
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 |
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 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
|
243 |
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 hosts[module.host].events.add_handler("route/remote", route_to_onion, 200); |