Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

roll our own dsa_to/of_sexp, since mirage-crypto-pk will remove these functions soon #228

Merged
merged 1 commit into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/persistency.ml
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,16 @@ let load_password cfgdir =

let otr_dsa = "otr_dsa.sexp"

let sexp_of_priv Mirage_crypto_pk.Dsa.{ p ; q ; gg ; x ; y } =
let open Conv in
let sexp_of_z z = sexp_of_string (Z.to_string z) in
sexp_of_list (sexp_of_pair sexp_of_string sexp_of_z)
[ "p", p; "q", q; "gg", gg; "x", x; "y", y ]

let dump_dsa cfgdir dsa =
write cfgdir otr_dsa (Bytes.of_string (Sexp.to_string_hum (Mirage_crypto_pk.Dsa.sexp_of_priv dsa)))
write cfgdir otr_dsa (Bytes.of_string (Sexp.to_string_hum (sexp_of_priv dsa)))

let load_dsa cfgdir =
read cfgdir otr_dsa >|= function
| None -> None
| Some x -> Some (Mirage_crypto_pk.Dsa.priv_of_sexp (Sexp.of_string x))
| Some x -> Some (Xconfig.dsa_priv_of_sexp (Sexp.of_string x))
11 changes: 10 additions & 1 deletion src/xconfig.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ type t = {

let current_version = 3

let dsa_priv_of_sexp s =
let z_of_sexp s = Z.of_string (string_of_sexp s) in
match list_of_sexp (pair_of_sexp string_of_sexp z_of_sexp) s with
| [ "p", p; "q", q; "gg", gg; "x", x; "y", y ] ->
(match Mirage_crypto_pk.Dsa.priv ?fips:None ~p ~q ~gg ~x ~y () with
| Ok p -> p
| Error (`Msg m) -> invalid_arg ("bad private " ^ m))
| _ -> raise (Of_sexp_error (Failure "expected p, q, gg, x, and y'", s))

let dsa_of_cfg_sexp t =
match t with
| Sexp.List l ->
Expand All @@ -33,7 +42,7 @@ let dsa_of_cfg_sexp t =
List.fold_left (fun (dsa, cfg) -> function
| Sexp.List [ Sexp.Atom "policies" ; _ ] as p -> (dsa, p :: cfg)
| Sexp.List [ Sexp.Atom "versions" ; _ ] as v -> (dsa, v :: cfg)
| Sexp.List [ Sexp.Atom "dsa" ; d ] -> (Some (Mirage_crypto_pk.Dsa.priv_of_sexp d), cfg)
| Sexp.List [ Sexp.Atom "dsa" ; d ] -> (Some (dsa_priv_of_sexp d), cfg)
| _ -> raise (Invalid_argument "broken sexp while trying to find dsa"))
(dsa, cfg) data
| _ -> (dsa, cfg))
Expand Down