parse command-line for options instead of hardcoding

note port is still hardcoded
This commit is contained in:
Daniel Barlow 2024-09-26 22:05:13 +01:00
parent e410cef1f4
commit 32099b7541
1 changed files with 32 additions and 4 deletions

View File

@ -36,9 +36,37 @@
(fn slurp [filename]
(with-open [f (io.open filename "r")] (f:read "*a")))
(local ca-key (pkey.new (slurp "ca.key")))
(local ca-crt (x509.new (slurp "ca.crt")))
(local psk (with-open [f (io.open "psk" "r")] (f:read "l")))
(fn read-line [filename]
(with-open [f (io.open filename "r")] (f:read "l")))
(fn assoc [tbl k v & more]
(tset tbl k v)
(case more
[k v] (assoc tbl k v)
_ tbl))
(fn parse-args [args]
(match args
["--certificate" f & rest]
(assoc (parse-args rest) :certificate (slurp f))
["--private-key" f & rest]
(assoc (parse-args rest) :private-key (slurp f))
["--challenge-password" f & rest]
(assoc (parse-args rest) :challenge-password (read-line f))
[peer] { : peer }
_ {}))
(local options
(doto
(parse-args arg)
(case
{: certificate : private-key : challenge-password : peer}
true
_
(assert nil "missing required command line params"))))
(local ca-key (pkey.new options.private-key))
(local ca-crt (x509.new options.certificate))
(fn new-crt [csr]
(let [crt
@ -56,7 +84,7 @@
(let [attr (csr:getAttributes)]
(accumulate [found false
_ v (ipairs (. attr "challengePassword"))]
(or found (= v psk)))))
(or found (= v options.challenge-password)))))
(fn handle-sign-csr [out]