87
87
from pymongo .results import BulkWriteResult , DeleteResult
88
88
from pymongo .ssl_support import BLOCKING_IO_ERRORS , get_ssl_context
89
89
from pymongo .typings import _DocumentType , _DocumentTypeArg
90
- from pymongo .uri_parser_shared import parse_host
90
+ from pymongo .uri_parser_shared import _parse_kms_tls_options , parse_host
91
91
from pymongo .write_concern import WriteConcern
92
92
93
93
if TYPE_CHECKING :
@@ -157,6 +157,7 @@ def __init__(
157
157
self .mongocryptd_client = mongocryptd_client
158
158
self .opts = opts
159
159
self ._spawned = False
160
+ self ._kms_ssl_contexts = opts ._kms_ssl_contexts (_IS_SYNC )
160
161
161
162
async def kms_request (self , kms_context : MongoCryptKmsContext ) -> None :
162
163
"""Complete a KMS request.
@@ -168,7 +169,7 @@ async def kms_request(self, kms_context: MongoCryptKmsContext) -> None:
168
169
endpoint = kms_context .endpoint
169
170
message = kms_context .message
170
171
provider = kms_context .kms_provider
171
- ctx = self .opts . _kms_ssl_contexts .get (provider )
172
+ ctx = self ._kms_ssl_contexts .get (provider )
172
173
if ctx is None :
173
174
# Enable strict certificate verification, OCSP, match hostname, and
174
175
# SNI using the system default CA certificates.
@@ -180,6 +181,7 @@ async def kms_request(self, kms_context: MongoCryptKmsContext) -> None:
180
181
False , # allow_invalid_certificates
181
182
False , # allow_invalid_hostnames
182
183
False , # disable_ocsp_endpoint_check
184
+ _IS_SYNC ,
183
185
)
184
186
# CSOT: set timeout for socket creation.
185
187
connect_timeout = max (_csot .clamp_remaining (_KMS_CONNECT_TIMEOUT ), 0.001 )
@@ -396,6 +398,8 @@ def __init__(self, client: AsyncMongoClient[_DocumentTypeArg], opts: AutoEncrypt
396
398
encrypted_fields_map = _dict_to_bson (opts ._encrypted_fields_map , False , _DATA_KEY_OPTS )
397
399
self ._bypass_auto_encryption = opts ._bypass_auto_encryption
398
400
self ._internal_client = None
401
+ # parsing kms_ssl_contexts here so that parsing errors will be raised before internal clients are created
402
+ opts ._kms_ssl_contexts (_IS_SYNC )
399
403
400
404
def _get_internal_client (
401
405
encrypter : _Encrypter , mongo_client : AsyncMongoClient [_DocumentTypeArg ]
@@ -675,6 +679,7 @@ def __init__(
675
679
kms_tls_options = kms_tls_options ,
676
680
key_expiration_ms = key_expiration_ms ,
677
681
)
682
+ self ._kms_ssl_contexts = _parse_kms_tls_options (opts ._kms_tls_options , _IS_SYNC )
678
683
self ._io_callbacks : Optional [_EncryptionIO ] = _EncryptionIO (
679
684
None , key_vault_coll , None , opts
680
685
)
0 commit comments