Skip to content

Commit e9b0390

Browse files
committed
CP-25372: Prefer non-wildcard certificate subjects
In the VDI.get_nbd_info function, when reading a TLS certificate and choosing a subject from it to include in the return value, avoid wildcard subjects if possible: return a concrete hostname (DNS name) if there is one, and a wildcard only as a last resort. Signed-off-by: Thomas Sanders <[email protected]>
1 parent f3d1e38 commit e9b0390

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

ocaml/xapi/xapi_vdi.ml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,12 +1072,16 @@ let _get_nbd_info ~__context ~self ~get_server_certificate =
10721072
if ips = [] then [] else
10731073
let cert = get_server_certificate ~host in
10741074
let port = 10809L in
1075-
let subject = try match Certificates.hostnames_of_pem_cert cert with
1075+
let rec seek = function
10761076
| [] -> (
10771077
error "Found no subject DNS names in this hosts's certificate. Returning empty string as subject.";
10781078
""
10791079
)
1080-
| name :: _ -> name
1080+
| last :: [] -> last (* Better to return a possible wildcard than nothing *)
1081+
| name :: xs -> if (String.contains name '*') then seek xs else name
1082+
in
1083+
let subject = try
1084+
seek (Certificates.hostnames_of_pem_cert cert)
10811085
with e -> (
10821086
error "get_nbd_info: failed to read subject from TLS certificate! Falling back to Host.hostname. Exn was %s" (ExnHelper.string_of_exn e);
10831087
Db.Host.get_hostname ~__context ~self:host

0 commit comments

Comments
 (0)