1diff --git a/certifi/core.py b/certifi/core.py 2index 91f538b..1110ce0 100644 3--- a/certifi/core.py 4+++ b/certifi/core.py 5@@ -4,6 +4,7 @@ certifi.py 6 7 This module returns the installation location of cacert.pem or its contents. 8 """ 9+import os 10 import sys 11 import atexit 12 13@@ -11,12 +12,21 @@ def exit_cacert_ctx() -> None: 14 _CACERT_CTX.__exit__(None, None, None) # type: ignore[union-attr] 15 16 17+def get_cacert_path_from_environ(): 18+ path = os.environ.get("NIX_SSL_CERT_FILE", None) 19+ 20+ if path == "/no-cert-file.crt": 21+ return None 22+ 23+ return path 24+ 25+ 26 if sys.version_info >= (3, 11): 27 28 from importlib.resources import as_file, files 29 30 _CACERT_CTX = None 31- _CACERT_PATH = None 32+ _CACERT_PATH = get_cacert_path_from_environ() 33 34 def where() -> str: 35 # This is slightly terrible, but we want to delay extracting the file 36@@ -44,6 +54,8 @@ if sys.version_info >= (3, 11): 37 return _CACERT_PATH 38 39 def contents() -> str: 40+ if _CACERT_PATH is not None: 41+ return open(_CACERT_PATH, encoding="utf-8").read() 42 return files("certifi").joinpath("cacert.pem").read_text(encoding="ascii") 43 44 elif sys.version_info >= (3, 7): 45@@ -51,7 +63,7 @@ elif sys.version_info >= (3, 7): 46 from importlib.resources import path as get_path, read_text 47 48 _CACERT_CTX = None 49- _CACERT_PATH = None 50+ _CACERT_PATH = get_cacert_path_from_environ() 51 52 def where() -> str: 53 # This is slightly terrible, but we want to delay extracting the 54@@ -80,7 +92,9 @@ elif sys.version_info >= (3, 7): 55 return _CACERT_PATH 56 57 def contents() -> str: 58- return read_text("certifi", "cacert.pem", encoding="ascii") 59+ if _CACERT_PATH is not None: 60+ return open(_CACERT_PATH, encoding="utf-8").read() 61+ return read_text("certifi", "cacert.pem", encoding="utf-8") 62 63 else: 64 import os 65@@ -90,6 +104,8 @@ else: 66 Package = Union[types.ModuleType, str] 67 Resource = Union[str, "os.PathLike"] 68 69+ _CACERT_PATH = get_cacert_path_from_environ() 70+ 71 # This fallback will work for Python versions prior to 3.7 that lack the 72 # importlib.resources module but relies on the existing `where` function 73 # so won't address issues with environments like PyOxidizer that don't set 74@@ -108,7 +124,13 @@ else: 75 def where() -> str: 76 f = os.path.dirname(__file__) 77 78+ if _CACERT_PATH is not None: 79+ return _CACERT_PATH 80+ 81 return os.path.join(f, "cacert.pem") 82 83 def contents() -> str: 84+ if _CACERT_PATH is not None: 85+ with open(_CACERT_PATH, encoding="utf-8") as data: 86+ return data.read() 87 return read_text("certifi", "cacert.pem", encoding="ascii")