Skip to content

Commit bec4ca6

Browse files
committed
CA-404460: Expose Stunnel_verify_error for mismatched certificate
Xapi uses stunnel to connect to remote peer and exposes certificate verify error by parsing stunnel logs. And when connect with a mismatched certificate, the log from stunnel would be: stunnel 5.60 on x86_64-koji-linux-gnu platform Compiled/running with OpenSSL 3.0.9 30 May 2023 Threading:PTHREAD Sockets:POLL,IPv6 TLS:ENGINE,OCSP,SNI Auth:LIBWRAP Reading configuration from descriptor 8 UTF-8 byte order mark not detected FIPS mode disabled Configuration successful Service [stunnel] accepted connection from unnamed socket s_connect: connected 10.63.96.116:443 Service [stunnel] connected remote server from 10.63.97.76:34138 CERT: Pre-verification error: self-signed certificate Rejected by CERT at depth=0: CN=10.63.96.116 SSL_connect: ssl/statem/statem_clnt.c:1889: error:0A000086:SSL routines::certificate verify failed Connection reset: 0 byte(s) sent to TLS, 0 byte(s) sent to socket This commit fixes the exposing of Stunnel_verify_error by checking "certificate verify failed" in the log, and expose it with reason "0A000086:SSL routines::certificate verify failed". We can find that the log "VERIFY ERROR" is not print by stunnel 5.60, which is the version of stunnel used in XS now, but it indeed was printed before: 20d6d2faf740ee5eb9b13752b076ee583fec94d8:src/verify.c: s_log(LOG_WARNING, "VERIFY ERROR: depth=%d, error=%s: %s", [gangj@xenrt10715872 stunnel]$ git branch --contains 20d6d2faf740ee5eb9b13752b076ee583fec94d8 master * private/gangj/stunnel-5.60 While we can find the log "certificate verify failed" which comes from openssl library: https://github.com/openssl/openssl/blob/openssl-3.0.9/ssl/ssl_err.c {ERR_PACK(ERR_LIB_SSL, 0, SSL_R_CERTIFICATE_VERIFY_FAILED), "certificate verify failed"}, Signed-off-by: Gang Ji <[email protected]>
1 parent 18e93ff commit bec4ca6

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

ocaml/libs/stunnel/stunnel.ml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -483,12 +483,17 @@ let check_verify_error line =
483483
let split_1 c s =
484484
match Astring.String.cut ~sep:c s with Some (x, _) -> x | None -> s
485485
in
486-
if Astring.String.is_infix ~affix:"VERIFY ERROR: " line then
487-
match Astring.String.find_sub ~sub:"error=" line with
486+
(* When verified with a mismatched certificate, one line of log from stunnel
487+
* would look like:
488+
SSL_connect: ssl/statem/statem_clnt.c:1889: error:0A000086:SSL routines::certificate verify failed
489+
* in this case, Stunnel_verify_error can be raised with detailed error as
490+
* reason if it can found in the log *)
491+
if Astring.String.is_infix ~affix:"certificate verify failed" line then
492+
match Astring.String.find_sub ~sub:"error:" line with
488493
| Some e ->
489494
raise
490495
(Stunnel_verify_error
491-
(split_1 "," (sub_after (e + String.length "error=") line))
496+
(split_1 "," (sub_after (e + String.length "error:") line))
492497
)
493498
| None ->
494499
raise (Stunnel_verify_error "")

0 commit comments

Comments
 (0)