@@ -13,16 +13,24 @@ index 42ebb8ed384..c15c0ec940f 100644
1313
1414 sslsocket_class = None # SSLSocket is assigned later.
1515 sslobject_class = None # SSLObject is assigned later.
16- @@ -531,6 +534,34 @@ def load_default_certs(self, purpose=Purpose.SERVER_AUTH):
16+ @@ -531,6 +535,41 @@ def load_default_certs(self, purpose=Purpose.SERVER_AUTH):
1717 if sys.platform == "win32":
1818 for storename in self._windows_cert_stores:
1919 self._load_windows_store_certs(storename, purpose)
20- + else :
21- + def _cert_dir_has_entries (path):
20+ + elif sys.platform == "linux" :
21+ + def _has_hashed_certs (path):
2222+ if not os.path.isdir(path):
2323+ return False
2424+ try:
25- + return next(os.scandir(path), None) is not None
25+ + for entry in os.scandir(path):
26+ + name, dot, suffix = entry.name.partition(".")
27+ + if dot and len(name) == 8 and suffix.isdigit():
28+ + try:
29+ + int(name, 16)
30+ + except ValueError:
31+ + continue
32+ + return True
33+ + return False
2634+ except OSError:
2735+ return False
2836+
@@ -31,15 +39,14 @@ index 42ebb8ed384..c15c0ec940f 100644
3139+ _def_paths[0] in os.environ or os.path.isfile(_def_paths[1])
3240+ )
3341+ _has_cert_dir = (
34- + _def_paths[2] in os.environ or _cert_dir_has_entries (_def_paths[3])
42+ + _def_paths[2] in os.environ or _has_hashed_certs (_def_paths[3])
3543+ )
36- + if sys.platform == "linux":
37- + if not _has_cert_file and os.path.isfile(self._FALLBACK_CERT_FILE):
38- + self.load_verify_locations(cafile=self._FALLBACK_CERT_FILE)
39- + _has_cert_file = True
40- + if not _has_cert_dir and _cert_dir_has_entries(self._FALLBACK_CERT_DIR):
41- + self.load_verify_locations(capath=self._FALLBACK_CERT_DIR)
42- + _has_cert_dir = True
44+ + if not _has_cert_file and os.path.isfile(self._FALLBACK_CERT_FILE):
45+ + self.load_verify_locations(cafile=self._FALLBACK_CERT_FILE)
46+ + _has_cert_file = True
47+ + if not _has_cert_dir and _has_hashed_certs(self._FALLBACK_CERT_DIR):
48+ + self.load_verify_locations(capath=self._FALLBACK_CERT_DIR)
49+ + _has_cert_dir = True
4350+ if (self._STANDALONE_CERT_FALLBACK_ENV not in os.environ and
4451+ not _has_cert_file and
4552+ not _has_cert_dir and
0 commit comments