Skip to content

Commit 99c92d3

Browse files
thomassarobhoes
authored andcommitted
get_nbd_info: use hostname if cert parsing fails
If the x509 library raises an exception when trying to parse a host's certificate and read a subject out of it, log the error and fall back to using Host.hostname. Signed-off-by: Thomas Sanders <[email protected]>
1 parent f712756 commit 99c92d3

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

ocaml/xapi/xapi_vdi.ml

Lines changed: 5 additions & 1 deletion
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 = match Certificates.hostnames_of_pem_cert cert with
1075+
let subject = try match Certificates.hostnames_of_pem_cert cert with
10761076
| [] -> (
10771077
error "Found no subject DNS names in this hosts's certificate. Returning empty string as subject.";
10781078
""
10791079
)
10801080
| name :: _ -> name
1081+
with e -> (
1082+
error "get_nbd_info: failed to read subject from TLS certificate! Falling back to Host.hostname. Exn was %s" (ExnHelper.string_of_exn e);
1083+
Db.Host.get_hostname ~__context ~self:host
1084+
)
10811085
in
10821086
let template = API.{
10831087
vdi_nbd_server_info_exportname = exportname;

0 commit comments

Comments
 (0)