Skip to content

Commit 6365e70

Browse files
committed
undo other changes
1 parent 9b734fd commit 6365e70

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

pymongo/ocsp_support.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,13 @@ def _ocsp_callback(conn: Connection, ocsp_bytes: bytes, user_data: Optional[_Cal
347347
_LOGGER.debug("No peer cert?")
348348
return False
349349
cert = pycert.to_cryptography()
350-
pychain = conn.get_verified_chain()
351-
trusted_ca_certs = None
350+
# Use the verified chain when available (pyopenssl>=20.0).
351+
if hasattr(conn, "get_verified_chain"):
352+
pychain = conn.get_verified_chain()
353+
trusted_ca_certs = None
354+
else:
355+
pychain = conn.get_peer_cert_chain()
356+
trusted_ca_certs = user_data.trusted_ca_certs
352357
if not pychain:
353358
_LOGGER.debug("No peer cert chain?")
354359
return False

pymongo/pyopenssl_context.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
from pymongo.errors import ConfigurationError as _ConfigurationError
3636
from pymongo.errors import _CertificateError # type:ignore[attr-defined]
3737
from pymongo.ocsp_cache import _OCSPCache
38-
from pymongo.ocsp_support import _ocsp_callback
38+
from pymongo.ocsp_support import _load_trusted_ca_certs, _ocsp_callback
3939
from pymongo.socket_checker import SocketChecker as _SocketChecker
4040
from pymongo.socket_checker import _errno_from_exception
4141
from pymongo.write_concern import validate_boolean
@@ -322,6 +322,10 @@ def load_verify_locations(
322322
ssl.CERT_NONE.
323323
"""
324324
self._ctx.load_verify_locations(cafile, capath)
325+
# Manually load the CA certs when get_verified_chain is not available (pyopenssl<20).
326+
if not hasattr(_SSL.Connection, "get_verified_chain"):
327+
assert cafile is not None
328+
self._callback_data.trusted_ca_certs = _load_trusted_ca_certs(cafile)
325329

326330
def _load_certifi(self) -> None:
327331
"""Attempt to load CA certs from certifi."""

test/asynchronous/test_dns.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,8 @@
3030
unittest,
3131
)
3232
from test.utils_shared import async_wait_until
33-
from test.version import Version
3433
from unittest.mock import MagicMock, patch
3534

36-
import pytest
37-
3835
from pymongo.asynchronous.uri_parser import parse_uri
3936
from pymongo.common import validate_read_preference_tags
4037
from pymongo.errors import ConfigurationError

test/test_dns.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,8 @@
3030
unittest,
3131
)
3232
from test.utils_shared import wait_until
33-
from test.version import Version
3433
from unittest.mock import MagicMock, patch
3534

36-
import pytest
37-
3835
from pymongo.common import validate_read_preference_tags
3936
from pymongo.errors import ConfigurationError
4037
from pymongo.synchronous.uri_parser import parse_uri

0 commit comments

Comments
 (0)