Force the use of the system-wide certificate store

Olivier Renaud orenaud at coventor.com
Fri Jul 5 10:25:34 UTC 2019


Is there any way to force Mercurial to use the system-wide certificates, 
when it uses https?

By system-wide, I mean the certificate store on Windows, and the global 
ca-bundle on Linux (mine is `/etc/pki/tls/certs/ca-bundle.crt`). 
Basically, what `ssl.SSLContext.load_default_certs` uses.

I am asking because my company issues its own certificates, and every 
computer has these company-specific CA files installed already. I really 
want to use them, and not manage certificates for each program individually.

In `sslutil.py`, I can see that `_defaultcacerts` always uses the 
`certifi` python package if it exists, instead of the system-wide one. 
The comment says:

# The "certifi" Python package provides certificates. If it is installed
# and usable, assume the user intends it to be used and use it.

I disagree with this assertion. I do have `certifi` installed on my 
machine but it is not my choice: `certifi` is a direct dependency of 
`requests`, which is used by a ton of packages. I tried to uninstall 
`certifi` and it does force Mercurial to use the system-wide 
certificates, but of course it breaks all other packages that depend on 
`certifi` or `requests`. I could install Mercurial in its own virtualenv 
without `certifi`, but then I could not have `conan` in the same 
virtualenv because `conan` depends on `requests`, which depends on 
`certifi`.

On Linux, a workaround is to define 
`web.cacerts=/etc/pki/tls/certs/ca-bundle.crt`. But even then, this path 
depends on the Linux distrib and its version. But on Windows I think 
there is nothing I can do.

It seems that at some point in 2015, `web.cacerts` could be set to 
`None` to force the use of the system-wide certificates 
(https://www.mercurial-scm.org/repo/hg/rev/760a86865f80). This is not 
the case anymore.

My ideal behavior would be for Mercurial to trust both the system-wide 
certificates and the ones from `certifi`, and for `web.cacerts` to be 
either a path to a crt bundle, or a special value "certifi", or a 
special value "system". I would be happy with any workaround you could 
think of, though!

Olivier Renaud



More information about the Mercurial mailing list