2018-11-23 19:28:33 +00:00
|
|
|
(* (c) 2018 Hannes Mehnert, all rights reserved *)
|
|
|
|
|
|
|
|
open Lwt.Infix
|
2019-03-27 23:11:43 +00:00
|
|
|
open Albatross_tls_common
|
2018-11-23 19:28:33 +00:00
|
|
|
|
|
|
|
let jump cacert cert priv_key =
|
|
|
|
Sys.(set_signal sigpipe Signal_ignore) ;
|
|
|
|
Lwt_main.run
|
|
|
|
(Nocrypto_entropy_lwt.initialize () >>= fun () ->
|
|
|
|
tls_config cacert cert priv_key >>= fun (config, ca) ->
|
|
|
|
let fd = Lwt_unix.of_unix_file_descr Unix.stdin in
|
|
|
|
Lwt.catch
|
|
|
|
(fun () -> Tls_lwt.Unix.server_of_fd config fd)
|
|
|
|
(fun exn ->
|
|
|
|
Vmm_lwt.safe_close fd >>= fun () ->
|
|
|
|
Lwt.fail exn) >>= fun t ->
|
|
|
|
Lwt.catch
|
|
|
|
(fun () ->
|
|
|
|
(handle ca t >|= function
|
|
|
|
| Error (`Msg msg) -> Logs.err (fun m -> m "error in handle %s" msg)
|
|
|
|
| Ok () -> ()) >>= fun () ->
|
|
|
|
Vmm_tls_lwt.close t)
|
|
|
|
(fun e ->
|
|
|
|
Logs.err (fun m -> m "error while handle() %s" (Printexc.to_string e)) ;
|
2019-04-08 14:40:58 +00:00
|
|
|
Vmm_tls_lwt.close t))
|
2018-11-23 19:28:33 +00:00
|
|
|
|
|
|
|
open Cmdliner
|
|
|
|
|
|
|
|
let cmd =
|
2019-04-08 14:40:58 +00:00
|
|
|
Term.(const jump $ cacert $ cert $ key),
|
2019-03-27 23:11:43 +00:00
|
|
|
Term.info "albatross_tls_inetd" ~version:"%%VERSION_NUM%%"
|
2018-11-23 19:28:33 +00:00
|
|
|
|
|
|
|
let () = match Term.eval cmd with `Ok () -> exit 0 | _ -> exit 1
|