Skip to content

Commit bff1e6a

Browse files
committed
Vendor truststore 0.8.0
1 parent fca773c commit bff1e6a

File tree

5 files changed

+41
-22
lines changed

5 files changed

+41
-22
lines changed

news/truststore.vendor.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Add truststore 0.7.0
1+
Add truststore 0.8.0

src/pip/_vendor/truststore/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010
del _api, _sys # type: ignore[name-defined] # noqa: F821
1111

1212
__all__ = ["SSLContext", "inject_into_ssl", "extract_from_ssl"]
13-
__version__ = "0.7.0"
13+
__version__ = "0.8.0"

src/pip/_vendor/truststore/_api.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
import array
2-
import ctypes
3-
import mmap
41
import os
5-
import pickle
62
import platform
73
import socket
84
import ssl
95
import typing
106

117
import _ssl # type: ignore[import]
128

13-
from ._ssl_constants import _original_SSLContext, _original_super_SSLContext
9+
from ._ssl_constants import (
10+
_original_SSLContext,
11+
_original_super_SSLContext,
12+
_truststore_SSLContext_dunder_class,
13+
_truststore_SSLContext_super_class,
14+
)
1415

1516
if platform.system() == "Windows":
1617
from ._windows import _configure_context, _verify_peercerts_impl
@@ -19,21 +20,13 @@
1920
else:
2021
from ._openssl import _configure_context, _verify_peercerts_impl
2122

23+
if typing.TYPE_CHECKING:
24+
from pip._vendor.typing_extensions import Buffer
25+
2226
# From typeshed/stdlib/ssl.pyi
2327
_StrOrBytesPath: typing.TypeAlias = str | bytes | os.PathLike[str] | os.PathLike[bytes]
2428
_PasswordType: typing.TypeAlias = str | bytes | typing.Callable[[], str | bytes]
2529

26-
# From typeshed/stdlib/_typeshed/__init__.py
27-
_ReadableBuffer: typing.TypeAlias = typing.Union[
28-
bytes,
29-
memoryview,
30-
bytearray,
31-
"array.array[typing.Any]",
32-
mmap.mmap,
33-
"ctypes._CData",
34-
pickle.PickleBuffer,
35-
]
36-
3730

3831
def inject_into_ssl() -> None:
3932
"""Injects the :class:`truststore.SSLContext` into the ``ssl``
@@ -61,9 +54,16 @@ def extract_from_ssl() -> None:
6154
pass
6255

6356

64-
class SSLContext(ssl.SSLContext):
57+
class SSLContext(_truststore_SSLContext_super_class): # type: ignore[misc]
6558
"""SSLContext API that uses system certificates on all platforms"""
6659

60+
@property # type: ignore[misc]
61+
def __class__(self) -> type:
62+
# Dirty hack to get around isinstance() checks
63+
# for ssl.SSLContext instances in aiohttp/trustme
64+
# when using non-CPython implementations.
65+
return _truststore_SSLContext_dunder_class or SSLContext
66+
6767
def __init__(self, protocol: int = None) -> None: # type: ignore[assignment]
6868
self._ctx = _original_SSLContext(protocol)
6969

@@ -129,7 +129,7 @@ def load_verify_locations(
129129
self,
130130
cafile: str | bytes | os.PathLike[str] | os.PathLike[bytes] | None = None,
131131
capath: str | bytes | os.PathLike[str] | os.PathLike[bytes] | None = None,
132-
cadata: str | _ReadableBuffer | None = None,
132+
cadata: typing.Union[str, "Buffer", None] = None,
133133
) -> None:
134134
return self._ctx.load_verify_locations(
135135
cafile=cafile, capath=capath, cadata=cadata
@@ -252,7 +252,7 @@ def protocol(self) -> ssl._SSLMethod:
252252
return self._ctx.protocol
253253

254254
@property
255-
def security_level(self) -> int: # type: ignore[override]
255+
def security_level(self) -> int:
256256
return self._ctx.security_level
257257

258258
@property

src/pip/_vendor/truststore/_ssl_constants.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,29 @@
11
import ssl
2+
import sys
3+
import typing
24

35
# Hold on to the original class so we can create it consistently
46
# even if we inject our own SSLContext into the ssl module.
57
_original_SSLContext = ssl.SSLContext
68
_original_super_SSLContext = super(_original_SSLContext, _original_SSLContext)
79

10+
# CPython is known to be good, but non-CPython implementations
11+
# may implement SSLContext differently so to be safe we don't
12+
# subclass the SSLContext.
13+
14+
# This is returned by truststore.SSLContext.__class__()
15+
_truststore_SSLContext_dunder_class: typing.Optional[type]
16+
17+
# This value is the superclass of truststore.SSLContext.
18+
_truststore_SSLContext_super_class: type
19+
20+
if sys.implementation.name == "cpython":
21+
_truststore_SSLContext_super_class = _original_SSLContext
22+
_truststore_SSLContext_dunder_class = None
23+
else:
24+
_truststore_SSLContext_super_class = object
25+
_truststore_SSLContext_dunder_class = _original_SSLContext
26+
827

928
def _set_ssl_context_verify_mode(
1029
ssl_context: ssl.SSLContext, verify_mode: ssl.VerifyMode

src/pip/_vendor/vendor.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ setuptools==68.0.0
2020
six==1.16.0
2121
tenacity==8.2.2
2222
tomli==2.0.1
23-
truststore==0.7.0
23+
truststore==0.8.0
2424
webencodings==0.5.1

0 commit comments

Comments
 (0)