@@ -23,7 +23,7 @@ exception Stunnel_binary_missing
2323
2424exception Stunnel_error of string
2525
26- exception Stunnel_verify_error of string
26+ exception Stunnel_verify_error of string list
2727
2828let crl_path = " /etc/stunnel/crls"
2929
@@ -138,7 +138,7 @@ type t = {
138138}
139139
140140type stunnel_error =
141- | Certificate_verify of string
141+ | Certificate_verify of string list
142142 | Stunnel of string
143143 | Unknown of string
144144
@@ -489,14 +489,7 @@ let with_client_proxy_systemd_service ~verify_cert ~remote_host ~remote_port
489489 )
490490 (fun () -> Unixext. unlink_safe conf_path)
491491
492- let check_verify_error line =
493- let sub_after i s =
494- let len = String. length s in
495- String. sub s i (len - i)
496- in
497- let split_1 c s =
498- match Astring.String. cut ~sep: c s with Some (x , _ ) -> x | None -> s
499- in
492+ let check_verify_error cert_errors line =
500493 (* When verified with a mismatched certificate, one line of log from stunnel
501494 * would look like:
502495 SSL_connect: ssl/statem/statem_clnt.c:1889: error:0A000086:SSL routines::certificate verify failed
@@ -505,17 +498,14 @@ let check_verify_error line =
505498 if Astring.String. is_infix ~affix: " certificate verify failed" line then
506499 match Astring.String. find_sub ~sub: " error:" line with
507500 | Some e ->
508- raise
509- (Stunnel_verify_error
510- (split_1 " ," (sub_after (e + String. length " error:" ) line))
511- )
501+ raise (Stunnel_verify_error cert_errors)
512502 | None ->
513- raise (Stunnel_verify_error " " )
503+ raise (Stunnel_verify_error [] )
514504 else if
515505 Astring.String. is_infix ~affix: " No certificate or private key specified"
516506 line
517507 then
518- raise (Stunnel_verify_error " The specified certificate is corrupt" )
508+ raise (Stunnel_verify_error [ " The specified certificate is corrupt" ] )
519509 else
520510 ()
521511
@@ -524,9 +514,12 @@ let check_error s line =
524514 raise (Stunnel_error s)
525515
526516let check_stunnel_logfile logfile =
517+ let cert_errors = ref [] in
527518 let check_line line =
528519 ! stunnel_logger line ;
529- check_verify_error line ;
520+ if Astring.String. is_infix ~affix: " CERT:" line then
521+ cert_errors := line :: ! cert_errors ;
522+ check_verify_error ! cert_errors line ;
530523 check_error " Connection refused" line ;
531524 check_error " No host resolved" line ;
532525 check_error " No route to host" line ;
@@ -540,8 +533,8 @@ let check_stunnel_status logfile =
540533 match check_stunnel_logfile logfile with
541534 | () ->
542535 Ok ()
543- | exception Stunnel_verify_error reason ->
544- Error (Certificate_verify reason )
536+ | exception Stunnel_verify_error r ->
537+ Error (Certificate_verify r )
545538 | exception Stunnel_error reason ->
546539 Error (Stunnel reason)
547540 | exception exn ->
0 commit comments