util.x509: Only collect commonNames that pass idna
[prosody.git] / util / dependencies.lua
blob84e2dd5c61800e8eef1e3c2f0c99f7aeb73d5257
1 -- Prosody IM
2 -- Copyright (C) 2008-2010 Matthew Wild
3 -- Copyright (C) 2008-2010 Waqas Hussain
4 --
5 -- This project is MIT/X11 licensed. Please see the
6 -- COPYING file in the source package for more information.
7 --
9 local function softreq(...) local ok, lib = pcall(require, ...); if ok then return lib; else return nil, lib; end end
11 -- Required to be able to find packages installed with luarocks
12 if not softreq "luarocks.loader" then -- LuaRocks 2.x
13 softreq "luarocks.require"; -- LuaRocks <1.x
14 end
16 local function missingdep(name, sources, msg)
17 print("");
18 print("**************************");
19 print("Prosody was unable to find "..tostring(name));
20 print("This package can be obtained in the following ways:");
21 print("");
22 local longest_platform = 0;
23 for platform in pairs(sources) do
24 longest_platform = math.max(longest_platform, #platform);
25 end
26 for platform, source in pairs(sources) do
27 print("", platform..":"..(" "):rep(4+longest_platform-#platform)..source);
28 end
29 print("");
30 print(msg or (name.." is required for Prosody to run, so we will now exit."));
31 print("More help can be found on our website, at https://prosody.im/doc/depends");
32 print("**************************");
33 print("");
34 end
36 local function check_dependencies()
37 if _VERSION < "Lua 5.1" then
38 print "***********************************"
39 print("Unsupported Lua version: ".._VERSION);
40 print("At least Lua 5.1 is required.");
41 print "***********************************"
42 return false;
43 end
45 local fatal;
47 local lxp = softreq "lxp"
49 if not lxp then
50 missingdep("luaexpat", {
51 ["Debian/Ubuntu"] = "sudo apt-get install lua-expat";
52 ["luarocks"] = "luarocks install luaexpat";
53 ["Source"] = "http://matthewwild.co.uk/projects/luaexpat/";
54 });
55 fatal = true;
56 end
58 local socket = softreq "socket"
60 if not socket then
61 missingdep("luasocket", {
62 ["Debian/Ubuntu"] = "sudo apt-get install lua-socket";
63 ["luarocks"] = "luarocks install luasocket";
64 ["Source"] = "http://www.tecgraf.puc-rio.br/~diego/professional/luasocket/";
65 });
66 fatal = true;
67 elseif not socket.tcp4 then
68 -- COMPAT LuaSocket before being IP-version agnostic
69 socket.tcp4 = socket.tcp;
70 socket.udp4 = socket.udp;
71 end
73 local lfs, err = softreq "lfs"
74 if not lfs then
75 missingdep("luafilesystem", {
76 ["luarocks"] = "luarocks install luafilesystem";
77 ["Debian/Ubuntu"] = "sudo apt-get install lua-filesystem";
78 ["Source"] = "http://www.keplerproject.org/luafilesystem/";
79 });
80 fatal = true;
81 end
83 local ssl = softreq "ssl"
85 if not ssl then
86 missingdep("LuaSec", {
87 ["Debian/Ubuntu"] = "sudo apt-get install lua-sec";
88 ["luarocks"] = "luarocks install luasec";
89 ["Source"] = "https://github.com/brunoos/luasec";
90 }, "SSL/TLS support will not be available");
91 end
93 local bit = _G.bit32 or softreq"bit";
95 if not bit then
96 missingdep("lua-bitops", {
97 ["Debian/Ubuntu"] = "sudo apt-get install lua-bitop";
98 ["luarocks"] = "luarocks install luabitop";
99 ["Source"] = "http://bitop.luajit.org/";
100 }, "WebSocket support will not be available");
103 local encodings, err = softreq "util.encodings"
104 if not encodings then
105 if err:match("module '[^']*' not found") then
106 missingdep("util.encodings", {
107 ["Windows"] = "Make sure you have encodings.dll from the Prosody distribution in util/";
108 ["GNU/Linux"] = "Run './configure' and 'make' in the Prosody source directory to build util/encodings.so";
110 else
111 print "***********************************"
112 print("util/encodings couldn't be loaded. Check that you have a recent version of libidn");
113 print ""
114 print("The full error was:");
115 print(err)
116 print "***********************************"
118 fatal = true;
121 local hashes, err = softreq "util.hashes"
122 if not hashes then
123 if err:match("module '[^']*' not found") then
124 missingdep("util.hashes", {
125 ["Windows"] = "Make sure you have hashes.dll from the Prosody distribution in util/";
126 ["GNU/Linux"] = "Run './configure' and 'make' in the Prosody source directory to build util/hashes.so";
128 else
129 print "***********************************"
130 print("util/hashes couldn't be loaded. Check that you have a recent version of OpenSSL (libcrypto in particular)");
131 print ""
132 print("The full error was:");
133 print(err)
134 print "***********************************"
136 fatal = true;
139 return not fatal;
142 local function log_warnings()
143 if _VERSION > "Lua 5.3" then
144 prosody.log("warn", "Support for %s is experimental, please report any issues", _VERSION);
146 local ssl = softreq"ssl";
147 if ssl then
148 local major, minor, veryminor, patched = ssl._VERSION:match("(%d+)%.(%d+)%.?(%d*)(M?)");
149 if not major or ((tonumber(major) == 0 and (tonumber(minor) or 0) <= 3 and (tonumber(veryminor) or 0) <= 2) and patched ~= "M") then
150 prosody.log("error", "This version of LuaSec contains a known bug that causes disconnects, see https://prosody.im/doc/depends");
153 local lxp = softreq"lxp";
154 if lxp then
155 if not pcall(lxp.new, { StartDoctypeDecl = false }) then
156 prosody.log("error", "The version of LuaExpat on your system leaves Prosody "
157 .."vulnerable to denial-of-service attacks. You should upgrade to "
158 .."LuaExpat 1.3.0 or higher as soon as possible. See "
159 .."https://prosody.im/doc/depends#luaexpat for more information.");
161 if not lxp.new({}).getcurrentbytecount then
162 prosody.log("error", "The version of LuaExpat on your system does not support "
163 .."stanza size limits, which may leave servers on untrusted "
164 .."networks (e.g. the internet) vulnerable to denial-of-service "
165 .."attacks. You should upgrade to LuaExpat 1.3.0 or higher as "
166 .."soon as possible. See "
167 .."https://prosody.im/doc/depends#luaexpat for more information.");
172 return {
173 softreq = softreq;
174 missingdep = missingdep;
175 check_dependencies = check_dependencies;
176 log_warnings = log_warnings;