Annotate

util/openssl.lua @ 5311:86fe6e2fa5ae

util.xmppstream: Include error stanza in error message if no error handler is available.
author Waqas Hussain <waqas20@gmail.com>
date Sat, 26 Jan 2013 03:39:18 +0500
parent 5290:befb1923527d
child 5379:27de7cc94111
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4823
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 local type, tostring, pairs, ipairs = type, tostring, pairs, ipairs;
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2 local t_insert, t_concat = table.insert, table.concat;
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3 local s_format = string.format;
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5 local oid_xmppaddr = "1.3.6.1.5.5.7.8.5"; -- [XMPP-CORE]
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6 local oid_dnssrv = "1.3.6.1.5.5.7.8.7"; -- [SRV-ID]
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 local idna_to_ascii = require "util.encodings".idna.to_ascii;
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10 local _M = {};
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11 local config = {};
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 _M.config = config;
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14 local ssl_config = {};
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15 local ssl_config_mt = {__index=ssl_config};
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17 function config.new()
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 return setmetatable({
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19 req = {
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20 distinguished_name = "distinguished_name",
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21 req_extensions = "v3_extensions",
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 x509_extensions = "v3_extensions",
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 prompt = "no",
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24 },
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 distinguished_name = {
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 commonName = "example.com",
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27 countryName = "GB",
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28 localityName = "The Internet",
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
29 organizationName = "Your Organisation",
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
30 organizationalUnitName = "XMPP Department",
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31 emailAddress = "xmpp@example.com",
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
32 },
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
33 v3_extensions = {
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
34 basicConstraints = "CA:FALSE",
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
35 keyUsage = "digitalSignature,keyEncipherment",
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
36 extendedKeyUsage = "serverAuth,clientAuth",
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
37 subjectAltName = "@subject_alternative_name",
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
38 },
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
39 subject_alternative_name = {
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
40 DNS = {},
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
41 otherName = {},
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
42 },
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
43 }, ssl_config_mt);
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
44 end
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
45
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
46 function ssl_config:serialize()
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
47 local s = "";
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
48 for k, t in pairs(self) do
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
49 s = s .. ("[%s]\n"):format(k);
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
50 if k == "subject_alternative_name" then
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
51 for san, n in pairs(t) do
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
52 for i = 1,#n do
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
53 s = s .. s_format("%s.%d = %s\n", san, i -1, n[i]);
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
54 end
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
55 end
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
56 else
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
57 for k, v in pairs(t) do
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
58 s = s .. ("%s = %s\n"):format(k, v);
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
59 end
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
60 end
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
61 s = s .. "\n";
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
62 end
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
63 return s;
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
64 end
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
65
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
66 local function utf8string(s)
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
67 -- This is how we tell openssl not to encode UTF-8 strings as fake Latin1
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
68 return s_format("FORMAT:UTF8,UTF8:%s", s);
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
69 end
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
70
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
71 local function ia5string(s)
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
72 return s_format("IA5STRING:%s", s);
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
73 end
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
74
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
75 _M.util = {
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
76 utf8string = utf8string,
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
77 ia5string = ia5string,
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
78 };
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
79
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
80 function ssl_config:add_dNSName(host)
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
81 t_insert(self.subject_alternative_name.DNS, idna_to_ascii(host));
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
82 end
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
83
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
84 function ssl_config:add_sRVName(host, service)
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
85 t_insert(self.subject_alternative_name.otherName,
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
86 s_format("%s;%s", oid_dnssrv, ia5string("_" .. service .."." .. idna_to_ascii(host))));
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
87 end
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
88
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
89 function ssl_config:add_xmppAddr(host)
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
90 t_insert(self.subject_alternative_name.otherName,
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
91 s_format("%s;%s", oid_xmppaddr, utf8string(host)));
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
92 end
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
93
5290
befb1923527d util.openssl: Cleanup; remove some unused variables.
Kim Alvefur <zash@zash.se>
parents: 4823
diff changeset
94 function ssl_config:from_prosody(hosts, config, certhosts)
4823
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
95 -- TODO Decide if this should go elsewhere
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
96 local found_matching_hosts = false;
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
97 for i = 1,#certhosts do
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
98 local certhost = certhosts[i];
5290
befb1923527d util.openssl: Cleanup; remove some unused variables.
Kim Alvefur <zash@zash.se>
parents: 4823
diff changeset
99 for name in pairs(hosts) do
4823
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
100 if name == certhost or name:sub(-1-#certhost) == "."..certhost then
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
101 found_matching_hosts = true;
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
102 self:add_dNSName(name);
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
103 --print(name .. "#component_module: " .. (config.get(name, "core", "component_module") or "nil"));
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
104 if config.get(name, "core", "component_module") == nil then
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
105 self:add_sRVName(name, "xmpp-client");
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
106 end
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
107 --print(name .. "#anonymous_login: " .. tostring(config.get(name, "core", "anonymous_login")));
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
108 if not (config.get(name, "core", "anonymous_login") or
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
109 config.get(name, "core", "authentication") == "anonymous") then
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
110 self:add_sRVName(name, "xmpp-server");
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
111 end
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
112 self:add_xmppAddr(name);
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
113 end
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
114 end
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
115 end
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
116 if not found_matching_hosts then
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
117 return nil, "no-matching-hosts";
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
118 end
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
119 end
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
120
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
121 do -- Lua to shell calls.
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
122 local function shell_escape(s)
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
123 return s:gsub("'",[['\'']]);
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
124 end
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
125
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
126 local function serialize(f,o)
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
127 local r = {"openssl", f};
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
128 for k,v in pairs(o) do
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
129 if type(k) == "string" then
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
130 t_insert(r, ("-%s"):format(k));
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
131 if v ~= true then
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
132 t_insert(r, ("'%s'"):format(shell_escape(tostring(v))));
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
133 end
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
134 end
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
135 end
5290
befb1923527d util.openssl: Cleanup; remove some unused variables.
Kim Alvefur <zash@zash.se>
parents: 4823
diff changeset
136 for _,v in ipairs(o) do
4823
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
137 t_insert(r, ("'%s'"):format(shell_escape(tostring(v))));
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
138 end
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
139 return t_concat(r, " ");
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
140 end
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
141
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
142 local os_execute = os.execute;
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
143 setmetatable(_M, {
5290
befb1923527d util.openssl: Cleanup; remove some unused variables.
Kim Alvefur <zash@zash.se>
parents: 4823
diff changeset
144 __index=function(_,f)
4823
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
145 return function(opts)
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
146 return 0 == os_execute(serialize(f, type(opts) == "table" and opts or {}));
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
147 end;
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
148 end;
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
149 });
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
150 end
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
151
a61e78b4a2b3 util.openssl: Add wrapper for the openssl cli tool and move certificate config logic from util.x509 into it.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
152 return _M;