liminix

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 87c45dec670406b1248ccf583892bf1e5e76f571
parent 53244beab81f5be0cca24337fdd8091ac29eaaa7
Author: Daniel Barlow <dan@telent.net>
Date:   Sun, 19 Oct 2025 14:07:27 +0100

switch certifix-client to luahttp

Diffstat:
Mmodules/tls-certificate/certifix-client.nix | 2+-
Mpkgs/certifix-client/certifix-client.fnl | 33++++++++++++++++++++-------------
Mpkgs/certifix-client/default.nix | 15+++++++++------
3 files changed, 30 insertions(+), 20 deletions(-)

diff --git a/modules/tls-certificate/certifix-client.nix b/modules/tls-certificate/certifix-client.nix @@ -23,7 +23,7 @@ oneshot { inherit name; up = '' (in_outputs ${name} - SSL_CA_CERT_FILE=${caCertFile} ${certifix-client}/bin/certifix-client --subject ${subject} --secret ${secretFile} --key-out key --certificate-out cert ${serviceUrl} + SSL_CERT_FILE=${caCertFile} ${certifix-client}/bin/certifix-client --subject ${subject} --secret ${secretFile} --key-out key --certificate-out cert ${serviceUrl} ) ''; } diff --git a/pkgs/certifix-client/certifix-client.fnl b/pkgs/certifix-client/certifix-client.fnl @@ -7,7 +7,9 @@ (local pkey (require :openssl.pkey)) (local xn (require :openssl.x509.name)) -(local http (require :fetch)) +(local request (require :http.request)) +(local http_tls (require :http.tls)) +(local x509 (require :openssl.x509)) (macro ncall [f] `(case ,f @@ -62,22 +64,27 @@ (: :addAttribute :challengePassword [options.secret]) (: :sign pk))) - -(fn http-post [url body] - (match - (http.request "POST" url - "" 0 - "application/x-pem-file" - body) - s s - (nil code msg) (error (.. "Error " code " POST " url ": " msg)))) - +(fn http-post [url body] + (let [r (request.new_from_uri url) + h r.headers] + (h:upsert ":method" :POST) + (h:upsert "content-type" "application/x-pem-file") + (when body + (r:set_body body)) + (or + (case (r:go) + (headers stream) + (if (= (headers:get ":status") "200") + (stream:get_body_as_string) + (error (.. "error response from server: " + (headers:get ":status")))) + + (nil failure) + (error (.. "error: " failure)))))) (fn run [] (let [pk (private-key) csr (signing-request pk) - ;; key-out (or options.key-out-handle io.stdout) - ;; cert-out (or options.cert-out-handle io.stdout) cert (http-post options.server (csr:toPEM))] (with-open [f (ncall (io.open options.key-out :w))] (f:write (pk:toPEM :private))) diff --git a/pkgs/certifix-client/default.nix b/pkgs/certifix-client/default.nix @@ -7,9 +7,7 @@ lua, anoia, lualinux, - fetch-freebsd, openssl, - luaossl', stdenv, }: let @@ -20,7 +18,6 @@ stdenv.mkDerivation { src = ./.; buildInputs = [ - fetch-freebsd openssl lua ]; @@ -30,12 +27,18 @@ stdenv.mkDerivation { mkdir -p $out/bin cp -p ${ writeFennel name { - packages = [ - fetch-freebsd + packages = with lua.pkgs; [ fennel anoia lualinux - luaossl' + luaossl + http + lpeg + lpeg_patterns + basexx + cqueues + fifo + binaryheap ]; mainFunction = "run"; } ./${name}.fnl