diff --git a/src/bin_signer/socket_daemon.ml b/src/bin_signer/socket_daemon.ml index f5d77e632..ba61a80b0 100644 --- a/src/bin_signer/socket_daemon.ml +++ b/src/bin_signer/socket_daemon.ml @@ -43,7 +43,6 @@ let run (cctxt : #Client_context.wallet) path ?magic_bytes ~require_auth = end ; loop () in - Lwt_unix.listen fd 10 ; begin match path with | Tcp (host, port) -> diff --git a/src/lib_signer_backends/http_gen.ml b/src/lib_signer_backends/http_gen.ml index bdddb69c6..23d6e9a6e 100644 --- a/src/lib_signer_backends/http_gen.ml +++ b/src/lib_signer_backends/http_gen.ml @@ -57,7 +57,9 @@ module Make(N : sig val scheme : string end) = struct | None -> failwith "Invalid locator %a" Uri.pp_hum uri | Some i -> - let pkh = String.sub path (i + 1) (String.length path - i - 1) in + let pkh = + try String.sub path (i + 1) (String.length path - i - 1) + with _ -> "" in let path = String.sub path 0 i in return (Uri.with_path uri path, pkh) end >>=? fun (base, pkh) -> diff --git a/src/lib_signer_backends/socket.ml b/src/lib_signer_backends/socket.ml index 8376e67d9..452f9cdd1 100644 --- a/src/lib_signer_backends/socket.ml +++ b/src/lib_signer_backends/socket.ml @@ -23,19 +23,24 @@ module Make(P : sig | None -> msg | Some watermark -> MBytes.concat "" [ Signature.bytes_of_watermark watermark ; msg ] in - Lwt_utils_unix.Socket.connect path >>=? fun conn -> - Lwt_utils_unix.Socket.send - conn Request.encoding Request.Authorized_keys >>=? fun () -> - Lwt_utils_unix.Socket.recv conn - Authorized_keys.Response.encoding >>=? fun authorized_keys -> - begin match authorized_keys with - | No_authentication -> return None - | Authorized_keys authorized_keys -> - P.authenticate authorized_keys - (Sign.Request.to_sign ~pkh ~data:msg) >>=? fun signature -> - return (Some signature) + begin + Lwt_utils_unix.Socket.connect path >>=? fun conn -> + Lwt_utils_unix.Socket.send + conn Request.encoding Request.Authorized_keys >>=? fun () -> + Lwt_utils_unix.Socket.recv conn + (result_encoding Authorized_keys.Response.encoding) >>=? fun authorized_keys -> + Lwt.return authorized_keys >>=? fun authorized_keys -> + Lwt_unix.close conn >>= fun () -> + begin match authorized_keys with + | No_authentication -> return None + | Authorized_keys authorized_keys -> + P.authenticate authorized_keys + (Sign.Request.to_sign ~pkh ~data:msg) >>=? fun signature -> + return (Some signature) + end end >>=? fun signature -> let req = { Sign.Request.pkh ; data = msg ; signature } in + Lwt_utils_unix.Socket.connect path >>=? fun conn -> Lwt_utils_unix.Socket.send conn Request.encoding (Request.Sign req) >>=? fun () -> Lwt_utils_unix.Socket.recv conn @@ -61,7 +66,7 @@ module Make(P : sig let description = "Valid locators are of the form\n\ - \ - unix:///path/to/socket?pkh=tz1..." + \ - unix:/path/to/socket?pkh=tz1..." let parse uri = assert (Uri.scheme uri = Some scheme) ; @@ -109,8 +114,12 @@ module Make(P : sig | _, None -> failwith "Missing host port" | Some path, Some port -> + let pkh = Uri.path uri in + let pkh = + try String.(sub pkh 1 (length pkh - 1)) + with _ -> "" in Lwt.return - (Signature.Public_key_hash.of_b58check (Uri.path uri)) >>=? fun pkh -> + (Signature.Public_key_hash.of_b58check pkh) >>=? fun pkh -> return (Lwt_utils_unix.Socket.Tcp (path, port), pkh) let public_key uri = diff --git a/src/lib_signer_services/signer_messages.ml b/src/lib_signer_services/signer_messages.ml index 0c1064f6d..cf1a2be29 100644 --- a/src/lib_signer_services/signer_messages.ml +++ b/src/lib_signer_services/signer_messages.ml @@ -19,7 +19,7 @@ module Sign = struct let to_sign ~pkh ~data = MBytes.concat "" - [ MBytes.of_hex (`Hex "04") ; + [ MBytes.of_string "\x04" ; Signature.Public_key_hash.to_bytes pkh ; data ] diff --git a/src/lib_stdlib_unix/lwt_utils_unix.ml b/src/lib_stdlib_unix/lwt_utils_unix.ml index 85835240d..b01056e05 100644 --- a/src/lib_stdlib_unix/lwt_utils_unix.ml +++ b/src/lib_stdlib_unix/lwt_utils_unix.ml @@ -285,7 +285,7 @@ module Socket = struct | Tcp (host, port) -> get_addrs host >>=? fun addrs -> let rec try_connect = function - | [] -> failwith "..." + | [] -> failwith "could not resolve host '%s'" host | addr :: addrs -> Lwt.catch (fun () -> @@ -307,7 +307,7 @@ module Socket = struct | Tcp (host, port) -> get_addrs host >>=? fun addrs -> let rec try_bind = function - | [] -> failwith "..." + | [] -> failwith "could not resolve host '%s'" host | addr :: addrs -> Lwt.catch (fun () -> @@ -328,18 +328,18 @@ module Socket = struct register_error_kind `Permanent ~id: "signer.encoding_error" ~title: "Encoding_error" - ~description: "Error while encoding a request to the remote signer" + ~description: "Error while encoding a remote signer message" ~pp: (fun ppf () -> - Format.fprintf ppf "Could not encode a request to the remote signer") + Format.fprintf ppf "Could not encode a remote signer message") Data_encoding.empty (function Encoding_error -> Some () | _ -> None) (fun () -> Encoding_error) ; register_error_kind `Permanent ~id: "signer.decoding_error" ~title: "Decoding_error" - ~description: "Error while decoding a request to the remote signer" + ~description: "Error while decoding a remote signer message" ~pp: (fun ppf () -> - Format.fprintf ppf "Could not decode a request to the remote signer") + Format.fprintf ppf "Could not decode a remote signer message") Data_encoding.empty (function Decoding_error -> Some () | _ -> None) (fun () -> Decoding_error)