Skip to content

Commit

Permalink
fix Tls.Config.client/server breaking change
Browse files Browse the repository at this point in the history
  • Loading branch information
art-w committed Aug 27, 2024
1 parent e6bf7a1 commit c54b76f
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 12 deletions.
2 changes: 1 addition & 1 deletion conduit-lwt-unix.opam
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ depends: [
]
depopts: ["tls-lwt" "lwt_ssl" "launchd"]
conflicts: [
"tls-lwt" {< "0.16.0"}
"tls-lwt" {< "1.0.0"}
"ssl" {< "0.5.12"}
]
build: [
Expand Down
6 changes: 3 additions & 3 deletions conduit-mirage.opam
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ depends: [
"mirage-flow-combinators" {>= "2.0.0"}
"mirage-random" {>= "2.0.0"}
"mirage-time" {>= "2.0.0"}
"dns-client-mirage" {>= "8.0.0"}
"dns-client-mirage" {>= "9.0.0"}
"conduit-lwt" {=version}
"vchan" {>= "5.0.0"}
"xenstore"
"tls" {>= "0.11.0"}
"tls-mirage" {>= "0.17.4"}
"tls" {>= "1.0.0"}
"tls-mirage" {>= "1.0.0"}
"ca-certs-nss"
"ipaddr" {>= "3.0.0"}
"ipaddr-sexp"
Expand Down
15 changes: 12 additions & 3 deletions src/conduit-lwt-unix/conduit_lwt_tls.real.ml
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,25 @@ module X509 = struct
end

module Client = struct
let config ?certificates ~authenticator () =
match Tls.Config.client ~authenticator ?certificates () with
| Ok config -> config
| Error (`Msg msg) -> failwith msg

let connect ?src ?certificates ~authenticator host sa =
Conduit_lwt_server.with_socket sa (fun fd ->
(match src with
| None -> Lwt.return_unit
| Some src_sa -> Lwt_unix.bind fd src_sa)
>>= fun () ->
let config = Tls.Config.client ~authenticator ?certificates () in
let config = config ~authenticator ?certificates () in
Lwt_unix.connect fd sa >>= fun () ->
Tls_lwt.Unix.client_of_fd config ~host fd >|= fun t ->
let ic, oc = Tls_lwt.of_t t in
(fd, ic, oc))

let tunnel ?certificates ~authenticator host channels =
let config = Tls.Config.client ~authenticator ?certificates () in
let config = config ~authenticator ?certificates () in
Tls_lwt.Unix.client_of_channels config ~host channels >|= fun t ->
Tls_lwt.of_t t
end
Expand All @@ -64,7 +69,11 @@ module Server = struct
let init ?backlog ~certfile ~keyfile ?stop ?timeout sa callback =
X509_lwt.private_of_pems ~cert:certfile ~priv_key:keyfile
>>= fun certificate ->
let config = Tls.Config.server ~certificates:(`Single certificate) () in
let config =
match Tls.Config.server ~certificates:(`Single certificate) () with
| Ok config -> config
| Error (`Msg msg) -> failwith msg
in
init' ?backlog ?stop ?timeout config sa callback
end

Expand Down
11 changes: 8 additions & 3 deletions src/conduit-mirage/conduit_mirage.ml
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,14 @@ let tls_client ~host ~authenticator x =
let peer_name =
Result.to_option (Result.bind (Domain_name.of_string host) Domain_name.host)
in
`TLS (Tls.Config.client ?peer_name ~authenticator (), x)

let tls_server ?authenticator x = `TLS (Tls.Config.server ?authenticator (), x)
match Tls.Config.client ?peer_name ~authenticator () with
| Ok config -> `TLS (config, x)
| Error (`Msg msg) -> failwith msg

let tls_server ?authenticator x =
match Tls.Config.server ?authenticator () with
| Ok config -> `TLS (config, x)
| Error (`Msg msg) -> failwith msg

module TLS (S : S) = struct
module TLS = Tls_mirage.Make (S.Flow)
Expand Down
2 changes: 1 addition & 1 deletion src/conduit-mirage/resolver_mirage.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module type S = sig
end

module Make
(R : Mirage_random.S)
(R : Mirage_crypto_rng_mirage.S)
(T : Mirage_time.S)
(C : Mirage_clock.MCLOCK)
(P : Mirage_clock.PCLOCK)
Expand Down
2 changes: 1 addition & 1 deletion src/conduit-mirage/resolver_mirage.mli
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ end

(** Provides a DNS-enabled {!Resolver_lwt} given a network stack. *)
module Make
(R : Mirage_random.S)
(R : Mirage_crypto_rng_mirage.S)
(T : Mirage_time.S)
(C : Mirage_clock.MCLOCK)
(P : Mirage_clock.PCLOCK)
Expand Down

0 comments on commit c54b76f

Please sign in to comment.