wip /management
This commit is contained in:
parent
b27ebea6ee
commit
ec80a32f29
9 changed files with 154 additions and 5 deletions
|
|
@ -448,7 +448,10 @@ module DenominationKeyAnnouncementPS = struct
|
|||
anchor_time: TimeAbsoluteNBO.t;
|
||||
duration_withdraw: TimeRelativeNBO.t;
|
||||
}
|
||||
|
||||
(* TODO management *)
|
||||
(* let bin = ... *)
|
||||
let to_string _ = assert false
|
||||
end
|
||||
|
||||
module SingleWithdrawRequestPS = struct
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ end
|
|||
let coin_kudo_1 =
|
||||
Types.Config_types.Coin.
|
||||
{
|
||||
section_name= "kudo_1";
|
||||
value= amount "EUR:0.01";
|
||||
duration_withdraw= 999999;
|
||||
duration_spend= 999999;
|
||||
|
|
@ -64,5 +65,7 @@ let coin_kudo_1 =
|
|||
age_restricted= `NO;
|
||||
}
|
||||
|
||||
let coin_kudo_2 = { coin_kudo_1 with value= amount "EUR:0.02" }
|
||||
let coin_kudo_2 =
|
||||
{ coin_kudo_1 with section_name= "kudo_2"; value= amount "EUR:0.02" }
|
||||
|
||||
let coins = [ coin_kudo_1; coin_kudo_2 ]
|
||||
|
|
|
|||
12
src/json.ml
12
src/json.ml
|
|
@ -79,6 +79,7 @@ let amount_jsont =
|
|||
module EddsaPublicKey = struct
|
||||
open EddsaPublicKey
|
||||
|
||||
(* todo?: rewrite with of_of_string *)
|
||||
let jsont =
|
||||
let dec = Jsont.Base.dec_result of_string in
|
||||
let enc = Jsont.Base.enc to_string in
|
||||
|
|
@ -89,6 +90,15 @@ module EddsaSignature = struct
|
|||
let jsont = Jsont.string
|
||||
end
|
||||
|
||||
module RsaPublicKey = struct
|
||||
open RsaPublicKey
|
||||
|
||||
let jsont =
|
||||
let dec = Jsont.Base.dec_result of_string in
|
||||
let enc = Jsont.Base.enc to_string in
|
||||
Jsont.Base.string (Jsont.Base.map ~kind:"RsaPublicKey" ~dec ~enc ())
|
||||
end
|
||||
|
||||
module RsaDenominationKey = struct
|
||||
open RsaDenominationKey
|
||||
|
||||
|
|
@ -98,7 +108,7 @@ module RsaDenominationKey = struct
|
|||
let rsa_pub v = v.rsa_pub in
|
||||
Jsont.Object.map ~kind:"RsaDenominationKey" make
|
||||
|> Jsont.Object.mem "age_mask" Jsont.int ~enc:age_mask
|
||||
|> Jsont.Object.mem "rsa_pub" Jsont.string ~enc:rsa_pub
|
||||
|> Jsont.Object.mem "rsa_pub" RsaPublicKey.jsont ~enc:rsa_pub
|
||||
|> Jsont.Object.finish
|
||||
end
|
||||
|
||||
|
|
|
|||
114
src/management.ml
Normal file
114
src/management.ml
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
open Types
|
||||
|
||||
(* TODO
|
||||
- take secmod devices as param
|
||||
- key stamp/time stuff
|
||||
- hash stuff
|
||||
... *)
|
||||
|
||||
let mk_denomination_key rsa_pub =
|
||||
DenominationKey.Rsa RsaDenominationKey.{ age_mask= 0; rsa_pub }
|
||||
|
||||
let mk_future_denom denom_secmod_sign_f (denom : Secmod_denom.rsa) =
|
||||
let Config_types.Coin.
|
||||
{
|
||||
section_name;
|
||||
value;
|
||||
duration_withdraw= _;
|
||||
duration_spend= _;
|
||||
duration_legal= _;
|
||||
fee_withdraw;
|
||||
fee_deposit;
|
||||
fee_refresh;
|
||||
fee_refund;
|
||||
cipher= _;
|
||||
rsa_keysize= _;
|
||||
age_restricted= _;
|
||||
} =
|
||||
denom.coin
|
||||
in
|
||||
let denom_pub = mk_denomination_key denom.pub in
|
||||
let stamp_x = Timestamp.Never in
|
||||
let ps =
|
||||
let h_denom_pub =
|
||||
(* TODO hash *)
|
||||
let v = denom.pub |> RsaPublicKey.to_string in
|
||||
Binary_formats.DenominationHash.{ v= { v } }
|
||||
in
|
||||
let h_section_name =
|
||||
(* TODO hash *)
|
||||
let v = section_name in
|
||||
Binary_formats.HashCode.{ v }
|
||||
in
|
||||
let anchor_time = Binary_formats.TimeAbsoluteNBO.{ v= 0_L } in
|
||||
let duration_withdraw = Binary_formats.TimeRelativeNBO.{ v= 0_L } in
|
||||
Binary_formats.DenominationKeyAnnouncementPS.
|
||||
{ h_denom_pub; h_section_name; anchor_time; duration_withdraw }
|
||||
in
|
||||
let denom_secmod_sig =
|
||||
ps
|
||||
|>
|
||||
(* TODO implement DenominationKeyAnnouncementPS.bin *)
|
||||
Binary_formats.DenominationKeyAnnouncementPS.to_string
|
||||
|>
|
||||
(* TODO sig type *)
|
||||
(* Signature by the denomination security module
|
||||
not this denomination rsa signature *)
|
||||
denom_secmod_sign_f
|
||||
in
|
||||
FutureDenom.
|
||||
{
|
||||
section_name;
|
||||
value;
|
||||
stamp_start= stamp_x;
|
||||
stamp_expire_withdraw= stamp_x;
|
||||
stamp_expire_deposit= stamp_x;
|
||||
stamp_expire_legal= stamp_x;
|
||||
denom_pub;
|
||||
fee_withdraw;
|
||||
fee_deposit;
|
||||
fee_refresh;
|
||||
fee_refund;
|
||||
denom_secmod_sig;
|
||||
}
|
||||
|
||||
let mk_future_sign_key signkey_secmod_sign_f exchange_pub_key =
|
||||
let stamp_start = Timestamp.Seconds 0.0 in
|
||||
let stamp_expire = Timestamp.Never in
|
||||
let stamp_end = Timestamp.Never in
|
||||
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_string exchange_pub_key in
|
||||
Binary_formats.ExchangePublicKeyP.{ v= { v } }
|
||||
in
|
||||
let anchor_time = Binary_formats.TimeAbsoluteNBO.{ v= 0_L } in
|
||||
let duration = Binary_formats.TimeRelativeNBO.{ v= 0_L } in
|
||||
let signing_key_announcement_ps =
|
||||
Binary_formats.SigningKeyAnnouncementPS.
|
||||
{ exchange_pub; anchor_time; duration }
|
||||
in
|
||||
let signkey_secmod_sig = signkey_secmod_sign_f signing_key_announcement_ps in
|
||||
FutureSignKey.
|
||||
{
|
||||
key= exchange_pub_key;
|
||||
stamp_start;
|
||||
stamp_expire;
|
||||
stamp_end;
|
||||
signkey_secmod_sig;
|
||||
}
|
||||
|
||||
(* TODO *)
|
||||
let keys req _server _env =
|
||||
let open Vif.Response in
|
||||
let open Syntax in
|
||||
let* () = with_string req "keys .. \n" in
|
||||
let* () = add ~field:"content-type" "application/json" in
|
||||
respond `OK
|
||||
|
|
@ -112,6 +112,7 @@ let routes =
|
|||
[
|
||||
get (rel /?? nil) --> hello; get (rel / "terms" /?? nil) --> Static.terms;
|
||||
get (rel / "privacy" /?? nil) --> Static.privacy;
|
||||
get (rel / "management" / "keys" /?? nil) --> Management.keys;
|
||||
]
|
||||
|
||||
let () =
|
||||
|
|
|
|||
|
|
@ -1,7 +1,13 @@
|
|||
type rsa = {
|
||||
coin: Types.Config_types.Coin.t;
|
||||
pub: Types.RsaPublicKey.t;
|
||||
sign: string -> string;
|
||||
sign:
|
||||
(* TODO sig type
|
||||
should be
|
||||
string -> RsaSignature.t
|
||||
+ b32 *)
|
||||
string ->
|
||||
string;
|
||||
}
|
||||
|
||||
let hash_pub _pub = "todo public key converted to Crockford Base32"
|
||||
|
|
|
|||
|
|
@ -1,6 +1,12 @@
|
|||
type t = {
|
||||
pub: Mirage_crypto_ec.Ed25519.pub;
|
||||
sign: string -> string;
|
||||
sign:
|
||||
(* TODO sig type
|
||||
should be
|
||||
string -> EddsaSignature.t
|
||||
+ b32 *)
|
||||
string ->
|
||||
string;
|
||||
}
|
||||
|
||||
let make ~name =
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ module Config_types = struct
|
|||
|
||||
module Coin = struct
|
||||
type t = {
|
||||
(* section_name: Name in the configuration file that defines this denomination *)
|
||||
section_name: string;
|
||||
value: Amount.t;
|
||||
duration_withdraw: int;
|
||||
duration_spend: int;
|
||||
|
|
@ -82,6 +84,9 @@ module EddsaPublicKey = struct
|
|||
pub |> Mirage_crypto_ec.Ed25519.pub_to_octets |> B32.encode
|
||||
end
|
||||
|
||||
(* TODO sig type
|
||||
abstract type
|
||||
same for RsaSignature *)
|
||||
module EddsaSignature = struct
|
||||
(* EdDSA signatures are transmitted as 64-bytes base32
|
||||
binary-encoded objects with just the R and S values (base32_ binary-only).
|
||||
|
|
@ -130,7 +135,7 @@ end
|
|||
module RsaDenominationKey = struct
|
||||
type t = {
|
||||
age_mask: int;
|
||||
rsa_pub: string; (* Rsa.pub *)
|
||||
rsa_pub: RsaPublicKey.t;
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ let () =
|
|||
check_bad Timestamp.jsont {|{"t_s": "123456780"}|};
|
||||
check_bad Timestamp.jsont {|{"t_s": "agagou"}|};
|
||||
|
||||
(* TODO use a valid rsa_pub value *)
|
||||
check DenominationKey.jsont
|
||||
{|{"cipher": "RSA", "age_mask": 18, "rsa_pub": "agagouh"}|};
|
||||
check DenominationKey.jsont
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue