Skip to content

Commit

Permalink
Merge pull request #76 from hannesm/variants
Browse files Browse the repository at this point in the history
defunctorise
  • Loading branch information
hannesm authored Feb 5, 2025
2 parents 4617c9c + aa2b842 commit 58ffe10
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 16 deletions.
4 changes: 2 additions & 2 deletions awa-mirage.opam
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ depends: [
"cstruct" {>= "6.0.0"}
"mtime" {>= "1.0.0"}
"lwt" {>= "5.3.0"}
"mirage-time" {>= "2.0.0"}
"mirage-sleep" {>= "4.0.0"}
"duration" {>= "0.2.0"}
"mirage-flow" {>= "4.0.0"}
"mirage-clock" {>= "3.0.0"}
"mirage-mtime" {>= "4.0.0"}
"logs"
]
synopsis: "SSH implementation in OCaml"
Expand Down
2 changes: 1 addition & 1 deletion awa.opam
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ depends: [
"ocaml" {>= "4.10.0"}
"dune" {>= "2.7"}
"mirage-crypto" {>= "1.0.0"}
"mirage-crypto-rng" {>= "1.0.0"}
"mirage-crypto-rng" {>= "1.2.0"}
"mirage-crypto-pk"
"mirage-crypto-ec" {>= "1.0.0"}
"x509" {>= "1.0.0"}
Expand Down
10 changes: 3 additions & 7 deletions mirage/awa_mirage.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ open Lwt.Infix
let src = Logs.Src.create "awa.mirage" ~doc:"Awa mirage"
module Log = (val Logs.src_log src : Logs.LOG)

module Make (F : Mirage_flow.S) (T : Mirage_time.S) (M : Mirage_clock.MCLOCK) = struct

module MCLOCK = M

module Make (F : Mirage_flow.S) = struct
type error = [ `Msg of string
| `Read of F.error
| `Write of F.write_error ]
Expand Down Expand Up @@ -81,8 +78,7 @@ module Make (F : Mirage_flow.S) (T : Mirage_time.S) (M : Mirage_clock.MCLOCK) =
| Ok () -> write_flow t d)
(Ok ()) bufs

let now () =
Mtime.of_uint64_ns (M.elapsed_ns ())
let now () = Mtime.of_uint64_ns (Mirage_mtime.elapsed_ns ())

let read_react t =
match t.state with
Expand Down Expand Up @@ -305,7 +301,7 @@ module Make (F : Mirage_flow.S) (T : Mirage_time.S) (M : Mirage_clock.MCLOCK) =
match server.Awa.Server.key_eol with
| None -> []
| Some mtime ->
[ T.sleep_ns (Mtime.to_uint64_ns mtime) >>= fun () -> Lwt.return Rekey ]
[ Mirage_sleep.ns (Mtime.to_uint64_ns mtime) >>= fun () -> Lwt.return Rekey ]

let rec nexus t fd server input_buffer pending_promises =
wrapr (Awa.Server.pop_msg2 server input_buffer)
Expand Down
2 changes: 1 addition & 1 deletion mirage/awa_mirage.mli
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(** Effectful operations using Mirage for pure SSH. *)

(** SSH module given a flow *)
module Make (F : Mirage_flow.S) (T : Mirage_time.S) (M : Mirage_clock.MCLOCK) : sig
module Make (F : Mirage_flow.S) : sig

(** possible errors: incoming alert, processing failure, or a
problem in the underlying flow. *)
Expand Down
2 changes: 1 addition & 1 deletion mirage/dune
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
(name awa_mirage)
(public_name awa-mirage)
(wrapped false)
(libraries awa mirage-flow mirage-clock mirage-time duration lwt mtime logs))
(libraries awa mirage-flow mirage-mtime mirage-sleep duration lwt mtime logs))
2 changes: 1 addition & 1 deletion test/awa_gen_key.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

let gen_key seed typ =
Mirage_crypto_rng_unix.initialize (module Mirage_crypto_rng.Fortuna);
Mirage_crypto_rng_unix.use_default ();
let seed = match seed with
| None -> Base64.encode_string (Mirage_crypto_rng.generate 30)
| Some x -> x
Expand Down
2 changes: 1 addition & 1 deletion test/awa_test_client.ml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ let write_cstruct fd buf =

let jump _ user pass seed typ keyfile authenticator host port =
let ( let* ) = Result.bind in
Mirage_crypto_rng_unix.initialize (module Mirage_crypto_rng.Fortuna);
Mirage_crypto_rng_unix.use_default ();
let fd = Unix.(socket PF_INET SOCK_STREAM 0) in
Unix.(connect fd (ADDR_INET (inet_addr_of_string host, port)));
match
Expand Down
2 changes: 1 addition & 1 deletion test/awa_test_server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ let rec wait_connection priv_key listen_fd server_port =
wait_connection priv_key listen_fd server_port

let jump () =
Mirage_crypto_rng_unix.initialize (module Mirage_crypto_rng.Fortuna);
Mirage_crypto_rng_unix.use_default ();
let g = Mirage_crypto_rng.(create ~seed:"180586" (module Fortuna)) in
let (ec_priv,_) = Mirage_crypto_ec.Ed25519.generate ~g () in
let priv_key = Awa.Hostkey.Ed25519_priv (ec_priv) in
Expand Down
2 changes: 1 addition & 1 deletion test/test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ let all_tests = [
]

let _ =
Mirage_crypto_rng_unix.initialize (module Mirage_crypto_rng.Fortuna);
Mirage_crypto_rng_unix.use_default ();
Sys.set_signal Sys.sigalrm (Sys.Signal_handle (fun _ -> failwith "timeout"));
Unix.chmod "data/awa_test_rsa" 0o600;
List.iter run_test all_tests;

0 comments on commit 58ffe10

Please sign in to comment.