codekingpro/portable-devtools
114k
1"""Utilities for certificate management."""2 3import os4 5certifi_available = False6certifi_where = None7try:8 from certifi import where as certifi_where9 certifi_available = True10except ImportError:11 pass12 13custom_ca_locater_available = False14custom_ca_locater_where = None15try:16 from ca_certs_locater import get as custom_ca_locater_where17 custom_ca_locater_available = True18except ImportError:19 pass20 21 22BUILTIN_CA_CERTS = os.path.join(23 os.path.dirname(os.path.abspath(__file__)), "cacerts.txt"24)25 26 27def where():28 env = os.environ.get("HTTPLIB2_CA_CERTS")29 if env is not None:30 if os.path.isfile(env):31 return env32 else:33 raise RuntimeError("Environment variable HTTPLIB2_CA_CERTS not a valid file")34 if custom_ca_locater_available:35 return custom_ca_locater_where()36 if certifi_available:37 return certifi_where()38 return BUILTIN_CA_CERTS39 40 41if __name__ == "__main__":42 print(where())43 