Comparison

prosodyctl @ 8274:3798955049e3

prosodyctl: cert import: Reuse function from certmanager for locating certificates and keys
author Kim Alvefur <zash@zash.se>
date Wed, 27 Sep 2017 15:21:20 +0200
parent 8265:17ebd8ac8545
child 8276:5ebad58b2548
comparison
equal deleted inserted replaced
8273:ca881f4bc415 8274:3798955049e3
892 local owner, group; 892 local owner, group;
893 if pposix.getuid() == 0 then -- We need root to change ownership 893 if pposix.getuid() == 0 then -- We need root to change ownership
894 owner = config.get("*", "prosody_user") or "prosody"; 894 owner = config.get("*", "prosody_user") or "prosody";
895 group = config.get("*", "prosody_group") or owner; 895 group = config.get("*", "prosody_group") or owner;
896 end 896 end
897 local cm = require "core.certmanager";
897 local imported = {}; 898 local imported = {};
898 for _, host in ipairs(hostnames) do 899 for _, host in ipairs(hostnames) do
899 for _, dir in ipairs(arg) do 900 for _, dir in ipairs(arg) do
900 if lfs.attributes(dir .. "/" .. host .. "/fullchain.pem") 901 local paths = cm.find_cert(dir, host);
901 and lfs.attributes(dir .. "/" .. host .. "/privkey.pem") then 902 if paths then
902 copy(dir .. "/" .. host .. "/fullchain.pem", cert_basedir .. "/" .. host .. ".crt", nil, owner, group); 903 copy(paths.certificate, cert_basedir .. "/" .. host .. ".crt", nil, owner, group);
903 copy(dir .. "/" .. host .. "/privkey.pem", cert_basedir .. "/" .. host .. ".key", "0377", owner, group); 904 copy(paths.key, cert_basedir .. "/" .. host .. ".key", "0377", owner, group);
904 table.insert(imported, host);
905 elseif lfs.attributes(dir .. "/" .. host .. ".crt")
906 and lfs.attributes(dir .. "/" .. host .. ".key") then
907 copy(dir .. "/" .. host .. ".crt", cert_basedir .. "/" .. host .. ".crt", nil, owner, group);
908 copy(dir .. "/" .. host .. ".key", cert_basedir .. "/" .. host .. ".key", "0377", owner, group);
909 table.insert(imported, host); 905 table.insert(imported, host);
910 else 906 else
911 -- TODO Say where we looked 907 -- TODO Say where we looked
912 show_warning("No certificate for host "..host.." found :("); 908 show_warning("No certificate for host "..host.." found :(");
913 end 909 end