| 1 | From: =?utf-8?q?S=C3=A9bastien_Delafond?= <[email protected]> |
| 2 | Date: Wed, 11 Dec 2019 13:51:16 -0300 |
| 3 | Subject: Use Debian provided /etc/ssl/certs/ca-certificates.crt |
| 4 | |
| 5 | Forwarded: not-needed |
| 6 | --- |
| 7 | certifi/core.py | 82 ++++++--------------------------------------------------- |
| 8 | 1 file changed, 8 insertions(+), 74 deletions(-) |
| 9 | |
| 10 | diff --git a/certifi/core.py b/certifi/core.py |
| 11 | index 1c9661c..28061f0 100644 |
| 12 | --- a/certifi/core.py |
| 13 | +++ b/certifi/core.py |
| 14 | @@ -2,82 +2,16 @@ |
| 15 | certifi.py |
| 16 | ~~~~~~~~~~ |
| 17 | |
| 18 | -This module returns the installation location of cacert.pem or its contents. |
| 19 | +This module returns the installation location of |
| 20 | +/etc/ssl/certs/ca-certificates.crt or its contents. |
| 21 | """ |
| 22 | -import sys |
| 23 | -import atexit |
| 24 | |
| 25 | -def exit_cacert_ctx() -> None: |
| 26 | - _CACERT_CTX.__exit__(None, None, None) # type: ignore[union-attr] |
| 27 | +DEBIAN_CA_CERTS_PATH = '/etc/ssl/certs/ca-certificates.crt' |
| 28 | |
| 29 | |
| 30 | -if sys.version_info >= (3, 11): |
| 31 | +def where() -> str: |
| 32 | + return DEBIAN_CA_CERTS_PATH |
| 33 | |
| 34 | - from importlib.resources import as_file, files |
| 35 | - |
| 36 | - _CACERT_CTX = None |
| 37 | - _CACERT_PATH = None |
| 38 | - |
| 39 | - def where() -> str: |
| 40 | - # This is slightly terrible, but we want to delay extracting the file |
| 41 | - # in cases where we're inside of a zipimport situation until someone |
| 42 | - # actually calls where(), but we don't want to re-extract the file |
| 43 | - # on every call of where(), so we'll do it once then store it in a |
| 44 | - # global variable. |
| 45 | - global _CACERT_CTX |
| 46 | - global _CACERT_PATH |
| 47 | - if _CACERT_PATH is None: |
| 48 | - # This is slightly janky, the importlib.resources API wants you to |
| 49 | - # manage the cleanup of this file, so it doesn't actually return a |
| 50 | - # path, it returns a context manager that will give you the path |
| 51 | - # when you enter it and will do any cleanup when you leave it. In |
| 52 | - # the common case of not needing a temporary file, it will just |
| 53 | - # return the file system location and the __exit__() is a no-op. |
| 54 | - # |
| 55 | - # We also have to hold onto the actual context manager, because |
| 56 | - # it will do the cleanup whenever it gets garbage collected, so |
| 57 | - # we will also store that at the global level as well. |
| 58 | - _CACERT_CTX = as_file(files("certifi").joinpath("cacert.pem")) |
| 59 | - _CACERT_PATH = str(_CACERT_CTX.__enter__()) |
| 60 | - atexit.register(exit_cacert_ctx) |
| 61 | - |
| 62 | - return _CACERT_PATH |
| 63 | - |
| 64 | - def contents() -> str: |
| 65 | - return files("certifi").joinpath("cacert.pem").read_text(encoding="ascii") |
| 66 | - |
| 67 | -else: |
| 68 | - |
| 69 | - from importlib.resources import path as get_path, read_text |
| 70 | - |
| 71 | - _CACERT_CTX = None |
| 72 | - _CACERT_PATH = None |
| 73 | - |
| 74 | - def where() -> str: |
| 75 | - # This is slightly terrible, but we want to delay extracting the |
| 76 | - # file in cases where we're inside of a zipimport situation until |
| 77 | - # someone actually calls where(), but we don't want to re-extract |
| 78 | - # the file on every call of where(), so we'll do it once then store |
| 79 | - # it in a global variable. |
| 80 | - global _CACERT_CTX |
| 81 | - global _CACERT_PATH |
| 82 | - if _CACERT_PATH is None: |
| 83 | - # This is slightly janky, the importlib.resources API wants you |
| 84 | - # to manage the cleanup of this file, so it doesn't actually |
| 85 | - # return a path, it returns a context manager that will give |
| 86 | - # you the path when you enter it and will do any cleanup when |
| 87 | - # you leave it. In the common case of not needing a temporary |
| 88 | - # file, it will just return the file system location and the |
| 89 | - # __exit__() is a no-op. |
| 90 | - # |
| 91 | - # We also have to hold onto the actual context manager, because |
| 92 | - # it will do the cleanup whenever it gets garbage collected, so |
| 93 | - # we will also store that at the global level as well. |
| 94 | - _CACERT_CTX = get_path("certifi", "cacert.pem") |
| 95 | - _CACERT_PATH = str(_CACERT_CTX.__enter__()) |
| 96 | - atexit.register(exit_cacert_ctx) |
| 97 | - |
| 98 | - return _CACERT_PATH |
| 99 | - |
| 100 | - def contents() -> str: |
| 101 | - return read_text("certifi", "cacert.pem", encoding="ascii") |
| 102 | +def contents() -> str: |
| 103 | + with open(where(), "r", encoding="ascii") as data: |
| 104 | + return data.read() |