Skip to content

Commit afe37ec

Browse files
authored
CA-404460: Expose Stunnel_verify_error for mismatched or corrupted certificate, and expose ssl_verify_error during update syncing (#6376)
Pls refer to commit msg for details
2 parents e53aec6 + 15df700 commit afe37ec

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

ocaml/libs/stunnel/stunnel.ml

+14-4
Original file line numberDiff line numberDiff line change
@@ -478,20 +478,30 @@ let check_verify_error line =
478478
let split_1 c s =
479479
match Astring.String.cut ~sep:c s with Some (x, _) -> x | None -> s
480480
in
481-
if Astring.String.is_infix ~affix:"VERIFY ERROR: " line then
482-
match Astring.String.find_sub ~sub:"error=" line with
481+
(* When verified with a mismatched certificate, one line of log from stunnel
482+
* would look like:
483+
SSL_connect: ssl/statem/statem_clnt.c:1889: error:0A000086:SSL routines::certificate verify failed
484+
* in this case, Stunnel_verify_error can be raised with detailed error as
485+
* reason if it can found in the log *)
486+
if Astring.String.is_infix ~affix:"certificate verify failed" line then
487+
match Astring.String.find_sub ~sub:"error:" line with
483488
| Some e ->
484489
raise
485490
(Stunnel_verify_error
486-
(split_1 "," (sub_after (e + String.length "error=") line))
491+
(split_1 "," (sub_after (e + String.length "error:") line))
487492
)
488493
| None ->
489494
raise (Stunnel_verify_error "")
495+
else if
496+
Astring.String.is_infix ~affix:"No certificate or private key specified"
497+
line
498+
then
499+
raise (Stunnel_verify_error "The specified certificate is corrupt")
490500
else
491501
()
492502
493503
let check_error s line =
494-
if Astring.String.is_infix ~affix:line s then
504+
if Astring.String.is_infix ~affix:s line then
495505
raise (Stunnel_error s)
496506
497507
let diagnose_failure st_proc =

ocaml/xapi/repository.ml

+2
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,8 @@ let sync ~__context ~self ~token ~token_id ~username ~password =
306306
with
307307
| Api_errors.Server_error (_, _) as e ->
308308
raise e
309+
| Stunnel.Stunnel_verify_error reason ->
310+
raise (Api_errors.Server_error (Api_errors.ssl_verify_error, [reason]))
309311
| e ->
310312
error "Failed to sync with remote YUM repository: %s"
311313
(ExnHelper.string_of_exn e) ;

0 commit comments

Comments
 (0)