This commit is contained in:
swrup 2025-11-02 18:58:23 +01:00
parent 46c9a392c0
commit 348f6beb0f

View file

@ -29,31 +29,32 @@ let alpn =
let ( <.> ) f g x = f (g x)
let always x _ = x
let map_err_to_string pp_err res =
Lwt.map (R.reword_error (R.msgf "%a" pp_err)) res
module Make
(Certificate : Mirage_kv.RO)
(Key : Mirage_kv.RO)
(Certificates_ro : Mirage_kv.RO)
(Keys_ro : Mirage_kv.RO)
(Tcp : Tcpip.Tcp.S with type ipaddr = Ipaddr.t)
(Connect : Connect.S)
(HTTP_server : Paf_mirage.S) =
struct
let tls certificate_ro key_ro =
let ( >>= ) = Lwt_result.bind in
Key.list key_ro Mirage_kv.Key.empty
|> Lwt.map (R.reword_error (R.msgf "%a" Key.pp_error))
Keys_ro.list key_ro Mirage_kv.Key.empty
|> map_err_to_string Keys_ro.pp_error
>>= fun keys ->
let keys, _ = List.partition (fun (_, t) -> t = `Value) keys in
Certificate.list certificate_ro Mirage_kv.Key.empty
|> Lwt.map (R.reword_error (R.msgf "%a" Certificate.pp_error))
let keys = List.filter (fun (_, t) -> t = `Value) keys in
Certificates_ro.list certificate_ro Mirage_kv.Key.empty
|> map_err_to_string Certificates_ro.pp_error
>>= fun certificates ->
let certificates, _ =
List.partition (fun (_, t) -> t = `Value) certificates
in
let certificates = List.filter (fun (_, t) -> t = `Value) certificates in
let fold acc (name, _) =
match Mirage_kv.Key.basename name with
| ".gitkeep" -> Lwt.return acc
| _ ->
Certificate.get certificate_ro name
|> Lwt.map (R.reword_error (R.msgf "%a" Certificate.pp_error))
Certificates_ro.get certificate_ro name
|> map_err_to_string Certificates_ro.pp_error
>>= (Lwt.return <.> X509.Certificate.decode_pem_multiple)
>>= fun certificates ->
Lwt.return acc >>= fun acc ->
@ -64,8 +65,8 @@ struct
match Mirage_kv.Key.basename name with
| ".gitkeep" -> Lwt.return acc
| _ ->
Key.get key_ro name
|> Lwt.map (R.reword_error (R.msgf "%a" Key.pp_error))
Keys_ro.get key_ro name
|> map_err_to_string Keys_ro.pp_error
>>= (Lwt.return <.> X509.Private_key.decode_pem)
>>= fun key ->
Lwt.return acc >>= fun acc -> Lwt.return_ok ((name, key) :: acc)