Force the use of the system-wide certificate store
Augie Fackler
raf at durin42.com
Tue Jul 9 22:25:59 UTC 2019
> On Jul 5, 2019, at 06:25, Olivier Renaud <orenaud at coventor.com> wrote:
>
> 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!
It sounds like a virtuous request - could you file a feature request in bugzilla for a way to disable certifi even if present? Or if you're comfortable with it, send us a patch (it sounds like you're already deep enough in the code to know where the changes should be made!), that's even more likely to land.
I'd probably make it something like `web.cacerts-use-certifi = false` or something to disable automatic use of certifi.
>
> Olivier Renaud
>
> _______________________________________________
> Mercurial mailing list
> Mercurial at mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial
More information about the Mercurial
mailing list