diff --git a/src/binary_formats.ml b/src/binary_formats.ml index 772dd577..b77126d4 100644 --- a/src/binary_formats.ml +++ b/src/binary_formats.ml @@ -20,7 +20,12 @@ - test them - some purpose (`TALER_SIGNATURE_XXX`) are missing exchange and gana master branch are not in sync - and we should use a specific git tag instead *) + and we should use a specific git tag instead + + - clean up functor mess + don't have not hash thing be HashCode like + - have a make function for wrapped HashCode structs + make it take the relevant type *) module Taler_signatures = Include.Taler_signatures diff --git a/src/management.ml b/src/management.ml index dfe84277..ae8750be 100644 --- a/src/management.ml +++ b/src/management.ml @@ -75,35 +75,23 @@ let mk_future_denom denom_secmod_sign_f let mk_future_sign_key signkey_secmod_sign_f ({ pub; sign= _; stamp_start; stamp_expire; stamp_end } : Secmod_keys.t) = - let exchange_pub = - (* TODO - - I don't think its in crockford base 32 here - maybe SHA-512? - or maybe SHA-512 in crockford base 32 - -> no, its not a hash here - need to change ugly binary_formats functor - to not mixup hashed values with others - - have a make function for wrapped HashCode structs - make it take the relevant type *) - let v = EddsaPublicKey.to_b32 pub in - Binary_formats.ExchangePublicKeyP.{ v= { v } } - in let signkey_secmod_sig = let open Binary_formats in - let ps = - let anchor_time = - TimeAbsoluteNBO.{ v= Util.ptime_to_int64_us stamp_start } - in - let duration = - let v = - Ptime.diff stamp_start stamp_expire - |> Util.ptime_of_span_exn - |> Util.ptime_to_int64_us - in - TimeRelativeNBO.{ v } - in - SigningKeyAnnouncementPS.{ exchange_pub; anchor_time; duration } + let exchange_pub = + ExchangePublicKeyP.{ v= { v= EddsaPublicKey.to_octets pub } } in + let anchor_time = + TimeAbsoluteNBO.{ v= Util.ptime_to_int64_us stamp_start } + in + let duration = + let v = + Ptime.diff stamp_start stamp_expire + |> Util.ptime_of_span_exn + |> Util.ptime_to_int64_us + in + TimeRelativeNBO.{ v } + in + let ps = SigningKeyAnnouncementPS.{ exchange_pub; anchor_time; duration } in ps |> Bin.to_string SigningKeyAnnouncementPS.bin |> signkey_secmod_sign_f in FutureSignKey. diff --git a/src/types.ml b/src/types.ml index ac07fe92..73c500dd 100644 --- a/src/types.ml +++ b/src/types.ml @@ -82,6 +82,8 @@ module EddsaPublicKey = struct converted to Crockford Base32. *) type t = Mirage_crypto_ec.Ed25519.pub + let to_octets t = Mirage_crypto_ec.Ed25519.pub_to_octets t + let of_b32 s = let open Syntax in let open Mirage_crypto_ec in @@ -90,13 +92,14 @@ module EddsaPublicKey = struct | Error e -> Fmt.error "%a" pp_error e | Ok pub -> Ok pub - let to_b32 pub = pub |> Mirage_crypto_ec.Ed25519.pub_to_octets |> B32.encode + let to_b32 t = B32.encode (to_octets t) let jsont = Jsont.of_of_string ~kind:"EddsaPublicKey" of_b32 ~enc:to_b32 end module EddsaSignature : sig type t + val to_octets : t -> string val sign : key:Mirage_crypto_ec.Ed25519.priv -> string -> t val of_b32 : string -> (t, string) result val to_b32 : t -> string @@ -108,6 +111,8 @@ end = struct They are signature over a c-struct like `TALER_xxxPS` + with a purpose *) type t = string + let to_octets t = t + (* TODO key format is it exactly like in GNU_CRYPTO? endianess issue? *) @@ -128,6 +133,13 @@ end module RsaPublicKey = struct type t = Mirage_crypto_pk.Rsa.pub + let to_octets ({ n; e } : Mirage_crypto_pk.Rsa.pub) = + let open Binary_formats.RsaPublicKey in + let header = { n_len= Z.size n; e_len= Z.size e } in + let v = { header; n; e } in + let s = Bin.to_string bin v in + s + let of_b32 s = let open Syntax in let* s = B32.decode s in @@ -135,20 +147,14 @@ module RsaPublicKey = struct let+ v = Mirage_crypto_pk.Rsa.pub ~n:v.n ~e:v.e |> unwrap_err_msg in v - let to_b32 ({ n; e } : Mirage_crypto_pk.Rsa.pub) = - let open Binary_formats.RsaPublicKey in - let header = { n_len= Z.size n; e_len= Z.size e } in - let v = { header; n; e } in - let s = Bin.to_string bin v in - let s = B32.encode s in - s - + let to_b32 t = B32.encode (to_octets t) let jsont = Jsont.of_of_string ~kind:"RsaPublicKey" of_b32 ~enc:to_b32 end module RsaSignature : sig type t + val to_octets : t -> string val sign : key:Mirage_crypto_pk.Rsa.priv -> string -> t val of_b32 : string -> (t, string) result val to_b32 : t -> string @@ -156,6 +162,8 @@ module RsaSignature : sig end = struct type t = string + let to_octets t = t + (* no Rsa.sign(?): decrypt is equivalent to sign *) let sign ~key s =