handle decryption exceptions

This commit is contained in:
Eitan Chatav 2016-11-07 14:38:02 -08:00
parent 001ba994a8
commit 1733cd499a
3 changed files with 9 additions and 4 deletions

View File

@ -384,8 +384,11 @@ let connect_to_peer config limits my_gid my_public_key my_nonce my_secret_key so
| Message msg ->
push (Recv (peer, msg)) ; receiver ()
| Box msg_encr ->
let msg = Crypto_box.box_open my_secret_key public_key msg_encr (peer.current_nonce ()) in
push (Recv (peer, [B msg])) ; receiver ()
Crypto_box.box_open my_secret_key public_key msg_encr (peer.current_nonce ())
|> function
| None -> debug "(%a) cannot decrypt message (from peer) %a @ %a:%d"
pp_gid my_gid pp_gid gid Ipaddr.pp_hum addr port ; receiver ()
| Some msg -> push (Recv (peer, [B msg])) ; receiver ()
in
(* The polling loop *)
let rec pulse_monitor ping =

View File

@ -18,7 +18,9 @@ let random_keypair = Sodium.Box.random_keypair
let random_nonce = Sodium.Box.random_nonce
let increment_nonce = Sodium.Box.increment_nonce
let box = Sodium.Box.Bigbytes.box
let box_open = Sodium.Box.Bigbytes.box_open
let box_open sk pk msg nonce =
try Some (Sodium.Box.Bigbytes.box_open sk pk msg nonce) with
| Sodium.Verification_failure -> None
let to_secret_key = Sodium.Box.Bigbytes.to_secret_key
let of_secret_key = Sodium.Box.Bigbytes.of_secret_key
let to_public_key = Sodium.Box.Bigbytes.to_public_key

View File

@ -17,7 +17,7 @@ val random_keypair : unit -> secret_key * public_key
val random_nonce : unit -> nonce
val increment_nonce : ?step:int -> nonce -> nonce
val box : secret_key -> public_key -> MBytes.t -> nonce -> MBytes.t
val box_open : secret_key -> public_key -> MBytes.t -> nonce -> MBytes.t
val box_open : secret_key -> public_key -> MBytes.t -> nonce -> MBytes.t option
val to_secret_key : MBytes.t -> secret_key
val of_secret_key : secret_key -> MBytes.t
val to_public_key : MBytes.t -> public_key