Skip to content

Commit 5d1601c

Browse files
committed
CA-370082: Block multiple definitions of certificate-chain in xe cli
User were allowed to define more than one certificate-chain when installing a host certificate. The implementation picked the first one, ignoring successive ones. This could lead to a situation where the host served a certificate with certificates missing in their chain of trust, making it unverifiable. Instead detect the situation and block the operation immediately. Signed-off-by: Pau Ruiz Safont <[email protected]>
1 parent b6f17fd commit 5d1601c

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

ocaml/xapi-cli-server/cli_operations.ml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,22 @@ let get_param params param ~default =
7171
else
7272
default
7373

74+
(** [get_unique_param param params] is intended to replace [List.assoc_opt] in
75+
the cases where a parameter can only exist once, as repeating it might
76+
force the CLI to make choices the user didn't foresee. In those cases
77+
raises an exception to warn the user to input it only once *)
78+
let get_unique_param param params =
79+
match List.find_all (fun (n, _) -> n = param) params with
80+
| [] ->
81+
None
82+
| [(_, value)] ->
83+
Some value
84+
| _ :: _ :: _ ->
85+
failwith
86+
(Printf.sprintf
87+
"Parameter %s is defined multiple times, define it only once." param
88+
)
89+
7490
open Client
7591

7692
let progress_bar printer task_record =
@@ -3606,7 +3622,7 @@ let host_install_server_certificate fd _printer rpc session_id params =
36063622
List.assoc "private-key" params |> get_file_or_fail fd "private key"
36073623
in
36083624
let certificate_chain =
3609-
List.assoc_opt "certificate-chain" params
3625+
get_unique_param "certificate-chain" params
36103626
|> Option.fold ~none:"" ~some:(get_file_or_fail fd "certificate chain")
36113627
in
36123628
ignore

0 commit comments

Comments
 (0)