diff --git a/mercurial/sslutil.py b/mercurial/sslutil.py --- a/mercurial/sslutil.py +++ b/mercurial/sslutil.py @@ -268,7 +268,12 @@ def wrapsocket(sock, keyfile, certfile, sslcontext.load_cert_chain(certfile, keyfile, password) if settings['cafile'] is not None: - sslcontext.load_verify_locations(cafile=settings['cafile']) + try: + sslcontext.load_verify_locations(cafile=settings['cafile']) + except ssl.SSLError as e: + raise error.Abort(_('error loading CA file %s: %s') % ( + settings['cafile'], e.args[1]), + hint=_('file is empty or malformed?')) caloaded = True elif settings['allowloaddefaultcerts']: # This is a no-op on old Python. diff --git a/tests/test-https.t b/tests/test-https.t --- a/tests/test-https.t +++ b/tests/test-https.t @@ -62,9 +62,16 @@ Specifying a per-host certificate file t A malformed per-host certificate file will raise an error $ echo baddata > badca.pem +#if sslcontext + $ hg --config hostsecurity.localhost:verifycertsfile=badca.pem clone https://localhost:$HGPORT/ + abort: error loading CA file badca.pem: * (glob) + (file is empty or malformed?) + [255] +#else $ hg --config hostsecurity.localhost:verifycertsfile=badca.pem clone https://localhost:$HGPORT/ abort: error: * (glob) [255] +#endif A per-host certificate mismatching the server will fail verification @@ -183,10 +190,19 @@ variables in the filename empty cacert file $ touch emptycafile + +#if sslcontext + $ hg --config web.cacerts=emptycafile -R copy-pull pull + pulling from https://localhost:$HGPORT/ + abort: error loading CA file emptycafile: * (glob) + (file is empty or malformed?) + [255] +#else $ hg --config web.cacerts=emptycafile -R copy-pull pull pulling from https://localhost:$HGPORT/ abort: error: * (glob) [255] +#endif cacert mismatch