|
49 | 49 | from pymongo.mongo_client import MongoClient
|
50 | 50 | from pymongo.pool import _configured_socket, PoolOptions
|
51 | 51 | from pymongo.read_concern import ReadConcern
|
52 |
| -from pymongo.ssl_support import get_ssl_context |
| 52 | +from pymongo.ssl_support import get_ssl_context, HAVE_SSL |
53 | 53 | from pymongo.uri_parser import parse_host
|
54 | 54 | from pymongo.write_concern import WriteConcern
|
55 | 55 | from pymongo.daemon import _spawn_daemon
|
56 | 56 |
|
| 57 | +if HAVE_SSL: |
| 58 | + from ssl import CERT_REQUIRED |
| 59 | +else: |
| 60 | + CERT_REQUIRED = None |
57 | 61 |
|
58 | 62 | _HTTPS_PORT = 443
|
59 | 63 | _KMS_CONNECT_TIMEOUT = 10 # TODO: CDRIVER-3262 will define this value.
|
@@ -107,7 +111,17 @@ def kms_request(self, kms_context):
|
107 | 111 | endpoint = kms_context.endpoint
|
108 | 112 | message = kms_context.message
|
109 | 113 | host, port = parse_host(endpoint, _HTTPS_PORT)
|
110 |
| - ctx = get_ssl_context(None, None, None, None, None, None, True, True) |
| 114 | + # Enable strict certificate verification, OCSP, match hostname, and |
| 115 | + # SNI using the system default CA certificates. |
| 116 | + ctx = get_ssl_context( |
| 117 | + None, # certfile |
| 118 | + None, # keyfile |
| 119 | + None, # passphrase |
| 120 | + None, # ca_certs |
| 121 | + CERT_REQUIRED, # cert_reqs |
| 122 | + None, # crlfile |
| 123 | + True, # match_hostname |
| 124 | + True) # check_ocsp_endpoint |
111 | 125 | opts = PoolOptions(connect_timeout=_KMS_CONNECT_TIMEOUT,
|
112 | 126 | socket_timeout=_KMS_CONNECT_TIMEOUT,
|
113 | 127 | ssl_context=ctx)
|
|
0 commit comments