Skip to content

Commit b317e1d

Browse files
committed
PYTHON-5040 Use PROTOCOL_TLS_CLIENT in http_post for Python 3.14
Python 3.14 sets X509_V_FLAG_X509_STRICT in ssl.create_default_context(), which requires Subject Key Identifier on all certs including the root CA. We intentionally omit SKI from the CA cert because adding it causes macOS SecTrust to trigger OCSP revocation checks during MongoDB 4.2 server startup, resulting in ~67-second connection timeouts. Using ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) instead gives the same security guarantees (certificate verification, hostname checking) without enabling strict mode, matching pre-Python-3.14 behavior.
1 parent a71871f commit b317e1d

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

test/asynchronous/test_encryption.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3045,7 +3045,13 @@ async def asyncSetUp(self):
30453045
async def http_post(self, path, data=None):
30463046
# Note, the connection to the mock server needs to be closed after
30473047
# each request because the server is single threaded.
3048-
ctx = ssl.create_default_context(cafile=CA_PEM)
3048+
# Use PROTOCOL_TLS_CLIENT instead of create_default_context so that
3049+
# X509_V_FLAG_X509_STRICT is not set. Python 3.14 enables strict mode
3050+
# in create_default_context, which requires SKI on the root CA cert.
3051+
# We intentionally omit SKI from the CA cert to prevent macOS SecTrust
3052+
# from triggering OCSP revocation checks during MongoDB 4.2 server startup.
3053+
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
3054+
ctx.load_verify_locations(cafile=CA_PEM)
30493055
ctx.load_cert_chain(CLIENT_PEM)
30503056
conn = http.client.HTTPSConnection("127.0.0.1:9003", context=ctx)
30513057
try:

test/test_encryption.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3027,7 +3027,13 @@ def setUp(self):
30273027
def http_post(self, path, data=None):
30283028
# Note, the connection to the mock server needs to be closed after
30293029
# each request because the server is single threaded.
3030-
ctx = ssl.create_default_context(cafile=CA_PEM)
3030+
# Use PROTOCOL_TLS_CLIENT instead of create_default_context so that
3031+
# X509_V_FLAG_X509_STRICT is not set. Python 3.14 enables strict mode
3032+
# in create_default_context, which requires SKI on the root CA cert.
3033+
# We intentionally omit SKI from the CA cert to prevent macOS SecTrust
3034+
# from triggering OCSP revocation checks during MongoDB 4.2 server startup.
3035+
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
3036+
ctx.load_verify_locations(cafile=CA_PEM)
30313037
ctx.load_cert_chain(CLIENT_PEM)
30323038
conn = http.client.HTTPSConnection("127.0.0.1:9003", context=ctx)
30333039
try:

0 commit comments

Comments
 (0)