Software /
code /
prosody
Annotate
util/openssl.lua @ 7023:c2ccbfe30113
util.openssl: Fix style / whitespace
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 23 Dec 2015 08:47:57 +0100 |
parent | 7022:3252c107c91a |
child | 7192:18a13a7b4bac |
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 = {}; |
7023
c2ccbfe30113
util.openssl: Fix style / whitespace
Kim Alvefur <zash@zash.se>
parents:
7022
diff
changeset
|
15 local ssl_config_mt = { __index = ssl_config }; |
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
|
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", |
6902
d2d7ad2563f9
util.openssl: Separate extension sections into one for self-signed certs and one for requests
Kim Alvefur <zash@zash.se>
parents:
5544
diff
changeset
|
21 req_extensions = "certrequest", |
d2d7ad2563f9
util.openssl: Separate extension sections into one for self-signed certs and one for requests
Kim Alvefur <zash@zash.se>
parents:
5544
diff
changeset
|
22 x509_extensions = "selfsigned", |
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
|
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 countryName = "GB", |
5544
d911d9fb3929
util.openssl: Write the distinguished_name part of the config in a consistent order
Kim Alvefur <zash@zash.se>
parents:
5379
diff
changeset
|
27 -- stateOrProvinceName = "", |
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
|
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", |
5544
d911d9fb3929
util.openssl: Write the distinguished_name part of the config in a consistent order
Kim Alvefur <zash@zash.se>
parents:
5379
diff
changeset
|
31 commonName = "example.com", |
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
|
32 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
|
33 }, |
6902
d2d7ad2563f9
util.openssl: Separate extension sections into one for self-signed certs and one for requests
Kim Alvefur <zash@zash.se>
parents:
5544
diff
changeset
|
34 certrequest = { |
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
|
35 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
|
36 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
|
37 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
|
38 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
|
39 }, |
6902
d2d7ad2563f9
util.openssl: Separate extension sections into one for self-signed certs and one for requests
Kim Alvefur <zash@zash.se>
parents:
5544
diff
changeset
|
40 selfsigned = { |
d2d7ad2563f9
util.openssl: Separate extension sections into one for self-signed certs and one for requests
Kim Alvefur <zash@zash.se>
parents:
5544
diff
changeset
|
41 basicConstraints = "CA:TRUE", |
d2d7ad2563f9
util.openssl: Separate extension sections into one for self-signed certs and one for requests
Kim Alvefur <zash@zash.se>
parents:
5544
diff
changeset
|
42 subjectAltName = "@subject_alternative_name", |
d2d7ad2563f9
util.openssl: Separate extension sections into one for self-signed certs and one for requests
Kim Alvefur <zash@zash.se>
parents:
5544
diff
changeset
|
43 }, |
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
|
44 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
|
45 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
|
46 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
|
47 }, |
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 }, 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
|
49 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
|
50 |
5544
d911d9fb3929
util.openssl: Write the distinguished_name part of the config in a consistent order
Kim Alvefur <zash@zash.se>
parents:
5379
diff
changeset
|
51 local DN_order = { |
d911d9fb3929
util.openssl: Write the distinguished_name part of the config in a consistent order
Kim Alvefur <zash@zash.se>
parents:
5379
diff
changeset
|
52 "countryName"; |
d911d9fb3929
util.openssl: Write the distinguished_name part of the config in a consistent order
Kim Alvefur <zash@zash.se>
parents:
5379
diff
changeset
|
53 "stateOrProvinceName"; |
d911d9fb3929
util.openssl: Write the distinguished_name part of the config in a consistent order
Kim Alvefur <zash@zash.se>
parents:
5379
diff
changeset
|
54 "localityName"; |
d911d9fb3929
util.openssl: Write the distinguished_name part of the config in a consistent order
Kim Alvefur <zash@zash.se>
parents:
5379
diff
changeset
|
55 "streetAddress"; |
d911d9fb3929
util.openssl: Write the distinguished_name part of the config in a consistent order
Kim Alvefur <zash@zash.se>
parents:
5379
diff
changeset
|
56 "organizationName"; |
d911d9fb3929
util.openssl: Write the distinguished_name part of the config in a consistent order
Kim Alvefur <zash@zash.se>
parents:
5379
diff
changeset
|
57 "organizationalUnitName"; |
d911d9fb3929
util.openssl: Write the distinguished_name part of the config in a consistent order
Kim Alvefur <zash@zash.se>
parents:
5379
diff
changeset
|
58 "commonName"; |
d911d9fb3929
util.openssl: Write the distinguished_name part of the config in a consistent order
Kim Alvefur <zash@zash.se>
parents:
5379
diff
changeset
|
59 "emailAddress"; |
d911d9fb3929
util.openssl: Write the distinguished_name part of the config in a consistent order
Kim Alvefur <zash@zash.se>
parents:
5379
diff
changeset
|
60 } |
d911d9fb3929
util.openssl: Write the distinguished_name part of the config in a consistent order
Kim Alvefur <zash@zash.se>
parents:
5379
diff
changeset
|
61 _M._DN_order = DN_order; |
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
|
62 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
|
63 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
|
64 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
|
65 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
|
66 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
|
67 for san, n in pairs(t) do |
7023
c2ccbfe30113
util.openssl: Fix style / whitespace
Kim Alvefur <zash@zash.se>
parents:
7022
diff
changeset
|
68 for i = 1, #n 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
|
69 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
|
70 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
|
71 end |
5544
d911d9fb3929
util.openssl: Write the distinguished_name part of the config in a consistent order
Kim Alvefur <zash@zash.se>
parents:
5379
diff
changeset
|
72 elseif k == "distinguished_name" then |
7023
c2ccbfe30113
util.openssl: Fix style / whitespace
Kim Alvefur <zash@zash.se>
parents:
7022
diff
changeset
|
73 for i=1, #DN_order do |
5544
d911d9fb3929
util.openssl: Write the distinguished_name part of the config in a consistent order
Kim Alvefur <zash@zash.se>
parents:
5379
diff
changeset
|
74 local k = DN_order[i] |
d911d9fb3929
util.openssl: Write the distinguished_name part of the config in a consistent order
Kim Alvefur <zash@zash.se>
parents:
5379
diff
changeset
|
75 local v = t[k]; |
d911d9fb3929
util.openssl: Write the distinguished_name part of the config in a consistent order
Kim Alvefur <zash@zash.se>
parents:
5379
diff
changeset
|
76 if v then |
d911d9fb3929
util.openssl: Write the distinguished_name part of the config in a consistent order
Kim Alvefur <zash@zash.se>
parents:
5379
diff
changeset
|
77 s = s .. ("%s = %s\n"):format(k, v); |
d911d9fb3929
util.openssl: Write the distinguished_name part of the config in a consistent order
Kim Alvefur <zash@zash.se>
parents:
5379
diff
changeset
|
78 end |
d911d9fb3929
util.openssl: Write the distinguished_name part of the config in a consistent order
Kim Alvefur <zash@zash.se>
parents:
5379
diff
changeset
|
79 end |
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
|
80 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
|
81 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
|
82 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
|
83 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
|
84 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
|
85 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
|
86 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
|
87 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
|
88 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
|
89 |
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 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
|
91 -- 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
|
92 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
|
93 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
|
94 |
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 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
|
96 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
|
97 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
|
98 |
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
|
99 _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
|
100 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
|
101 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
|
102 }; |
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 |
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 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
|
105 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
|
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 |
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 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
|
109 t_insert(self.subject_alternative_name.otherName, |
7023
c2ccbfe30113
util.openssl: Fix style / whitespace
Kim Alvefur <zash@zash.se>
parents:
7022
diff
changeset
|
110 s_format("%s;%s", oid_dnssrv, ia5string("_" .. service .. "." .. idna_to_ascii(host)))); |
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
|
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 |
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 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
|
114 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
|
115 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
|
116 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
|
117 |
5290
befb1923527d
util.openssl: Cleanup; remove some unused variables.
Kim Alvefur <zash@zash.se>
parents:
4823
diff
changeset
|
118 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
|
119 -- 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
|
120 local found_matching_hosts = false; |
7023
c2ccbfe30113
util.openssl: Fix style / whitespace
Kim Alvefur <zash@zash.se>
parents:
7022
diff
changeset
|
121 for i = 1, #certhosts 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
|
122 local certhost = certhosts[i]; |
5290
befb1923527d
util.openssl: Cleanup; remove some unused variables.
Kim Alvefur <zash@zash.se>
parents:
4823
diff
changeset
|
123 for name in pairs(hosts) do |
7023
c2ccbfe30113
util.openssl: Fix style / whitespace
Kim Alvefur <zash@zash.se>
parents:
7022
diff
changeset
|
124 if name == certhost or name:sub(-1-#certhost) == "." .. certhost then |
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
|
125 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
|
126 self:add_dNSName(name); |
5379
27de7cc94111
util.{prosodyctl,openssl}: More use of config sections removed
Kim Alvefur <zash@zash.se>
parents:
5290
diff
changeset
|
127 --print(name .. "#component_module: " .. (config.get(name, "component_module") or "nil")); |
27de7cc94111
util.{prosodyctl,openssl}: More use of config sections removed
Kim Alvefur <zash@zash.se>
parents:
5290
diff
changeset
|
128 if config.get(name, "component_module") == nil then |
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
|
129 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
|
130 end |
5379
27de7cc94111
util.{prosodyctl,openssl}: More use of config sections removed
Kim Alvefur <zash@zash.se>
parents:
5290
diff
changeset
|
131 --print(name .. "#anonymous_login: " .. tostring(config.get(name, "anonymous_login"))); |
27de7cc94111
util.{prosodyctl,openssl}: More use of config sections removed
Kim Alvefur <zash@zash.se>
parents:
5290
diff
changeset
|
132 if not (config.get(name, "anonymous_login") or |
27de7cc94111
util.{prosodyctl,openssl}: More use of config sections removed
Kim Alvefur <zash@zash.se>
parents:
5290
diff
changeset
|
133 config.get(name, "authentication") == "anonymous") then |
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
|
134 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
|
135 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
|
136 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
|
137 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
|
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 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
|
140 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
|
141 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
|
142 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
|
143 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
|
144 |
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 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
|
146 local function shell_escape(s) |
7021
f436446661ca
util.openssl: Move quoting and tostring call into escape function
Kim Alvefur <zash@zash.se>
parents:
6902
diff
changeset
|
147 return "'" .. tostring(s):gsub("'",[['\'']]) .. "'"; |
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
|
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 |
7022
3252c107c91a
util.openssl: Rename variables for readability
Kim Alvefur <zash@zash.se>
parents:
7021
diff
changeset
|
150 local function serialize(command, args) |
3252c107c91a
util.openssl: Rename variables for readability
Kim Alvefur <zash@zash.se>
parents:
7021
diff
changeset
|
151 local commandline = { "openssl", command }; |
3252c107c91a
util.openssl: Rename variables for readability
Kim Alvefur <zash@zash.se>
parents:
7021
diff
changeset
|
152 for k, v in pairs(args) 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
|
153 if type(k) == "string" then |
7022
3252c107c91a
util.openssl: Rename variables for readability
Kim Alvefur <zash@zash.se>
parents:
7021
diff
changeset
|
154 t_insert(commandline, ("-%s"):format(k)); |
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
|
155 if v ~= true then |
7022
3252c107c91a
util.openssl: Rename variables for readability
Kim Alvefur <zash@zash.se>
parents:
7021
diff
changeset
|
156 t_insert(commandline, shell_escape(v)); |
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
|
157 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
|
158 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
|
159 end |
7022
3252c107c91a
util.openssl: Rename variables for readability
Kim Alvefur <zash@zash.se>
parents:
7021
diff
changeset
|
160 for _, v in ipairs(args) do |
3252c107c91a
util.openssl: Rename variables for readability
Kim Alvefur <zash@zash.se>
parents:
7021
diff
changeset
|
161 t_insert(commandline, shell_escape(v)); |
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
|
162 end |
7022
3252c107c91a
util.openssl: Rename variables for readability
Kim Alvefur <zash@zash.se>
parents:
7021
diff
changeset
|
163 return t_concat(commandline, " "); |
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
|
164 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
|
165 |
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
|
166 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
|
167 setmetatable(_M, { |
7023
c2ccbfe30113
util.openssl: Fix style / whitespace
Kim Alvefur <zash@zash.se>
parents:
7022
diff
changeset
|
168 __index = function(_, command) |
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
|
169 return function(opts) |
7022
3252c107c91a
util.openssl: Rename variables for readability
Kim Alvefur <zash@zash.se>
parents:
7021
diff
changeset
|
170 return 0 == os_execute(serialize(command, type(opts) == "table" and opts or {})); |
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
|
171 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
|
172 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
|
173 }); |
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
|
174 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
|
175 |
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
|
176 return _M; |