Skip to content

Commit 78644cf

Browse files
committed
Issue #27114: Fix SSLContext._load_windows_store_certs fails with PermissionError
1 parent 6427cf4 commit 78644cf

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

Lib/ssl.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ def _import_symbols(prefix):
145145
from socket import SOL_SOCKET, SO_TYPE
146146
import base64 # for DER-to-PEM translation
147147
import errno
148+
import warnings
148149

149150

150151
socket_error = OSError # keep that public name in module namespace
@@ -405,11 +406,14 @@ def set_alpn_protocols(self, alpn_protocols):
405406

406407
def _load_windows_store_certs(self, storename, purpose):
407408
certs = bytearray()
408-
for cert, encoding, trust in enum_certificates(storename):
409-
# CA certs are never PKCS#7 encoded
410-
if encoding == "x509_asn":
411-
if trust is True or purpose.oid in trust:
412-
certs.extend(cert)
409+
try:
410+
for cert, encoding, trust in enum_certificates(storename):
411+
# CA certs are never PKCS#7 encoded
412+
if encoding == "x509_asn":
413+
if trust is True or purpose.oid in trust:
414+
certs.extend(cert)
415+
except PermissionError:
416+
warnings.warn("unable to enumerate Windows certificate store")
413417
if certs:
414418
self.load_verify_locations(cadata=certs)
415419
return certs

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ Core and Builtins
126126
Library
127127
-------
128128

129+
- Issue #27114: Fix SSLContext._load_windows_store_certs fails with
130+
PermissionError
131+
129132
- Issue #18383: Avoid creating duplicate filters when using filterwarnings
130133
and simplefilter. Based on patch by Alex Shkop.
131134

0 commit comments

Comments
 (0)