★ wanayoo — archive 1999 https://github.com/certifi/python-certifi/issues/108Nouvelle recherche | Portail wanayoo
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a bootstrapping utility that makes the stdlib use certifi #108

Open
glyph opened this issue Oct 14, 2019 · 2 comments
Open

add a bootstrapping utility that makes the stdlib use certifi #108

glyph opened this issue Oct 14, 2019 · 2 comments

Comments

@glyph
Copy link
Contributor

@glyph glyph commented Oct 14, 2019 •

There are a plethora of situations where you can end up with a Python whose stdlib doesn't point SSL_CTX_set_default_verify_paths at the right location for one reason or another. (Arguably, this is the reason certifi exists.)

The relevant PEP tells you to do this:

import ssl

try:
    _create_unverified_https_context = ssl._create_unverified_context
except AttributeError:
    # Legacy Python that doesn't verify HTTPS certificates by default
    pass
else:
    # Handle target environment that doesn't support HTTPS verification
    ssl._create_default_https_context = _create_unverified_https_context

"though highly discouraged".

It's pretty obscure to figure out that you need to know that the underlying function is actually documented here: https://www.openssl.org/docs/manmaster/man3/SSL_CTX_load_verify_locations.html and not in the stdlib.

certifi should come with a function that does something like this:

import ssl
import certifi

def _create_certifi_context():
    return ssl.create_default_context(purpose=ssl.Purpose.SERVER_AUTH, cafile=certifi.where())
ssl._create_default_https_context = _create_certifi_context

and then document it clearly so that anyone wanting a functioning stdlib TLS client layer will get it by default.

@alex
Copy link
Contributor

@alex alex commented Oct 14, 2019

IMO this is beyond the scope of certifi, which should be to do literally nothing but distribute a PEM file.

@glyph
Copy link
Contributor Author

@glyph glyph commented Oct 17, 2019

IMO this is beyond the scope of certifi, which should be to do literally nothing but distribute a PEM file.

Perhaps it should be a separate package that installs a .pth file that does this? I'm not dead set on including this in certifi but it does feel like a 1-line glue function wouldn't be so far out of scope.

I've updated the description to do this in a way that actually works - to my point about how subtle this is, setting the env var works in normal dynamically linked builds of python, but embedded builds (where this is more of an issue) might have accidentally initialized OpenSSL too early.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.