RPC: Add TLS on the client

This commit is contained in:
Vincent Bernardoff 2016-12-01 22:42:28 +01:00
parent 77506ac4b5
commit 59881cde32
2 changed files with 15 additions and 4 deletions

View File

@ -85,6 +85,10 @@ let incoming_port = in_both_groups @@
new int_cp [ "port" ] ~short_name:"P" 8732
"The TCP port at which the node's RPC server can be reached."
let tls = in_both_groups @@
new bool_cp [ "tls" ] false
"Use TLS to connect to node."
(* Version specific options *)
let contextual_options : (unit -> unit) ref Protocol_hash_table.t =
@ -191,6 +195,11 @@ let preparse_args argv cctxt : Node_rpc_services.Blocks.block Lwt.t =
"Error: can't read the configuration file: %s\n%!" msg
else Lwt.return ()
end >>= fun () ->
begin
match preparse "-tls" argv with
| None -> ()
| Some _ -> tls#set true
end ;
begin
match preparse "-addr" argv with
| None -> ()

View File

@ -24,10 +24,12 @@ let cpt = ref 0
let make_request cctxt service json =
incr cpt ;
let cpt = !cpt in
let serv = "http://" ^ Client_config.incoming_addr#get
^ ":" ^ string_of_int Client_config.incoming_port#get in
let string_uri = String.concat "/" (serv :: service) in
let uri = Uri.of_string string_uri in
let scheme = if Client_config.tls#get then "https" else "http" in
let host = Client_config.incoming_addr#get in
let port = Client_config.incoming_port#get in
let path = String.concat "/" service in
let uri = Uri.make ~scheme ~host ~port ~path () in
let string_uri = Uri.to_string uri in
let reqbody = Data_encoding_ezjsonm.to_string json in
let tzero = Unix.gettimeofday () in
catch