nixio: Autogenerate private key on installation if we have axtls
[project/luci.git] / libs / nixio / axtls-root / usr / sbin / nixio-axtls-checkkey
1 #!/usr/bin/lua
2 local nixio = require "nixio"
3 local posix
4 local defkey = nixio.meta_tls_context.tls_defaultkey
5 if not defkey or io.open(defkey) then
6         os.exit(0)
7 end
8
9 if os.execute("which openssl") then
10         io.stderr:write("Warning: OpenSSL detected "..
11         "but it looks like nixio was linked against axtls\n")
12         os.execute("umask 0077;openssl genrsa -out '" .. defkey .. "' 2048")
13 elseif os.execute("which dropbearkey && which dropbearconvert") then
14         os.execute("dropbearkey -t rsa -s 2048 -f /tmp/dbkey.rsa")
15         os.execute("umask 0077;dropbearconvert dropbear openssh /tmp/dbkey.rsa '"..defkey.."'")
16         os.remove("/tmp/dbkey.rsa")
17 else
18         io.stderr:write("No key generators available! Giving up.")
19         os.exit(1)
20 end