mirror of
https://github.com/linuxkit/linuxkit.git
synced 2026-04-03 14:18:37 +00:00
Also, separate out RPC encoding from application logic. Signed-off-by: Thomas Leonard <thomas.leonard@docker.com>
27 lines
965 B
OCaml
27 lines
965 B
OCaml
(** The TLS terminator implementation.
|
|
Listens for TLS connections on a port and forwards the plaintext flow to the HTTP service. *)
|
|
|
|
open Lwt.Infix
|
|
open Capnp_rpc_lwt
|
|
|
|
let run ~port ~http_service =
|
|
let tls_config : Conduit_lwt_unix.server_tls_config =
|
|
`Crt_file_path "tls-secrets/server.crt",
|
|
`Key_file_path "tls-secrets/server.key",
|
|
`No_password,
|
|
`Port port
|
|
in
|
|
let mode = `TLS tls_config in
|
|
Logs.info (fun f -> f "Listening on https port %d" port);
|
|
Conduit_lwt_unix.(serve ~ctx:default_ctx) ~mode (fun _flow ic oc ->
|
|
Logs.info (fun f -> f "Got new TLS connection");
|
|
let flow_obj = Rpc.Flow.local ic oc in
|
|
Rpc.Http.accept http_service flow_obj >|= fun () ->
|
|
Capability.dec_ref flow_obj
|
|
)
|
|
|
|
let init ~switch ~to_http =
|
|
let tags = Logs.Tag.add Logging.Actor.tag (`Blue, "TLS ") Logs.Tag.empty in
|
|
let http_service = CapTP.bootstrap (CapTP.connect ~tags ~switch to_http) in
|
|
run ~http_service ~port:8443
|